2009-12-22 19:51:24 +00:00
|
|
|
/*!
|
|
|
|
* jQuery UI Mouse @VERSION
|
|
|
|
*
|
2011-01-17 14:13:18 +00:00
|
|
|
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
2010-07-09 13:01:04 +00:00
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
* http://jquery.org/license
|
2009-12-22 19:51:24 +00:00
|
|
|
*
|
|
|
|
* http://docs.jquery.com/UI/Mouse
|
|
|
|
*
|
|
|
|
* Depends:
|
|
|
|
* jquery.ui.widget.js
|
|
|
|
*/
|
2010-07-13 13:57:58 +00:00
|
|
|
(function( $, undefined ) {
|
2009-12-22 19:51:24 +00:00
|
|
|
|
2011-08-02 13:36:22 +00:00
|
|
|
var mouseHandled = false;
|
|
|
|
$( document ).mouseup( function( e ) {
|
|
|
|
mouseHandled = false;
|
|
|
|
});
|
|
|
|
|
2010-01-07 03:19:50 +00:00
|
|
|
$.widget("ui.mouse", {
|
2011-05-28 19:39:55 +00:00
|
|
|
version: "@VERSION",
|
2010-01-07 03:19:50 +00:00
|
|
|
options: {
|
|
|
|
cancel: ':input,option',
|
|
|
|
distance: 1,
|
|
|
|
delay: 0
|
|
|
|
},
|
2009-12-22 19:51:24 +00:00
|
|
|
_mouseInit: function() {
|
2012-02-12 14:31:06 +00:00
|
|
|
var that = this;
|
2009-12-22 19:51:24 +00:00
|
|
|
|
|
|
|
this.element
|
|
|
|
.bind('mousedown.'+this.widgetName, function(event) {
|
2012-02-12 14:31:06 +00:00
|
|
|
return that._mouseDown(event);
|
2009-12-22 19:51:24 +00:00
|
|
|
})
|
|
|
|
.bind('click.'+this.widgetName, function(event) {
|
2012-02-12 14:31:06 +00:00
|
|
|
if (true === $.data(event.target, that.widgetName + '.preventClickEvent')) {
|
2012-02-27 16:48:17 +00:00
|
|
|
$.removeData(event.target, that.widgetName + '.preventClickEvent');
|
2009-12-22 19:51:24 +00:00
|
|
|
event.stopImmediatePropagation();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.started = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
// TODO: make sure destroying one instance of mouse doesn't mess with
|
|
|
|
// other instances of mouse
|
|
|
|
_mouseDestroy: function() {
|
|
|
|
this.element.unbind('.'+this.widgetName);
|
|
|
|
},
|
|
|
|
|
|
|
|
_mouseDown: function(event) {
|
|
|
|
// don't let more than one widget handle mouseStart
|
2011-08-02 13:36:22 +00:00
|
|
|
if( mouseHandled ) { return };
|
2009-12-22 19:51:24 +00:00
|
|
|
|
|
|
|
// we may have missed mouseup (out of window)
|
|
|
|
(this._mouseStarted && this._mouseUp(event));
|
|
|
|
|
|
|
|
this._mouseDownEvent = event;
|
|
|
|
|
2012-02-12 14:31:06 +00:00
|
|
|
var that = this,
|
2009-12-22 19:51:24 +00:00
|
|
|
btnIsLeft = (event.which == 1),
|
2011-08-09 13:32:01 +00:00
|
|
|
// event.target.nodeName works around a bug in IE 8 with
|
|
|
|
// disabled inputs (#7620)
|
|
|
|
elIsCancel = (typeof this.options.cancel == "string" && event.target.nodeName ? $(event.target).closest(this.options.cancel).length : false);
|
2009-12-22 19:51:24 +00:00
|
|
|
if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.mouseDelayMet = !this.options.delay;
|
|
|
|
if (!this.mouseDelayMet) {
|
|
|
|
this._mouseDelayTimer = setTimeout(function() {
|
2012-02-12 14:31:06 +00:00
|
|
|
that.mouseDelayMet = true;
|
2009-12-22 19:51:24 +00:00
|
|
|
}, this.options.delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
|
|
|
|
this._mouseStarted = (this._mouseStart(event) !== false);
|
|
|
|
if (!this._mouseStarted) {
|
|
|
|
event.preventDefault();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-05 08:13:55 +00:00
|
|
|
// Click event may never have fired (Gecko & Opera)
|
|
|
|
if (true === $.data(event.target, this.widgetName + '.preventClickEvent')) {
|
|
|
|
$.removeData(event.target, this.widgetName + '.preventClickEvent');
|
|
|
|
}
|
|
|
|
|
2009-12-22 19:51:24 +00:00
|
|
|
// these delegates are required to keep context
|
|
|
|
this._mouseMoveDelegate = function(event) {
|
2012-02-12 14:31:06 +00:00
|
|
|
return that._mouseMove(event);
|
2009-12-22 19:51:24 +00:00
|
|
|
};
|
|
|
|
this._mouseUpDelegate = function(event) {
|
2012-02-12 14:31:06 +00:00
|
|
|
return that._mouseUp(event);
|
2009-12-22 19:51:24 +00:00
|
|
|
};
|
|
|
|
$(document)
|
|
|
|
.bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
|
|
|
|
.bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
|
|
|
|
|
2010-10-13 17:30:50 +00:00
|
|
|
event.preventDefault();
|
2011-08-02 13:36:22 +00:00
|
|
|
|
|
|
|
mouseHandled = true;
|
2009-12-22 19:51:24 +00:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
_mouseMove: function(event) {
|
|
|
|
// IE mouseup check - mouseup happened when mouse was out of window
|
2010-10-15 08:04:39 +00:00
|
|
|
if ($.browser.msie && !(document.documentMode >= 9) && !event.button) {
|
2009-12-22 19:51:24 +00:00
|
|
|
return this._mouseUp(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._mouseStarted) {
|
|
|
|
this._mouseDrag(event);
|
|
|
|
return event.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
|
|
|
|
this._mouseStarted =
|
|
|
|
(this._mouseStart(this._mouseDownEvent, event) !== false);
|
|
|
|
(this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
|
|
|
|
}
|
|
|
|
|
|
|
|
return !this._mouseStarted;
|
|
|
|
},
|
|
|
|
|
|
|
|
_mouseUp: function(event) {
|
|
|
|
$(document)
|
|
|
|
.unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
|
|
|
|
.unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
|
|
|
|
|
|
|
|
if (this._mouseStarted) {
|
|
|
|
this._mouseStarted = false;
|
2010-11-03 07:45:47 +00:00
|
|
|
|
|
|
|
if (event.target == this._mouseDownEvent.target) {
|
2012-02-27 16:48:17 +00:00
|
|
|
$.data(event.target, this.widgetName + '.preventClickEvent', true);
|
2010-11-03 07:45:47 +00:00
|
|
|
}
|
|
|
|
|
2009-12-22 19:51:24 +00:00
|
|
|
this._mouseStop(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_mouseDistanceMet: function(event) {
|
|
|
|
return (Math.max(
|
|
|
|
Math.abs(this._mouseDownEvent.pageX - event.pageX),
|
|
|
|
Math.abs(this._mouseDownEvent.pageY - event.pageY)
|
|
|
|
) >= this.options.distance
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
_mouseDelayMet: function(event) {
|
|
|
|
return this.mouseDelayMet;
|
|
|
|
},
|
|
|
|
|
|
|
|
// These are placeholder methods, to be overriden by extending plugin
|
|
|
|
_mouseStart: function(event) {},
|
|
|
|
_mouseDrag: function(event) {},
|
|
|
|
_mouseStop: function(event) {},
|
|
|
|
_mouseCapture: function(event) { return true; }
|
2010-01-07 03:19:50 +00:00
|
|
|
});
|
2009-12-22 19:51:24 +00:00
|
|
|
|
|
|
|
})(jQuery);
|