comparison war/scripts/jQuery/ui/jquery.ui.mouse.js @ 3:cf06b77a8bbd

Committed branch of the e4D repos sti-gwt branch 16384. git-svn-id: http://dev.dariah.eu/svn/repos/eu.dariah.de/ap1/sti-gwt-dariah-geobrowser@36 f2b5be40-def6-11e0-8a09-b3c1cc336c6b
author StefanFunk <StefanFunk@f2b5be40-def6-11e0-8a09-b3c1cc336c6b>
date Tue, 17 Jul 2012 13:34:40 +0000
parents
children
comparison
equal deleted inserted replaced
2:2897af43ccc6 3:cf06b77a8bbd
1 /*!
2 * jQuery UI Mouse 1.8.14
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 var mouseHandled = false;
16 $(document).mousedown(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 },
49
50 _mouseDown: function(event) {
51 // don't let more than one widget handle mouseStart
52 if(mouseHandled) {return};
53
54 // we may have missed mouseup (out of window)
55 (this._mouseStarted && this._mouseUp(event));
56
57 this._mouseDownEvent = event;
58
59 var self = this,
60 btnIsLeft = (event.which == 1),
61 elIsCancel = (typeof this.options.cancel == "string" ? $(event.target).closest(this.options.cancel).length : false);
62 if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
63 return true;
64 }
65
66 this.mouseDelayMet = !this.options.delay;
67 if (!this.mouseDelayMet) {
68 this._mouseDelayTimer = setTimeout(function() {
69 self.mouseDelayMet = true;
70 }, this.options.delay);
71 }
72
73 if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
74 this._mouseStarted = (this._mouseStart(event) !== false);
75 if (!this._mouseStarted) {
76 event.preventDefault();
77 return true;
78 }
79 }
80
81 // Click event may never have fired (Gecko & Opera)
82 if (true === $.data(event.target, this.widgetName + '.preventClickEvent')) {
83 $.removeData(event.target, this.widgetName + '.preventClickEvent');
84 }
85
86 // these delegates are required to keep context
87 this._mouseMoveDelegate = function(event) {
88 return self._mouseMove(event);
89 };
90 this._mouseUpDelegate = function(event) {
91 return self._mouseUp(event);
92 };
93 $(document)
94 .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
95 .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
96
97 event.preventDefault();
98
99 mouseHandled = true;
100 return true;
101 },
102
103 _mouseMove: function(event) {
104 // IE mouseup check - mouseup happened when mouse was out of window
105 if ($.browser.msie && !(document.documentMode >= 9) && !event.button) {
106 return this._mouseUp(event);
107 }
108
109 if (this._mouseStarted) {
110 this._mouseDrag(event);
111 return event.preventDefault();
112 }
113
114 if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
115 this._mouseStarted =
116 (this._mouseStart(this._mouseDownEvent, event) !== false);
117 (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
118 }
119
120 return !this._mouseStarted;
121 },
122
123 _mouseUp: function(event) {
124 $(document)
125 .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
126 .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
127
128 if (this._mouseStarted) {
129 this._mouseStarted = false;
130
131 if (event.target == this._mouseDownEvent.target) {
132 $.data(event.target, this.widgetName + '.preventClickEvent', true);
133 }
134
135 this._mouseStop(event);
136 }
137
138 return false;
139 },
140
141 _mouseDistanceMet: function(event) {
142 return (Math.max(
143 Math.abs(this._mouseDownEvent.pageX - event.pageX),
144 Math.abs(this._mouseDownEvent.pageY - event.pageY)
145 ) >= this.options.distance
146 );
147 },
148
149 _mouseDelayMet: function(event) {
150 return this.mouseDelayMet;
151 },
152
153 // These are placeholder methods, to be overriden by extending plugin
154 _mouseStart: function(event) {},
155 _mouseDrag: function(event) {},
156 _mouseStop: function(event) {},
157 _mouseCapture: function(event) { return true; }
158 });
159
160 })(jQuery);