0
|
1 /*!
|
|
2 * jQuery UI Mouse 1.8.11
|
|
3 *
|
|
4 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
|
5 * Dual licensed under the MIT or GPL Version 2 licenses.
|
|
6 * http://jquery.org/license
|
|
7 *
|
|
8 * http://docs.jquery.com/UI/Mouse
|
|
9 *
|
|
10 * Depends:
|
|
11 * jquery.ui.widget.js
|
|
12 */
|
|
13 (function( $, undefined ) {
|
|
14
|
|
15 $.widget("ui.mouse", {
|
|
16 options: {
|
|
17 cancel: ':input,option',
|
|
18 distance: 1,
|
|
19 delay: 0
|
|
20 },
|
|
21 _mouseInit: function() {
|
|
22 var self = this;
|
|
23
|
|
24 this.element
|
|
25 .bind('mousedown.'+this.widgetName, function(event) {
|
|
26 return self._mouseDown(event);
|
|
27 })
|
|
28 .bind('click.'+this.widgetName, function(event) {
|
|
29 if (true === $.data(event.target, self.widgetName + '.preventClickEvent')) {
|
|
30 $.removeData(event.target, self.widgetName + '.preventClickEvent');
|
|
31 event.stopImmediatePropagation();
|
|
32 return false;
|
|
33 }
|
|
34 });
|
|
35
|
|
36 this.started = false;
|
|
37 },
|
|
38
|
|
39 // TODO: make sure destroying one instance of mouse doesn't mess with
|
|
40 // other instances of mouse
|
|
41 _mouseDestroy: function() {
|
|
42 this.element.unbind('.'+this.widgetName);
|
|
43 },
|
|
44
|
|
45 _mouseDown: function(event) {
|
|
46 // don't let more than one widget handle mouseStart
|
|
47 // TODO: figure out why we have to use originalEvent
|
|
48 event.originalEvent = event.originalEvent || {};
|
|
49 if (event.originalEvent.mouseHandled) { return; }
|
|
50
|
|
51 // we may have missed mouseup (out of window)
|
|
52 (this._mouseStarted && this._mouseUp(event));
|
|
53
|
|
54 this._mouseDownEvent = event;
|
|
55
|
|
56 var self = this,
|
|
57 btnIsLeft = (event.which == 1),
|
|
58 elIsCancel = (typeof this.options.cancel == "string" ? $(event.target).parents().add(event.target).filter(this.options.cancel).length : false);
|
|
59 if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
|
|
60 return true;
|
|
61 }
|
|
62
|
|
63 this.mouseDelayMet = !this.options.delay;
|
|
64 if (!this.mouseDelayMet) {
|
|
65 this._mouseDelayTimer = setTimeout(function() {
|
|
66 self.mouseDelayMet = true;
|
|
67 }, this.options.delay);
|
|
68 }
|
|
69
|
|
70 if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
|
|
71 this._mouseStarted = (this._mouseStart(event) !== false);
|
|
72 if (!this._mouseStarted) {
|
|
73 event.preventDefault();
|
|
74 return true;
|
|
75 }
|
|
76 }
|
|
77
|
|
78 // Click event may never have fired (Gecko & Opera)
|
|
79 if (true === $.data(event.target, this.widgetName + '.preventClickEvent')) {
|
|
80 $.removeData(event.target, this.widgetName + '.preventClickEvent');
|
|
81 }
|
|
82
|
|
83 // these delegates are required to keep context
|
|
84 this._mouseMoveDelegate = function(event) {
|
|
85 return self._mouseMove(event);
|
|
86 };
|
|
87 this._mouseUpDelegate = function(event) {
|
|
88 return self._mouseUp(event);
|
|
89 };
|
|
90 $(document)
|
|
91 .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
|
|
92 .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
|
|
93
|
|
94 event.preventDefault();
|
|
95 event.originalEvent.mouseHandled = true;
|
|
96 return true;
|
|
97 },
|
|
98
|
|
99 _mouseMove: function(event) {
|
|
100 // IE mouseup check - mouseup happened when mouse was out of window
|
|
101 if ($.browser.msie && !(document.documentMode >= 9) && !event.button) {
|
|
102 return this._mouseUp(event);
|
|
103 }
|
|
104
|
|
105 if (this._mouseStarted) {
|
|
106 this._mouseDrag(event);
|
|
107 return event.preventDefault();
|
|
108 }
|
|
109
|
|
110 if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
|
|
111 this._mouseStarted =
|
|
112 (this._mouseStart(this._mouseDownEvent, event) !== false);
|
|
113 (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
|
|
114 }
|
|
115
|
|
116 return !this._mouseStarted;
|
|
117 },
|
|
118
|
|
119 _mouseUp: function(event) {
|
|
120 $(document)
|
|
121 .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
|
|
122 .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
|
|
123
|
|
124 if (this._mouseStarted) {
|
|
125 this._mouseStarted = false;
|
|
126
|
|
127 if (event.target == this._mouseDownEvent.target) {
|
|
128 $.data(event.target, this.widgetName + '.preventClickEvent', true);
|
|
129 }
|
|
130
|
|
131 this._mouseStop(event);
|
|
132 }
|
|
133
|
|
134 return false;
|
|
135 },
|
|
136
|
|
137 _mouseDistanceMet: function(event) {
|
|
138 return (Math.max(
|
|
139 Math.abs(this._mouseDownEvent.pageX - event.pageX),
|
|
140 Math.abs(this._mouseDownEvent.pageY - event.pageY)
|
|
141 ) >= this.options.distance
|
|
142 );
|
|
143 },
|
|
144
|
|
145 _mouseDelayMet: function(event) {
|
|
146 return this.mouseDelayMet;
|
|
147 },
|
|
148
|
|
149 // These are placeholder methods, to be overriden by extending plugin
|
|
150 _mouseStart: function(event) {},
|
|
151 _mouseDrag: function(event) {},
|
|
152 _mouseStop: function(event) {},
|
|
153 _mouseCapture: function(event) { return true; }
|
|
154 });
|
|
155
|
|
156 })(jQuery);
|