[SPIP] +spip v3.0.17
[lhc/web/clavette_www.git] / www / plugins-dist / jquery_ui / prive / javascript / ui / jquery.ui.mouse.js
1 /*!
2 * jQuery UI Mouse 1.8.21
3 *
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
7 *
8 * http://docs.jquery.com/UI/Mouse
9 *
10 * Depends:
11 * jquery.ui.widget.js
12 */
13 (function( $, undefined ) {
14
15 var mouseHandled = false;
16 $( document ).mouseup( function( e ) {
17 mouseHandled = false;
18 });
19
20 $.widget("ui.mouse", {
21 options: {
22 cancel: ':input,option',
23 distance: 1,
24 delay: 0
25 },
26 _mouseInit: function() {
27 var self = this;
28
29 this.element
30 .bind('mousedown.'+this.widgetName, function(event) {
31 return self._mouseDown(event);
32 })
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();
37 return false;
38 }
39 });
40
41 this.started = false;
42 },
43
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 $(document)
49 .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
50 .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
51 },
52
53 _mouseDown: function(event) {
54 // don't let more than one widget handle mouseStart
55 if( mouseHandled ) { return };
56
57 // we may have missed mouseup (out of window)
58 (this._mouseStarted && this._mouseUp(event));
59
60 this._mouseDownEvent = event;
61
62 var self = this,
63 btnIsLeft = (event.which == 1),
64 // event.target.nodeName works around a bug in IE 8 with
65 // disabled inputs (#7620)
66 elIsCancel = (typeof this.options.cancel == "string" && event.target.nodeName ? $(event.target).closest(this.options.cancel).length : false);
67 if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
68 return true;
69 }
70
71 this.mouseDelayMet = !this.options.delay;
72 if (!this.mouseDelayMet) {
73 this._mouseDelayTimer = setTimeout(function() {
74 self.mouseDelayMet = true;
75 }, this.options.delay);
76 }
77
78 if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
79 this._mouseStarted = (this._mouseStart(event) !== false);
80 if (!this._mouseStarted) {
81 event.preventDefault();
82 return true;
83 }
84 }
85
86 // Click event may never have fired (Gecko & Opera)
87 if (true === $.data(event.target, this.widgetName + '.preventClickEvent')) {
88 $.removeData(event.target, this.widgetName + '.preventClickEvent');
89 }
90
91 // these delegates are required to keep context
92 this._mouseMoveDelegate = function(event) {
93 return self._mouseMove(event);
94 };
95 this._mouseUpDelegate = function(event) {
96 return self._mouseUp(event);
97 };
98 $(document)
99 .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
100 .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
101
102 event.preventDefault();
103
104 mouseHandled = true;
105 return true;
106 },
107
108 _mouseMove: function(event) {
109 // IE mouseup check - mouseup happened when mouse was out of window
110 if ($.browser.msie && !(document.documentMode >= 9) && !event.button) {
111 return this._mouseUp(event);
112 }
113
114 if (this._mouseStarted) {
115 this._mouseDrag(event);
116 return event.preventDefault();
117 }
118
119 if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
120 this._mouseStarted =
121 (this._mouseStart(this._mouseDownEvent, event) !== false);
122 (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
123 }
124
125 return !this._mouseStarted;
126 },
127
128 _mouseUp: function(event) {
129 $(document)
130 .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
131 .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
132
133 if (this._mouseStarted) {
134 this._mouseStarted = false;
135
136 if (event.target == this._mouseDownEvent.target) {
137 $.data(event.target, this.widgetName + '.preventClickEvent', true);
138 }
139
140 this._mouseStop(event);
141 }
142
143 return false;
144 },
145
146 _mouseDistanceMet: function(event) {
147 return (Math.max(
148 Math.abs(this._mouseDownEvent.pageX - event.pageX),
149 Math.abs(this._mouseDownEvent.pageY - event.pageY)
150 ) >= this.options.distance
151 );
152 },
153
154 _mouseDelayMet: function(event) {
155 return this.mouseDelayMet;
156 },
157
158 // These are placeholder methods, to be overriden by extending plugin
159 _mouseStart: function(event) {},
160 _mouseDrag: function(event) {},
161 _mouseStop: function(event) {},
162 _mouseCapture: function(event) { return true; }
163 });
164
165 })(jQuery);