| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
(function( $, undefined ) { |
| 15 |
|
| 16 |
var mouseHandled = false; |
| 17 |
$( document ).mouseup( function( e ) { |
| 18 |
mouseHandled = false; |
| 19 |
}); |
| 20 |
|
| 21 |
$.widget("ui.mouse", { |
| 22 |
version: "1.9.2", |
| 23 |
options: { |
| 24 |
cancel: 'input,textarea,button,select,option', |
| 25 |
distance: 1, |
| 26 |
delay: 0 |
| 27 |
}, |
| 28 |
_mouseInit: function() { |
| 29 |
var that = this; |
| 30 |
|
| 31 |
this.element |
| 32 |
.on('mousedown.'+this.widgetName, function(event) { |
| 33 |
return that._mouseDown(event); |
| 34 |
}) |
| 35 |
.on('click.'+this.widgetName, function(event) { |
| 36 |
if (true === $.data(event.target, that.widgetName + '.preventClickEvent')) { |
| 37 |
$.removeData(event.target, that.widgetName + '.preventClickEvent'); |
| 38 |
event.stopImmediatePropagation(); |
| 39 |
return false; |
| 40 |
} |
| 41 |
}); |
| 42 |
|
| 43 |
this.started = false; |
| 44 |
}, |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
_mouseDestroy: function() { |
| 49 |
this.element.off('.'+this.widgetName); |
| 50 |
if ( this._mouseMoveDelegate ) { |
| 51 |
$(document) |
| 52 |
.off('mousemove.'+this.widgetName, this._mouseMoveDelegate) |
| 53 |
.off('mouseup.'+this.widgetName, this._mouseUpDelegate); |
| 54 |
} |
| 55 |
}, |
| 56 |
|
| 57 |
_mouseDown: function(event) { |
| 58 |
|
| 59 |
if( mouseHandled ) { return; } |
| 60 |
|
| 61 |
|
| 62 |
(this._mouseStarted && this._mouseUp(event)); |
| 63 |
|
| 64 |
this._mouseDownEvent = event; |
| 65 |
|
| 66 |
var that = this, |
| 67 |
btnIsLeft = (event.which === 1), |
| 68 |
|
| 69 |
|
| 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)) { |
| 72 |
return true; |
| 73 |
} |
| 74 |
|
| 75 |
this.mouseDelayMet = !this.options.delay; |
| 76 |
if (!this.mouseDelayMet) { |
| 77 |
this._mouseDelayTimer = setTimeout(function() { |
| 78 |
that.mouseDelayMet = true; |
| 79 |
}, this.options.delay); |
| 80 |
} |
| 81 |
|
| 82 |
if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) { |
| 83 |
this._mouseStarted = (this._mouseStart(event) !== false); |
| 84 |
if (!this._mouseStarted) { |
| 85 |
event.preventDefault(); |
| 86 |
return true; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
if (true === $.data(event.target, this.widgetName + '.preventClickEvent')) { |
| 92 |
$.removeData(event.target, this.widgetName + '.preventClickEvent'); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
this._mouseMoveDelegate = function(event) { |
| 97 |
return that._mouseMove(event); |
| 98 |
}; |
| 99 |
this._mouseUpDelegate = function(event) { |
| 100 |
return that._mouseUp(event); |
| 101 |
}; |
| 102 |
$(document) |
| 103 |
.on('mousemove.'+this.widgetName, this._mouseMoveDelegate) |
| 104 |
.on('mouseup.'+this.widgetName, this._mouseUpDelegate); |
| 105 |
|
| 106 |
event.preventDefault(); |
| 107 |
|
| 108 |
mouseHandled = true; |
| 109 |
return true; |
| 110 |
}, |
| 111 |
|
| 112 |
_mouseMove: function(event) { |
| 113 |
|
| 114 |
if ($.ui.ie && !(document.documentMode >= 9) && !event.button) { |
| 115 |
return this._mouseUp(event); |
| 116 |
} |
| 117 |
|
| 118 |
if (this._mouseStarted) { |
| 119 |
this._mouseDrag(event); |
| 120 |
return event.preventDefault(); |
| 121 |
} |
| 122 |
|
| 123 |
if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) { |
| 124 |
this._mouseStarted = |
| 125 |
(this._mouseStart(this._mouseDownEvent, event) !== false); |
| 126 |
(this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event)); |
| 127 |
} |
| 128 |
|
| 129 |
return !this._mouseStarted; |
| 130 |
}, |
| 131 |
|
| 132 |
_mouseUp: function(event) { |
| 133 |
$(document) |
| 134 |
.off('mousemove.'+this.widgetName, this._mouseMoveDelegate) |
| 135 |
.off('mouseup.'+this.widgetName, this._mouseUpDelegate); |
| 136 |
|
| 137 |
if (this._mouseStarted) { |
| 138 |
this._mouseStarted = false; |
| 139 |
|
| 140 |
if (event.target === this._mouseDownEvent.target) { |
| 141 |
$.data(event.target, this.widgetName + '.preventClickEvent', true); |
| 142 |
} |
| 143 |
|
| 144 |
this._mouseStop(event); |
| 145 |
} |
| 146 |
|
| 147 |
return false; |
| 148 |
}, |
| 149 |
|
| 150 |
_mouseDistanceMet: function(event) { |
| 151 |
return (Math.max( |
| 152 |
Math.abs(this._mouseDownEvent.pageX - event.pageX), |
| 153 |
Math.abs(this._mouseDownEvent.pageY - event.pageY) |
| 154 |
) >= this.options.distance |
| 155 |
); |
| 156 |
}, |
| 157 |
|
| 158 |
_mouseDelayMet: function(event) { |
| 159 |
return this.mouseDelayMet; |
| 160 |
}, |
| 161 |
|
| 162 |
|
| 163 |
_mouseStart: function(event) {}, |
| 164 |
_mouseDrag: function(event) {}, |
| 165 |
_mouseStop: function(event) {}, |
| 166 |
_mouseCapture: function(event) { return true; } |
| 167 |
}); |
| 168 |
|
| 169 |
})(jQuery); |