commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / bower_components / jquery-ui / ui / mouse.js
1 /*!
2 * jQuery UI Mouse 1.11.4
3 * http://jqueryui.com
4 *
5 * Copyright jQuery Foundation and other contributors
6 * Released under the MIT license.
7 * http://jquery.org/license
8 *
9 * http://api.jqueryui.com/mouse/
10 */
11 (function( factory ) {
12 if ( typeof define === "function" && define.amd ) {
13
14 // AMD. Register as an anonymous module.
15 define([
16 "jquery",
17 "./widget"
18 ], factory );
19 } else {
20
21 // Browser globals
22 factory( jQuery );
23 }
24 }(function( $ ) {
25
26 var mouseHandled = false;
27 $( document ).mouseup( function() {
28 mouseHandled = false;
29 });
30
31 return $.widget("ui.mouse", {
32 version: "1.11.4",
33 options: {
34 cancel: "input,textarea,button,select,option",
35 distance: 1,
36 delay: 0
37 },
38 _mouseInit: function() {
39 var that = this;
40
41 this.element
42 .bind("mousedown." + this.widgetName, function(event) {
43 return that._mouseDown(event);
44 })
45 .bind("click." + this.widgetName, function(event) {
46 if (true === $.data(event.target, that.widgetName + ".preventClickEvent")) {
47 $.removeData(event.target, that.widgetName + ".preventClickEvent");
48 event.stopImmediatePropagation();
49 return false;
50 }
51 });
52
53 this.started = false;
54 },
55
56 // TODO: make sure destroying one instance of mouse doesn't mess with
57 // other instances of mouse
58 _mouseDestroy: function() {
59 this.element.unbind("." + this.widgetName);
60 if ( this._mouseMoveDelegate ) {
61 this.document
62 .unbind("mousemove." + this.widgetName, this._mouseMoveDelegate)
63 .unbind("mouseup." + this.widgetName, this._mouseUpDelegate);
64 }
65 },
66
67 _mouseDown: function(event) {
68 // don't let more than one widget handle mouseStart
69 if ( mouseHandled ) {
70 return;
71 }
72
73 this._mouseMoved = false;
74
75 // we may have missed mouseup (out of window)
76 (this._mouseStarted && this._mouseUp(event));
77
78 this._mouseDownEvent = event;
79
80 var that = this,
81 btnIsLeft = (event.which === 1),
82 // event.target.nodeName works around a bug in IE 8 with
83 // disabled inputs (#7620)
84 elIsCancel = (typeof this.options.cancel === "string" && event.target.nodeName ? $(event.target).closest(this.options.cancel).length : false);
85 if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
86 return true;
87 }
88
89 this.mouseDelayMet = !this.options.delay;
90 if (!this.mouseDelayMet) {
91 this._mouseDelayTimer = setTimeout(function() {
92 that.mouseDelayMet = true;
93 }, this.options.delay);
94 }
95
96 if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
97 this._mouseStarted = (this._mouseStart(event) !== false);
98 if (!this._mouseStarted) {
99 event.preventDefault();
100 return true;
101 }
102 }
103
104 // Click event may never have fired (Gecko & Opera)
105 if (true === $.data(event.target, this.widgetName + ".preventClickEvent")) {
106 $.removeData(event.target, this.widgetName + ".preventClickEvent");
107 }
108
109 // these delegates are required to keep context
110 this._mouseMoveDelegate = function(event) {
111 return that._mouseMove(event);
112 };
113 this._mouseUpDelegate = function(event) {
114 return that._mouseUp(event);
115 };
116
117 this.document
118 .bind( "mousemove." + this.widgetName, this._mouseMoveDelegate )
119 .bind( "mouseup." + this.widgetName, this._mouseUpDelegate );
120
121 event.preventDefault();
122
123 mouseHandled = true;
124 return true;
125 },
126
127 _mouseMove: function(event) {
128 // Only check for mouseups outside the document if you've moved inside the document
129 // at least once. This prevents the firing of mouseup in the case of IE<9, which will
130 // fire a mousemove event if content is placed under the cursor. See #7778
131 // Support: IE <9
132 if ( this._mouseMoved ) {
133 // IE mouseup check - mouseup happened when mouse was out of window
134 if ($.ui.ie && ( !document.documentMode || document.documentMode < 9 ) && !event.button) {
135 return this._mouseUp(event);
136
137 // Iframe mouseup check - mouseup occurred in another document
138 } else if ( !event.which ) {
139 return this._mouseUp( event );
140 }
141 }
142
143 if ( event.which || event.button ) {
144 this._mouseMoved = true;
145 }
146
147 if (this._mouseStarted) {
148 this._mouseDrag(event);
149 return event.preventDefault();
150 }
151
152 if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
153 this._mouseStarted =
154 (this._mouseStart(this._mouseDownEvent, event) !== false);
155 (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
156 }
157
158 return !this._mouseStarted;
159 },
160
161 _mouseUp: function(event) {
162 this.document
163 .unbind( "mousemove." + this.widgetName, this._mouseMoveDelegate )
164 .unbind( "mouseup." + this.widgetName, this._mouseUpDelegate );
165
166 if (this._mouseStarted) {
167 this._mouseStarted = false;
168
169 if (event.target === this._mouseDownEvent.target) {
170 $.data(event.target, this.widgetName + ".preventClickEvent", true);
171 }
172
173 this._mouseStop(event);
174 }
175
176 mouseHandled = false;
177 return false;
178 },
179
180 _mouseDistanceMet: function(event) {
181 return (Math.max(
182 Math.abs(this._mouseDownEvent.pageX - event.pageX),
183 Math.abs(this._mouseDownEvent.pageY - event.pageY)
184 ) >= this.options.distance
185 );
186 },
187
188 _mouseDelayMet: function(/* event */) {
189 return this.mouseDelayMet;
190 },
191
192 // These are placeholder methods, to be overriden by extending plugin
193 _mouseStart: function(/* event */) {},
194 _mouseDrag: function(/* event */) {},
195 _mouseStop: function(/* event */) {},
196 _mouseCapture: function(/* event */) { return true; }
197 });
198
199 }));