]> git.wh0rd.org - tt-rss.git/blame - lib/dijit/form/_ListMouseMixin.js.uncompressed.js
make precache_headlines_idle() start slower
[tt-rss.git] / lib / dijit / form / _ListMouseMixin.js.uncompressed.js
CommitLineData
1354d172
AD
1define("dijit/form/_ListMouseMixin", [
2 "dojo/_base/declare", // declare
3 "dojo/_base/event", // event.stop
4 "dojo/touch",
5 "./_ListBase"
6], function(declare, event, touch, _ListBase){
7
8/*=====
9var _ListBase = dijit.form._ListBase;
10=====*/
11
12// module:
13// dijit/form/_ListMouseMixin
14// summary:
15// a mixin to handle mouse or touch events for a focus-less menu
16
17return declare( "dijit.form._ListMouseMixin", _ListBase, {
18 // summary:
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)
22 // tags:
23 // private
24
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");
31 },
32
33 _onMouseDown: function(/*Event*/ evt){
34 event.stop(evt);
35 if(this._hoveredNode){
36 this.onUnhover(this._hoveredNode);
37 this._hoveredNode = null;
38 }
39 this._isDragging = true;
40 this._setSelectedAttr(this._getTarget(evt));
41 },
42
43 _onMouseUp: function(/*Event*/ evt){
44 event.stop(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);
54 }
55 },
56
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);
62 }
63 this._hoveredNode = null;
64 }
65 if(this._isDragging){
66 this._cancelDrag = (new Date()).getTime() + 1000; // cancel in 1 second if no _onMouseOver fires
67 }
68 },
69
70 _onMouseOver: function(/*Event*/ evt){
71 if(this._cancelDrag){
72 var time = (new Date()).getTime();
73 if(time > this._cancelDrag){
74 this._isDragging = false;
75 }
76 this._cancelDrag = null;
77 }
78 var node = this._getTarget(evt);
79 if(!node){ return; }
80 if(this._hoveredNode != node){
81 if(this._hoveredNode){
82 this._onMouseOut({ target: this._hoveredNode });
83 }
84 if(node && node.parentNode == this.containerNode){
85 if(this._isDragging){
86 this._setSelectedAttr(node);
87 }else{
88 this._hoveredNode = node;
89 this.onHover(node);
90 }
91 }
92 }
93 }
94});
95
96});