Debian Codegraph @

dijit/form/_ListMouseMixin.js

raw symbols SCIP
1 define([
2 "dojo/_base/declare", // declare
3 "dojo/on",
4 "dojo/touch",
5 "./_ListBase"
6 ], function(declare, on, touch, _ListBase){
7
8 // module:
9 // dijit/form/_ListMouseMixin
10
11 return declare("dijit.form._ListMouseMixin", _ListBase, {
12 // summary:
13 // A mixin to handle mouse or touch events for a focus-less menu
14 // Abstract methods that must be defined externally:
15 //
16 // - onClick: item was chosen (mousedown somewhere on the menu and mouseup somewhere on the menu)
17 // tags:
18 // private
19
20 postCreate: function(){
21 this.inherited(arguments);
22
23 // Add flag to use normalized click handling from dojo/touch
24 this.domNode.dojoClick = true;
25
26 this._listConnect("click", "_onClick");
27 this._listConnect("mousedown", "_onMouseDown");
28 this._listConnect("mouseup", "_onMouseUp");
29 this._listConnect("mouseover", "_onMouseOver");
30 this._listConnect("mouseout", "_onMouseOut");
31 },
32
33 _onClick: function(/*Event*/ evt, /*DomNode*/ target){
34 this._setSelectedAttr(target, false);
35 if(this._deferredClick){
36 this._deferredClick.remove();
37 }
38 this._deferredClick = this.defer(function(){
39 this._deferredClick = null;
40 this.onClick(target);
41 });
42 },
43
44 _onMouseDown: function(/*Event*/ evt, /*DomNode*/ target){
45 if(this._hoveredNode){
46 this.onUnhover(this._hoveredNode);
47 this._hoveredNode = null;
48 }
49 this._isDragging = true;
50 this._setSelectedAttr(target, false);
51 },
52
53 _onMouseUp: function(/*Event*/ evt, /*DomNode*/ target){
54 this._isDragging = false;
55 var selectedNode = this.selected;
56 var hoveredNode = this._hoveredNode;
57 if(selectedNode && target == selectedNode){
58 this.defer(function(){
59 this._onClick(evt, selectedNode);
60 });
61 }else if(hoveredNode){ // drag to select
62 this.defer(function(){
63 this._onClick(evt, hoveredNode);
64 });
65 }
66 },
67
68 _onMouseOut: function(/*Event*/ evt, /*DomNode*/ target){
69 if(this._hoveredNode){
70 this.onUnhover(this._hoveredNode);
71 this._hoveredNode = null;
72 }
73 if(this._isDragging){
74 this._cancelDrag = (new Date()).getTime() + 1000; // cancel in 1 second if no _onMouseOver fires
75 }
76 },
77
78 _onMouseOver: function(/*Event*/ evt, /*DomNode*/ target){
79 if(this._cancelDrag){
80 var time = (new Date()).getTime();
81 if(time > this._cancelDrag){
82 this._isDragging = false;
83 }
84 this._cancelDrag = null;
85 }
86 this._hoveredNode = target;
87 this.onHover(target);
88 if(this._isDragging){
89 this._setSelectedAttr(target, false);
90 }
91 }
92 });
93 });