2 * jQuery UI Mouse 1.8
\r
4 * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
\r
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
\r
6 * and GPL (GPL-LICENSE.txt) licenses.
\r
8 * http://docs.jquery.com/UI/Mouse
\r
11 * jquery.ui.widget.js
\r
15 $.widget("ui.mouse", {
\r
17 cancel: ':input,option',
\r
21 _mouseInit: function() {
\r
25 .bind('mousedown.'+this.widgetName, function(event) {
\r
26 return self._mouseDown(event);
\r
28 .bind('click.'+this.widgetName, function(event) {
\r
29 if(self._preventClickEvent) {
\r
30 self._preventClickEvent = false;
\r
31 event.stopImmediatePropagation();
\r
36 this.started = false;
\r
39 // TODO: make sure destroying one instance of mouse doesn't mess with
\r
40 // other instances of mouse
\r
41 _mouseDestroy: function() {
\r
42 this.element.unbind('.'+this.widgetName);
\r
45 _mouseDown: function(event) {
\r
46 // don't let more than one widget handle mouseStart
\r
47 // TODO: figure out why we have to use originalEvent
\r
48 event.originalEvent = event.originalEvent || {};
\r
49 if (event.originalEvent.mouseHandled) { return; }
\r
51 // we may have missed mouseup (out of window)
\r
52 (this._mouseStarted && this._mouseUp(event));
\r
54 this._mouseDownEvent = event;
\r
57 btnIsLeft = (event.which == 1),
\r
58 elIsCancel = (typeof this.options.cancel == "string" ? $(event.target).parents().add(event.target).filter(this.options.cancel).length : false);
\r
59 if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
\r
63 this.mouseDelayMet = !this.options.delay;
\r
64 if (!this.mouseDelayMet) {
\r
65 this._mouseDelayTimer = setTimeout(function() {
\r
66 self.mouseDelayMet = true;
\r
67 }, this.options.delay);
\r
70 if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
\r
71 this._mouseStarted = (this._mouseStart(event) !== false);
\r
72 if (!this._mouseStarted) {
\r
73 event.preventDefault();
\r
78 // these delegates are required to keep context
\r
79 this._mouseMoveDelegate = function(event) {
\r
80 return self._mouseMove(event);
\r
82 this._mouseUpDelegate = function(event) {
\r
83 return self._mouseUp(event);
\r
86 .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
\r
87 .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
\r
89 // preventDefault() is used to prevent the selection of text here -
\r
90 // however, in Safari, this causes select boxes not to be selectable
\r
91 // anymore, so this fix is needed
\r
92 ($.browser.safari || event.preventDefault());
\r
94 event.originalEvent.mouseHandled = true;
\r
98 _mouseMove: function(event) {
\r
99 // IE mouseup check - mouseup happened when mouse was out of window
\r
100 if ($.browser.msie && !event.button) {
\r
101 return this._mouseUp(event);
\r
104 if (this._mouseStarted) {
\r
105 this._mouseDrag(event);
\r
106 return event.preventDefault();
\r
109 if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
\r
110 this._mouseStarted =
\r
111 (this._mouseStart(this._mouseDownEvent, event) !== false);
\r
112 (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
\r
115 return !this._mouseStarted;
\r
118 _mouseUp: function(event) {
\r
120 .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
\r
121 .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
\r
123 if (this._mouseStarted) {
\r
124 this._mouseStarted = false;
\r
125 this._preventClickEvent = (event.target == this._mouseDownEvent.target);
\r
126 this._mouseStop(event);
\r
132 _mouseDistanceMet: function(event) {
\r
134 Math.abs(this._mouseDownEvent.pageX - event.pageX),
\r
135 Math.abs(this._mouseDownEvent.pageY - event.pageY)
\r
136 ) >= this.options.distance
\r
140 _mouseDelayMet: function(event) {
\r
141 return this.mouseDelayMet;
\r
144 // These are placeholder methods, to be overriden by extending plugin
\r
145 _mouseStart: function(event) {},
\r
146 _mouseDrag: function(event) {},
\r
147 _mouseStop: function(event) {},
\r
148 _mouseCapture: function(event) { return true; }
\r