]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/form/_ListMouseMixin.js.uncompressed.js
1 define("dijit/form/_ListMouseMixin", [
2 "dojo/_base/declare", // declare
3 "dojo/_base/event", // event.stop
6 ], function(declare
, event
, touch
, _ListBase
){
9 var _ListBase = dijit.form._ListBase;
13 // dijit/form/_ListMouseMixin
15 // a mixin to handle mouse or touch events for a focus-less menu
17 return declare( "dijit.form._ListMouseMixin", _ListBase
, {
19 // a Mixin to handle mouse or touch events for a focus-less menu
20 // Abstract methods that must be defined externally:
21 // onClick: item was chosen (mousedown somewhere on the menu and mouseup somewhere on the menu)
25 postCreate: function(){
26 this.inherited(arguments
);
27 this.connect(this.domNode
, touch
.press
, "_onMouseDown");
28 this.connect(this.domNode
, touch
.release
, "_onMouseUp");
29 this.connect(this.domNode
, "onmouseover", "_onMouseOver");
30 this.connect(this.domNode
, "onmouseout", "_onMouseOut");
33 _onMouseDown: function(/*Event*/ evt
){
35 if(this._hoveredNode
){
36 this.onUnhover(this._hoveredNode
);
37 this._hoveredNode
= null;
39 this._isDragging
= true;
40 this._setSelectedAttr(this._getTarget(evt
));
43 _onMouseUp: function(/*Event*/ evt
){
45 this._isDragging
= false;
46 var selectedNode
= this._getSelectedAttr();
47 var target
= this._getTarget(evt
);
48 var hoveredNode
= this._hoveredNode
;
49 if(selectedNode
&& target
== selectedNode
){
50 this.onClick(selectedNode
);
51 }else if(hoveredNode
&& target
== hoveredNode
){ // drag to select
52 this._setSelectedAttr(hoveredNode
);
53 this.onClick(hoveredNode
);
57 _onMouseOut: function(/*Event*/ /*===== evt ====*/){
58 if(this._hoveredNode
){
59 this.onUnhover(this._hoveredNode
);
60 if(this._getSelectedAttr() == this._hoveredNode
){
61 this.onSelect(this._hoveredNode
);
63 this._hoveredNode
= null;
66 this._cancelDrag
= (new Date()).getTime() + 1000; // cancel in 1 second if no _onMouseOver fires
70 _onMouseOver: function(/*Event*/ evt
){
72 var time
= (new Date()).getTime();
73 if(time
> this._cancelDrag
){
74 this._isDragging
= false;
76 this._cancelDrag
= null;
78 var node
= this._getTarget(evt
);
80 if(this._hoveredNode
!= node
){
81 if(this._hoveredNode
){
82 this._onMouseOut({ target
: this._hoveredNode
});
84 if(node
&& node
.parentNode
== this.containerNode
){
86 this._setSelectedAttr(node
);
88 this._hoveredNode
= node
;