| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
( function( factory ) { |
| 16 |
"use strict"; |
| 17 |
|
| 18 |
if ( typeof define === "function" && define.amd ) { |
| 19 |
|
| 20 |
|
| 21 |
define( [ |
| 22 |
"jquery", |
| 23 |
"../version", |
| 24 |
"../widget" |
| 25 |
], factory ); |
| 26 |
} else { |
| 27 |
|
| 28 |
|
| 29 |
factory( jQuery ); |
| 30 |
} |
| 31 |
} )( function( $ ) { |
| 32 |
"use strict"; |
| 33 |
|
| 34 |
var mouseHandled = false; |
| 35 |
$( document ).on( "mouseup", function() { |
| 36 |
mouseHandled = false; |
| 37 |
} ); |
| 38 |
|
| 39 |
return $.widget( "ui.mouse", { |
| 40 |
version: "1.14.2", |
| 41 |
options: { |
| 42 |
cancel: "input, textarea, button, select, option", |
| 43 |
distance: 1, |
| 44 |
delay: 0 |
| 45 |
}, |
| 46 |
_mouseInit: function() { |
| 47 |
var that = this; |
| 48 |
|
| 49 |
this.element |
| 50 |
.on( "mousedown." + this.widgetName, function( event ) { |
| 51 |
return that._mouseDown( event ); |
| 52 |
} ) |
| 53 |
.on( "click." + this.widgetName, function( event ) { |
| 54 |
if ( true === $.data( event.target, that.widgetName + ".preventClickEvent" ) ) { |
| 55 |
$.removeData( event.target, that.widgetName + ".preventClickEvent" ); |
| 56 |
event.stopImmediatePropagation(); |
| 57 |
return false; |
| 58 |
} |
| 59 |
} ); |
| 60 |
|
| 61 |
this.started = false; |
| 62 |
}, |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
_mouseDestroy: function() { |
| 67 |
this.element.off( "." + this.widgetName ); |
| 68 |
if ( this._mouseMoveDelegate ) { |
| 69 |
this.document |
| 70 |
.off( "mousemove." + this.widgetName, this._mouseMoveDelegate ) |
| 71 |
.off( "mouseup." + this.widgetName, this._mouseUpDelegate ); |
| 72 |
} |
| 73 |
}, |
| 74 |
|
| 75 |
_mouseDown: function( event ) { |
| 76 |
|
| 77 |
|
| 78 |
if ( mouseHandled ) { |
| 79 |
return; |
| 80 |
} |
| 81 |
|
| 82 |
this._mouseMoved = false; |
| 83 |
|
| 84 |
|
| 85 |
if ( this._mouseStarted ) { |
| 86 |
this._mouseUp( event ); |
| 87 |
} |
| 88 |
|
| 89 |
this._mouseDownEvent = event; |
| 90 |
|
| 91 |
var that = this, |
| 92 |
btnIsLeft = event.which === 1, |
| 93 |
elIsCancel = typeof this.options.cancel === "string" ? |
| 94 |
$( event.target ).closest( this.options.cancel ).length : |
| 95 |
false; |
| 96 |
if ( !btnIsLeft || elIsCancel || !this._mouseCapture( event ) ) { |
| 97 |
return true; |
| 98 |
} |
| 99 |
|
| 100 |
this.mouseDelayMet = !this.options.delay; |
| 101 |
if ( !this.mouseDelayMet ) { |
| 102 |
this._mouseDelayTimer = setTimeout( function() { |
| 103 |
that.mouseDelayMet = true; |
| 104 |
}, this.options.delay ); |
| 105 |
} |
| 106 |
|
| 107 |
if ( this._mouseDistanceMet( event ) && this._mouseDelayMet( event ) ) { |
| 108 |
this._mouseStarted = ( this._mouseStart( event ) !== false ); |
| 109 |
if ( !this._mouseStarted ) { |
| 110 |
event.preventDefault(); |
| 111 |
return true; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
if ( true === $.data( event.target, this.widgetName + ".preventClickEvent" ) ) { |
| 117 |
$.removeData( event.target, this.widgetName + ".preventClickEvent" ); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
this._mouseMoveDelegate = function( event ) { |
| 122 |
return that._mouseMove( event ); |
| 123 |
}; |
| 124 |
this._mouseUpDelegate = function( event ) { |
| 125 |
return that._mouseUp( event ); |
| 126 |
}; |
| 127 |
|
| 128 |
this.document |
| 129 |
.on( "mousemove." + this.widgetName, this._mouseMoveDelegate ) |
| 130 |
.on( "mouseup." + this.widgetName, this._mouseUpDelegate ); |
| 131 |
|
| 132 |
event.preventDefault(); |
| 133 |
|
| 134 |
mouseHandled = true; |
| 135 |
return true; |
| 136 |
}, |
| 137 |
|
| 138 |
_mouseMove: function( event ) { |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
if ( this._mouseMoved && !event.which ) { |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
if ( event.originalEvent.altKey || event.originalEvent.ctrlKey || |
| 148 |
event.originalEvent.metaKey || event.originalEvent.shiftKey ) { |
| 149 |
this.ignoreMissingWhich = true; |
| 150 |
} else if ( !this.ignoreMissingWhich ) { |
| 151 |
return this._mouseUp( event ); |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
if ( event.which || event.button ) { |
| 156 |
this._mouseMoved = true; |
| 157 |
} |
| 158 |
|
| 159 |
if ( this._mouseStarted ) { |
| 160 |
this._mouseDrag( event ); |
| 161 |
return event.preventDefault(); |
| 162 |
} |
| 163 |
|
| 164 |
if ( this._mouseDistanceMet( event ) && this._mouseDelayMet( event ) ) { |
| 165 |
this._mouseStarted = |
| 166 |
( this._mouseStart( this._mouseDownEvent, event ) !== false ); |
| 167 |
if ( this._mouseStarted ) { |
| 168 |
this._mouseDrag( event ); |
| 169 |
} else { |
| 170 |
this._mouseUp( event ); |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
return !this._mouseStarted; |
| 175 |
}, |
| 176 |
|
| 177 |
_mouseUp: function( event ) { |
| 178 |
this.document |
| 179 |
.off( "mousemove." + this.widgetName, this._mouseMoveDelegate ) |
| 180 |
.off( "mouseup." + this.widgetName, this._mouseUpDelegate ); |
| 181 |
|
| 182 |
if ( this._mouseStarted ) { |
| 183 |
this._mouseStarted = false; |
| 184 |
|
| 185 |
if ( event.target === this._mouseDownEvent.target ) { |
| 186 |
$.data( event.target, this.widgetName + ".preventClickEvent", true ); |
| 187 |
} |
| 188 |
|
| 189 |
this._mouseStop( event ); |
| 190 |
} |
| 191 |
|
| 192 |
if ( this._mouseDelayTimer ) { |
| 193 |
clearTimeout( this._mouseDelayTimer ); |
| 194 |
delete this._mouseDelayTimer; |
| 195 |
} |
| 196 |
|
| 197 |
this.ignoreMissingWhich = false; |
| 198 |
mouseHandled = false; |
| 199 |
event.preventDefault(); |
| 200 |
}, |
| 201 |
|
| 202 |
_mouseDistanceMet: function( event ) { |
| 203 |
return ( Math.max( |
| 204 |
Math.abs( this._mouseDownEvent.pageX - event.pageX ), |
| 205 |
Math.abs( this._mouseDownEvent.pageY - event.pageY ) |
| 206 |
) >= this.options.distance |
| 207 |
); |
| 208 |
}, |
| 209 |
|
| 210 |
_mouseDelayMet: function( ) { |
| 211 |
return this.mouseDelayMet; |
| 212 |
}, |
| 213 |
|
| 214 |
|
| 215 |
_mouseStart: function( ) {}, |
| 216 |
_mouseDrag: function( ) {}, |
| 217 |
_mouseStop: function( ) {}, |
| 218 |
_mouseCapture: function( ) { |
| 219 |
return true; |
| 220 |
} |
| 221 |
} ); |
| 222 |
|
| 223 |
} ); |