1 define("dijit/form/_ListMouseMixin", [
2 "dojo/_base/declare", // declare
7 ], function(declare, mouse, on, touch, _ListBase){
10 // dijit/form/_ListMouseMixin
12 return declare( "dijit.form._ListMouseMixin", _ListBase, {
14 // a Mixin to handle mouse or touch events for a focus-less menu
15 // Abstract methods that must be defined externally:
17 // - onClick: item was chosen (mousedown somewhere on the menu and mouseup somewhere on the menu)
21 postCreate: function(){
22 this.inherited(arguments);
24 this.own(on(this.domNode, touch.press, function(evt){ evt.preventDefault(); })); // prevent focus shift on list scrollbar press
26 this._listConnect(touch.press, "_onMouseDown");
27 this._listConnect(touch.release, "_onMouseUp");
28 this._listConnect(mouse.enter, "_onMouseOver");
29 this._listConnect(mouse.leave, "_onMouseOut");
32 _onMouseDown: function(/*Event*/ evt, /*DomNode*/ target){
33 if(this._hoveredNode){
34 this.onUnhover(this._hoveredNode);
35 this._hoveredNode = null;
37 this._isDragging = true;
38 this._setSelectedAttr(target);
41 _onMouseUp: function(/*Event*/ evt, /*DomNode*/ target){
42 this._isDragging = false;
43 var selectedNode = this.selected;
44 var hoveredNode = this._hoveredNode;
45 if(selectedNode && target == selectedNode){
46 this.onClick(selectedNode);
47 }else if(hoveredNode && target == hoveredNode){ // drag to select
48 this._setSelectedAttr(hoveredNode);
49 this.onClick(hoveredNode);
53 _onMouseOut: function(/*Event*/ evt, /*DomNode*/ target){
54 if(this._hoveredNode){
55 this.onUnhover(this._hoveredNode);
56 this._hoveredNode = null;
59 this._cancelDrag = (new Date()).getTime() + 1000; // cancel in 1 second if no _onMouseOver fires
63 _onMouseOver: function(/*Event*/ evt, /*DomNode*/ target){
65 var time = (new Date()).getTime();
66 if(time > this._cancelDrag){
67 this._isDragging = false;
69 this._cancelDrag = null;
71 this._hoveredNode = target;
74 this._setSelectedAttr(target);