2 * jQuery UI Mouse 1.11.4
5 * Copyright jQuery Foundation and other contributors
6 * Released under the MIT license.
7 * http://jquery.org/license
9 * http://api.jqueryui.com/mouse/
11 (function( factory
) {
12 if ( typeof define
=== "function" && define
.amd
) {
14 // AMD. Register as an anonymous module.
26 var mouseHandled
= false;
27 $( document
).mouseup( function() {
31 return $.widget("ui.mouse", {
34 cancel
: "input,textarea,button,select,option",
38 _mouseInit: function() {
42 .bind("mousedown." + this.widgetName
, function(event
) {
43 return that
._mouseDown(event
);
45 .bind("click." + this.widgetName
, function(event
) {
46 if (true === $.data(event
.target
, that
.widgetName
+ ".preventClickEvent")) {
47 $.removeData(event
.target
, that
.widgetName
+ ".preventClickEvent");
48 event
.stopImmediatePropagation();
56 // TODO: make sure destroying one instance of mouse doesn't mess with
57 // other instances of mouse
58 _mouseDestroy: function() {
59 this.element
.unbind("." + this.widgetName
);
60 if ( this._mouseMoveDelegate
) {
62 .unbind("mousemove." + this.widgetName
, this._mouseMoveDelegate
)
63 .unbind("mouseup." + this.widgetName
, this._mouseUpDelegate
);
67 _mouseDown: function(event
) {
68 // don't let more than one widget handle mouseStart
73 this._mouseMoved
= false;
75 // we may have missed mouseup (out of window)
76 (this._mouseStarted
&& this._mouseUp(event
));
78 this._mouseDownEvent
= event
;
81 btnIsLeft
= (event
.which
=== 1),
82 // event.target.nodeName works around a bug in IE 8 with
83 // disabled inputs (#7620)
84 elIsCancel
= (typeof this.options
.cancel
=== "string" && event
.target
.nodeName
? $(event
.target
).closest(this.options
.cancel
).length
: false);
85 if (!btnIsLeft
|| elIsCancel
|| !this._mouseCapture(event
)) {
89 this.mouseDelayMet
= !this.options
.delay
;
90 if (!this.mouseDelayMet
) {
91 this._mouseDelayTimer
= setTimeout(function() {
92 that
.mouseDelayMet
= true;
93 }, this.options
.delay
);
96 if (this._mouseDistanceMet(event
) && this._mouseDelayMet(event
)) {
97 this._mouseStarted
= (this._mouseStart(event
) !== false);
98 if (!this._mouseStarted
) {
99 event
.preventDefault();
104 // Click event may never have fired (Gecko & Opera)
105 if (true === $.data(event
.target
, this.widgetName
+ ".preventClickEvent")) {
106 $.removeData(event
.target
, this.widgetName
+ ".preventClickEvent");
109 // these delegates are required to keep context
110 this._mouseMoveDelegate = function(event
) {
111 return that
._mouseMove(event
);
113 this._mouseUpDelegate = function(event
) {
114 return that
._mouseUp(event
);
118 .bind( "mousemove." + this.widgetName
, this._mouseMoveDelegate
)
119 .bind( "mouseup." + this.widgetName
, this._mouseUpDelegate
);
121 event
.preventDefault();
127 _mouseMove: function(event
) {
128 // Only check for mouseups outside the document if you've moved inside the document
129 // at least once. This prevents the firing of mouseup in the case of IE<9, which will
130 // fire a mousemove event if content is placed under the cursor. See #7778
132 if ( this._mouseMoved
) {
133 // IE mouseup check - mouseup happened when mouse was out of window
134 if ($.ui
.ie
&& ( !document
.documentMode
|| document
.documentMode
< 9 ) && !event
.button
) {
135 return this._mouseUp(event
);
137 // Iframe mouseup check - mouseup occurred in another document
138 } else if ( !event
.which
) {
139 return this._mouseUp( event
);
143 if ( event
.which
|| event
.button
) {
144 this._mouseMoved
= true;
147 if (this._mouseStarted
) {
148 this._mouseDrag(event
);
149 return event
.preventDefault();
152 if (this._mouseDistanceMet(event
) && this._mouseDelayMet(event
)) {
154 (this._mouseStart(this._mouseDownEvent
, event
) !== false);
155 (this._mouseStarted
? this._mouseDrag(event
) : this._mouseUp(event
));
158 return !this._mouseStarted
;
161 _mouseUp: function(event
) {
163 .unbind( "mousemove." + this.widgetName
, this._mouseMoveDelegate
)
164 .unbind( "mouseup." + this.widgetName
, this._mouseUpDelegate
);
166 if (this._mouseStarted
) {
167 this._mouseStarted
= false;
169 if (event
.target
=== this._mouseDownEvent
.target
) {
170 $.data(event
.target
, this.widgetName
+ ".preventClickEvent", true);
173 this._mouseStop(event
);
176 mouseHandled
= false;
180 _mouseDistanceMet: function(event
) {
182 Math
.abs(this._mouseDownEvent
.pageX
- event
.pageX
),
183 Math
.abs(this._mouseDownEvent
.pageY
- event
.pageY
)
184 ) >= this.options
.distance
188 _mouseDelayMet: function(/* event */) {
189 return this.mouseDelayMet
;
192 // These are placeholder methods, to be overriden by extending plugin
193 _mouseStart: function(/* event */) {},
194 _mouseDrag: function(/* event */) {},
195 _mouseStop: function(/* event */) {},
196 _mouseCapture: function(/* event */) { return true; }