Merge "Whitelist the <wbr> element."
[mediawiki.git] / resources / jquery.ui / jquery.ui.mouse.js
blob52a1786c695faf610a0a952dd98c1341ebd2aa94
1 /*!
2  * jQuery UI Mouse 1.8.24
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 ) {
15 var mouseHandled = false;
16 $( document ).mouseup( function( e ) {
17         mouseHandled = false;
18 });
20 $.widget("ui.mouse", {
21         options: {
22                 cancel: ':input,option',
23                 distance: 1,
24                 delay: 0
25         },
26         _mouseInit: function() {
27                 var self = this;
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                         });
41                 this.started = false;
42         },
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 ) {
49                         $(document)
50                                 .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
51                                 .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
52                 }
53         },
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;
64                 var self = this,
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)) {
70                         return true;
71                 }
73                 this.mouseDelayMet = !this.options.delay;
74                 if (!this.mouseDelayMet) {
75                         this._mouseDelayTimer = setTimeout(function() {
76                                 self.mouseDelayMet = true;
77                         }, this.options.delay);
78                 }
80                 if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
81                         this._mouseStarted = (this._mouseStart(event) !== false);
82                         if (!this._mouseStarted) {
83                                 event.preventDefault();
84                                 return true;
85                         }
86                 }
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');
91                 }
93                 // these delegates are required to keep context
94                 this._mouseMoveDelegate = function(event) {
95                         return self._mouseMove(event);
96                 };
97                 this._mouseUpDelegate = function(event) {
98                         return self._mouseUp(event);
99                 };
100                 $(document)
101                         .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
102                         .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
104                 event.preventDefault();
105                 
106                 mouseHandled = true;
107                 return true;
108         },
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);
114                 }
116                 if (this._mouseStarted) {
117                         this._mouseDrag(event);
118                         return event.preventDefault();
119                 }
121                 if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
122                         this._mouseStarted =
123                                 (this._mouseStart(this._mouseDownEvent, event) !== false);
124                         (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
125                 }
127                 return !this._mouseStarted;
128         },
130         _mouseUp: function(event) {
131                 $(document)
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);
140                         }
142                         this._mouseStop(event);
143                 }
145                 return false;
146         },
148         _mouseDistanceMet: function(event) {
149                 return (Math.max(
150                                 Math.abs(this._mouseDownEvent.pageX - event.pageX),
151                                 Math.abs(this._mouseDownEvent.pageY - event.pageY)
152                         ) >= this.options.distance
153                 );
154         },
156         _mouseDelayMet: function(event) {
157                 return this.mouseDelayMet;
158         },
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; }
167 })(jQuery);