2 * jQuery UI Mouse 1.9.2
5 * Copyright 2012 jQuery Foundation and other contributors
6 * Released under the MIT license.
7 * http://jquery.org/license
9 * http://api.jqueryui.com/mouse/
14 (function( $, undefined ) {
16 var mouseHandled
= false;
17 $( document
).mouseup( function( e
) {
21 $.widget("ui.mouse", {
24 cancel
: 'input,textarea,button,select,option',
28 _mouseInit: function() {
32 .bind('mousedown.'+this.widgetName
, function(event
) {
33 return that
._mouseDown(event
);
35 .bind('click.'+this.widgetName
, function(event
) {
36 if (true === $.data(event
.target
, that
.widgetName
+ '.preventClickEvent')) {
37 $.removeData(event
.target
, that
.widgetName
+ '.preventClickEvent');
38 event
.stopImmediatePropagation();
46 // TODO: make sure destroying one instance of mouse doesn't mess with
47 // other instances of mouse
48 _mouseDestroy: function() {
49 this.element
.unbind('.'+this.widgetName
);
50 if ( this._mouseMoveDelegate
) {
52 .unbind('mousemove.'+this.widgetName
, this._mouseMoveDelegate
)
53 .unbind('mouseup.'+this.widgetName
, this._mouseUpDelegate
);
57 _mouseDown: function(event
) {
58 // don't let more than one widget handle mouseStart
59 if( mouseHandled
) { return; }
61 // we may have missed mouseup (out of window)
62 (this._mouseStarted
&& this._mouseUp(event
));
64 this._mouseDownEvent
= event
;
67 btnIsLeft
= (event
.which
=== 1),
68 // event.target.nodeName works around a bug in IE 8 with
69 // disabled inputs (#7620)
70 elIsCancel
= (typeof this.options
.cancel
=== "string" && event
.target
.nodeName
? $(event
.target
).closest(this.options
.cancel
).length
: false);
71 if (!btnIsLeft
|| elIsCancel
|| !this._mouseCapture(event
)) {
75 this.mouseDelayMet
= !this.options
.delay
;
76 if (!this.mouseDelayMet
) {
77 this._mouseDelayTimer
= setTimeout(function() {
78 that
.mouseDelayMet
= true;
79 }, this.options
.delay
);
82 if (this._mouseDistanceMet(event
) && this._mouseDelayMet(event
)) {
83 this._mouseStarted
= (this._mouseStart(event
) !== false);
84 if (!this._mouseStarted
) {
85 event
.preventDefault();
90 // Click event may never have fired (Gecko & Opera)
91 if (true === $.data(event
.target
, this.widgetName
+ '.preventClickEvent')) {
92 $.removeData(event
.target
, this.widgetName
+ '.preventClickEvent');
95 // these delegates are required to keep context
96 this._mouseMoveDelegate = function(event
) {
97 return that
._mouseMove(event
);
99 this._mouseUpDelegate = function(event
) {
100 return that
._mouseUp(event
);
103 .bind('mousemove.'+this.widgetName
, this._mouseMoveDelegate
)
104 .bind('mouseup.'+this.widgetName
, this._mouseUpDelegate
);
106 event
.preventDefault();
112 _mouseMove: function(event
) {
113 // IE mouseup check - mouseup happened when mouse was out of window
114 if ($.ui
.ie
&& !(document
.documentMode
>= 9) && !event
.button
) {
115 return this._mouseUp(event
);
118 if (this._mouseStarted
) {
119 this._mouseDrag(event
);
120 return event
.preventDefault();
123 if (this._mouseDistanceMet(event
) && this._mouseDelayMet(event
)) {
125 (this._mouseStart(this._mouseDownEvent
, event
) !== false);
126 (this._mouseStarted
? this._mouseDrag(event
) : this._mouseUp(event
));
129 return !this._mouseStarted
;
132 _mouseUp: function(event
) {
134 .unbind('mousemove.'+this.widgetName
, this._mouseMoveDelegate
)
135 .unbind('mouseup.'+this.widgetName
, this._mouseUpDelegate
);
137 if (this._mouseStarted
) {
138 this._mouseStarted
= false;
140 if (event
.target
=== this._mouseDownEvent
.target
) {
141 $.data(event
.target
, this.widgetName
+ '.preventClickEvent', true);
144 this._mouseStop(event
);
150 _mouseDistanceMet: function(event
) {
152 Math
.abs(this._mouseDownEvent
.pageX
- event
.pageX
),
153 Math
.abs(this._mouseDownEvent
.pageY
- event
.pageY
)
154 ) >= this.options
.distance
158 _mouseDelayMet: function(event
) {
159 return this.mouseDelayMet
;
162 // These are placeholder methods, to be overriden by extending plugin
163 _mouseStart: function(event
) {},
164 _mouseDrag: function(event
) {},
165 _mouseStop: function(event
) {},
166 _mouseCapture: function(event
) { return true; }