2 * jQuery UI Mouse 1.8.24
4 * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about)
5 * Dual licensed under the MIT or GPL Version 2 licenses.
6 * http://jquery.org/license
8 * http://docs.jquery.com/UI/Mouse
13 (function( $, undefined ) {
15 var mouseHandled = false;
16 $( document ).mouseup( function( e ) {
20 $.widget("ui.mouse", {
22 cancel: ':input,option',
26 _mouseInit: function() {
30 .bind('mousedown.'+this.widgetName, function(event) {
31 return self._mouseDown(event);
33 .bind('click.'+this.widgetName, function(event) {
34 if (true === $.data(event.target, self.widgetName + '.preventClickEvent')) {
35 $.removeData(event.target, self.widgetName + '.preventClickEvent');
36 event.stopImmediatePropagation();
44 // TODO: make sure destroying one instance of mouse doesn't mess with
45 // other instances of mouse
46 _mouseDestroy: function() {
47 this.element.unbind('.'+this.widgetName);
48 if ( this._mouseMoveDelegate ) {
50 .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
51 .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
55 _mouseDown: function(event) {
56 // don't let more than one widget handle mouseStart
57 if( mouseHandled ) { return };
59 // we may have missed mouseup (out of window)
60 (this._mouseStarted && this._mouseUp(event));
62 this._mouseDownEvent = event;
65 btnIsLeft = (event.which == 1),
66 // event.target.nodeName works around a bug in IE 8 with
67 // disabled inputs (#7620)
68 elIsCancel = (typeof this.options.cancel == "string" && event.target.nodeName ? $(event.target).closest(this.options.cancel).length : false);
69 if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
73 this.mouseDelayMet = !this.options.delay;
74 if (!this.mouseDelayMet) {
75 this._mouseDelayTimer = setTimeout(function() {
76 self.mouseDelayMet = true;
77 }, this.options.delay);
80 if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
81 this._mouseStarted = (this._mouseStart(event) !== false);
82 if (!this._mouseStarted) {
83 event.preventDefault();
88 // Click event may never have fired (Gecko & Opera)
89 if (true === $.data(event.target, this.widgetName + '.preventClickEvent')) {
90 $.removeData(event.target, this.widgetName + '.preventClickEvent');
93 // these delegates are required to keep context
94 this._mouseMoveDelegate = function(event) {
95 return self._mouseMove(event);
97 this._mouseUpDelegate = function(event) {
98 return self._mouseUp(event);
101 .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
102 .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
104 event.preventDefault();
110 _mouseMove: function(event) {
111 // IE mouseup check - mouseup happened when mouse was out of window
112 if ($.browser.msie && !(document.documentMode >= 9) && !event.button) {
113 return this._mouseUp(event);
116 if (this._mouseStarted) {
117 this._mouseDrag(event);
118 return event.preventDefault();
121 if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
123 (this._mouseStart(this._mouseDownEvent, event) !== false);
124 (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
127 return !this._mouseStarted;
130 _mouseUp: function(event) {
132 .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
133 .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
135 if (this._mouseStarted) {
136 this._mouseStarted = false;
138 if (event.target == this._mouseDownEvent.target) {
139 $.data(event.target, this.widgetName + '.preventClickEvent', true);
142 this._mouseStop(event);
148 _mouseDistanceMet: function(event) {
150 Math.abs(this._mouseDownEvent.pageX - event.pageX),
151 Math.abs(this._mouseDownEvent.pageY - event.pageY)
152 ) >= this.options.distance
156 _mouseDelayMet: function(event) {
157 return this.mouseDelayMet;
160 // These are placeholder methods, to be overriden by extending plugin
161 _mouseStart: function(event) {},
162 _mouseDrag: function(event) {},
163 _mouseStop: function(event) {},
164 _mouseCapture: function(event) { return true; }