Révision 503b3f7b
Ajouté par Assos Assos il y a environ 10 ans
drupal7/sites/all/modules/jquery_update/replace/ui/ui/jquery.ui.droppable.js | ||
---|---|---|
1 |
/* |
|
2 |
* jQuery UI Droppable 1.8.11 |
|
1 |
/*! |
|
2 |
* jQuery UI Droppable 1.10.2 |
|
3 |
* http://jqueryui.com |
|
3 | 4 |
* |
4 |
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
|
5 |
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
5 |
* Copyright 2013 jQuery Foundation and other contributors
|
|
6 |
* Released under the MIT license.
|
|
6 | 7 |
* http://jquery.org/license |
7 | 8 |
* |
8 |
* http://docs.jquery.com/UI/Droppables
|
|
9 |
* http://api.jqueryui.com/droppable/
|
|
9 | 10 |
* |
10 | 11 |
* Depends: |
11 | 12 |
* jquery.ui.core.js |
... | ... | |
15 | 16 |
*/ |
16 | 17 |
(function( $, undefined ) { |
17 | 18 |
|
19 |
function isOverAxis( x, reference, size ) { |
|
20 |
return ( x > reference ) && ( x < ( reference + size ) ); |
|
21 |
} |
|
22 |
|
|
18 | 23 |
$.widget("ui.droppable", { |
24 |
version: "1.10.2", |
|
19 | 25 |
widgetEventPrefix: "drop", |
20 | 26 |
options: { |
21 |
accept: '*',
|
|
27 |
accept: "*",
|
|
22 | 28 |
activeClass: false, |
23 | 29 |
addClasses: true, |
24 | 30 |
greedy: false, |
25 | 31 |
hoverClass: false, |
26 |
scope: 'default', |
|
27 |
tolerance: 'intersect' |
|
32 |
scope: "default", |
|
33 |
tolerance: "intersect", |
|
34 |
|
|
35 |
// callbacks |
|
36 |
activate: null, |
|
37 |
deactivate: null, |
|
38 |
drop: null, |
|
39 |
out: null, |
|
40 |
over: null |
|
28 | 41 |
}, |
29 | 42 |
_create: function() { |
30 | 43 |
|
31 |
var o = this.options, accept = o.accept; |
|
32 |
this.isover = 0; this.isout = 1; |
|
44 |
var o = this.options, |
|
45 |
accept = o.accept; |
|
46 |
|
|
47 |
this.isover = false; |
|
48 |
this.isout = true; |
|
33 | 49 |
|
34 | 50 |
this.accept = $.isFunction(accept) ? accept : function(d) { |
35 | 51 |
return d.is(accept); |
... | ... | |
46 | 62 |
|
47 | 63 |
}, |
48 | 64 |
|
49 |
destroy: function() { |
|
50 |
var drop = $.ui.ddmanager.droppables[this.options.scope]; |
|
51 |
for ( var i = 0; i < drop.length; i++ ) |
|
52 |
if ( drop[i] == this ) |
|
53 |
drop.splice(i, 1); |
|
65 |
_destroy: function() { |
|
66 |
var i = 0, |
|
67 |
drop = $.ui.ddmanager.droppables[this.options.scope]; |
|
54 | 68 |
|
55 |
this.element |
|
56 |
.removeClass("ui-droppable ui-droppable-disabled") |
|
57 |
.removeData("droppable") |
|
58 |
.unbind(".droppable"); |
|
69 |
for ( ; i < drop.length; i++ ) { |
|
70 |
if ( drop[i] === this ) { |
|
71 |
drop.splice(i, 1); |
|
72 |
} |
|
73 |
} |
|
59 | 74 |
|
60 |
return this;
|
|
75 |
this.element.removeClass("ui-droppable ui-droppable-disabled");
|
|
61 | 76 |
}, |
62 | 77 |
|
63 | 78 |
_setOption: function(key, value) { |
64 | 79 |
|
65 |
if(key == 'accept') {
|
|
80 |
if(key === "accept") {
|
|
66 | 81 |
this.accept = $.isFunction(value) ? value : function(d) { |
67 | 82 |
return d.is(value); |
68 | 83 |
}; |
... | ... | |
72 | 87 |
|
73 | 88 |
_activate: function(event) { |
74 | 89 |
var draggable = $.ui.ddmanager.current; |
75 |
if(this.options.activeClass) this.element.addClass(this.options.activeClass); |
|
76 |
(draggable && this._trigger('activate', event, this.ui(draggable))); |
|
90 |
if(this.options.activeClass) { |
|
91 |
this.element.addClass(this.options.activeClass); |
|
92 |
} |
|
93 |
if(draggable){ |
|
94 |
this._trigger("activate", event, this.ui(draggable)); |
|
95 |
} |
|
77 | 96 |
}, |
78 | 97 |
|
79 | 98 |
_deactivate: function(event) { |
80 | 99 |
var draggable = $.ui.ddmanager.current; |
81 |
if(this.options.activeClass) this.element.removeClass(this.options.activeClass); |
|
82 |
(draggable && this._trigger('deactivate', event, this.ui(draggable))); |
|
100 |
if(this.options.activeClass) { |
|
101 |
this.element.removeClass(this.options.activeClass); |
|
102 |
} |
|
103 |
if(draggable){ |
|
104 |
this._trigger("deactivate", event, this.ui(draggable)); |
|
105 |
} |
|
83 | 106 |
}, |
84 | 107 |
|
85 | 108 |
_over: function(event) { |
86 | 109 |
|
87 | 110 |
var draggable = $.ui.ddmanager.current; |
88 |
if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element |
|
111 |
|
|
112 |
// Bail if draggable and droppable are same element |
|
113 |
if (!draggable || (draggable.currentItem || draggable.element)[0] === this.element[0]) { |
|
114 |
return; |
|
115 |
} |
|
89 | 116 |
|
90 | 117 |
if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) { |
91 |
if(this.options.hoverClass) this.element.addClass(this.options.hoverClass); |
|
92 |
this._trigger('over', event, this.ui(draggable)); |
|
118 |
if(this.options.hoverClass) { |
|
119 |
this.element.addClass(this.options.hoverClass); |
|
120 |
} |
|
121 |
this._trigger("over", event, this.ui(draggable)); |
|
93 | 122 |
} |
94 | 123 |
|
95 | 124 |
}, |
... | ... | |
97 | 126 |
_out: function(event) { |
98 | 127 |
|
99 | 128 |
var draggable = $.ui.ddmanager.current; |
100 |
if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element |
|
129 |
|
|
130 |
// Bail if draggable and droppable are same element |
|
131 |
if (!draggable || (draggable.currentItem || draggable.element)[0] === this.element[0]) { |
|
132 |
return; |
|
133 |
} |
|
101 | 134 |
|
102 | 135 |
if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) { |
103 |
if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass); |
|
104 |
this._trigger('out', event, this.ui(draggable)); |
|
136 |
if(this.options.hoverClass) { |
|
137 |
this.element.removeClass(this.options.hoverClass); |
|
138 |
} |
|
139 |
this._trigger("out", event, this.ui(draggable)); |
|
105 | 140 |
} |
106 | 141 |
|
107 | 142 |
}, |
108 | 143 |
|
109 | 144 |
_drop: function(event,custom) { |
110 | 145 |
|
111 |
var draggable = custom || $.ui.ddmanager.current; |
|
112 |
if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return false; // Bail if draggable and droppable are same element |
|
146 |
var draggable = custom || $.ui.ddmanager.current, |
|
147 |
childrenIntersection = false; |
|
148 |
|
|
149 |
// Bail if draggable and droppable are same element |
|
150 |
if (!draggable || (draggable.currentItem || draggable.element)[0] === this.element[0]) { |
|
151 |
return false; |
|
152 |
} |
|
113 | 153 |
|
114 |
var childrenIntersection = false; |
|
115 |
this.element.find(":data(droppable)").not(".ui-draggable-dragging").each(function() { |
|
116 |
var inst = $.data(this, 'droppable'); |
|
154 |
this.element.find(":data(ui-droppable)").not(".ui-draggable-dragging").each(function() { |
|
155 |
var inst = $.data(this, "ui-droppable"); |
|
117 | 156 |
if( |
118 |
inst.options.greedy |
|
119 |
&& !inst.options.disabled
|
|
120 |
&& inst.options.scope == draggable.options.scope
|
|
121 |
&& inst.accept.call(inst.element[0], (draggable.currentItem || draggable.element))
|
|
122 |
&& $.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance)
|
|
157 |
inst.options.greedy &&
|
|
158 |
!inst.options.disabled &&
|
|
159 |
inst.options.scope === draggable.options.scope &&
|
|
160 |
inst.accept.call(inst.element[0], (draggable.currentItem || draggable.element)) &&
|
|
161 |
$.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance) |
|
123 | 162 |
) { childrenIntersection = true; return false; } |
124 | 163 |
}); |
125 |
if(childrenIntersection) return false; |
|
164 |
if(childrenIntersection) { |
|
165 |
return false; |
|
166 |
} |
|
126 | 167 |
|
127 | 168 |
if(this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) { |
128 |
if(this.options.activeClass) this.element.removeClass(this.options.activeClass); |
|
129 |
if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass); |
|
130 |
this._trigger('drop', event, this.ui(draggable)); |
|
169 |
if(this.options.activeClass) { |
|
170 |
this.element.removeClass(this.options.activeClass); |
|
171 |
} |
|
172 |
if(this.options.hoverClass) { |
|
173 |
this.element.removeClass(this.options.hoverClass); |
|
174 |
} |
|
175 |
this._trigger("drop", event, this.ui(draggable)); |
|
131 | 176 |
return this.element; |
132 | 177 |
} |
133 | 178 |
|
... | ... | |
146 | 191 |
|
147 | 192 |
}); |
148 | 193 |
|
149 |
$.extend($.ui.droppable, { |
|
150 |
version: "1.8.11" |
|
151 |
}); |
|
152 |
|
|
153 | 194 |
$.ui.intersect = function(draggable, droppable, toleranceMode) { |
154 | 195 |
|
155 |
if (!droppable.offset) return false; |
|
196 |
if (!droppable.offset) { |
|
197 |
return false; |
|
198 |
} |
|
156 | 199 |
|
157 |
var x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width, |
|
158 |
y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height; |
|
159 |
var l = droppable.offset.left, r = l + droppable.proportions.width, |
|
200 |
var draggableLeft, draggableTop, |
|
201 |
x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width, |
|
202 |
y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height, |
|
203 |
l = droppable.offset.left, r = l + droppable.proportions.width, |
|
160 | 204 |
t = droppable.offset.top, b = t + droppable.proportions.height; |
161 | 205 |
|
162 | 206 |
switch (toleranceMode) { |
163 |
case 'fit': |
|
164 |
return (l <= x1 && x2 <= r |
|
165 |
&& t <= y1 && y2 <= b); |
|
166 |
break; |
|
167 |
case 'intersect': |
|
168 |
return (l < x1 + (draggable.helperProportions.width / 2) // Right Half |
|
169 |
&& x2 - (draggable.helperProportions.width / 2) < r // Left Half |
|
170 |
&& t < y1 + (draggable.helperProportions.height / 2) // Bottom Half |
|
171 |
&& y2 - (draggable.helperProportions.height / 2) < b ); // Top Half |
|
172 |
break; |
|
173 |
case 'pointer': |
|
174 |
var draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left), |
|
175 |
draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top), |
|
176 |
isOver = $.ui.isOver(draggableTop, draggableLeft, t, l, droppable.proportions.height, droppable.proportions.width); |
|
177 |
return isOver; |
|
178 |
break; |
|
179 |
case 'touch': |
|
207 |
case "fit": |
|
208 |
return (l <= x1 && x2 <= r && t <= y1 && y2 <= b); |
|
209 |
case "intersect": |
|
210 |
return (l < x1 + (draggable.helperProportions.width / 2) && // Right Half |
|
211 |
x2 - (draggable.helperProportions.width / 2) < r && // Left Half |
|
212 |
t < y1 + (draggable.helperProportions.height / 2) && // Bottom Half |
|
213 |
y2 - (draggable.helperProportions.height / 2) < b ); // Top Half |
|
214 |
case "pointer": |
|
215 |
draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left); |
|
216 |
draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top); |
|
217 |
return isOverAxis( draggableTop, t, droppable.proportions.height ) && isOverAxis( draggableLeft, l, droppable.proportions.width ); |
|
218 |
case "touch": |
|
180 | 219 |
return ( |
181 |
(y1 >= t && y1 <= b) || // Top edge touching |
|
182 |
(y2 >= t && y2 <= b) || // Bottom edge touching |
|
183 |
(y1 < t && y2 > b) // Surrounded vertically |
|
184 |
) && ( |
|
185 |
(x1 >= l && x1 <= r) || // Left edge touching |
|
186 |
(x2 >= l && x2 <= r) || // Right edge touching |
|
187 |
(x1 < l && x2 > r) // Surrounded horizontally |
|
188 |
); |
|
189 |
break; |
|
220 |
(y1 >= t && y1 <= b) || // Top edge touching |
|
221 |
(y2 >= t && y2 <= b) || // Bottom edge touching |
|
222 |
(y1 < t && y2 > b) // Surrounded vertically |
|
223 |
) && ( |
|
224 |
(x1 >= l && x1 <= r) || // Left edge touching |
|
225 |
(x2 >= l && x2 <= r) || // Right edge touching |
|
226 |
(x1 < l && x2 > r) // Surrounded horizontally |
|
227 |
); |
|
190 | 228 |
default: |
191 | 229 |
return false; |
192 |
break; |
|
193 | 230 |
} |
194 | 231 |
|
195 | 232 |
}; |
... | ... | |
199 | 236 |
*/ |
200 | 237 |
$.ui.ddmanager = { |
201 | 238 |
current: null, |
202 |
droppables: { 'default': [] },
|
|
239 |
droppables: { "default": [] },
|
|
203 | 240 |
prepareOffsets: function(t, event) { |
204 | 241 |
|
205 |
var m = $.ui.ddmanager.droppables[t.options.scope] || []; |
|
206 |
var type = event ? event.type : null; // workaround for #2317 |
|
207 |
var list = (t.currentItem || t.element).find(":data(droppable)").andSelf(); |
|
242 |
var i, j, |
|
243 |
m = $.ui.ddmanager.droppables[t.options.scope] || [], |
|
244 |
type = event ? event.type : null, // workaround for #2317 |
|
245 |
list = (t.currentItem || t.element).find(":data(ui-droppable)").addBack(); |
|
246 |
|
|
247 |
droppablesLoop: for (i = 0; i < m.length; i++) { |
|
248 |
|
|
249 |
//No disabled and non-accepted |
|
250 |
if(m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) { |
|
251 |
continue; |
|
252 |
} |
|
208 | 253 |
|
209 |
droppablesLoop: for (var i = 0; i < m.length; i++) { |
|
254 |
// Filter out elements in the current dragged item |
|
255 |
for (j=0; j < list.length; j++) { |
|
256 |
if(list[j] === m[i].element[0]) { |
|
257 |
m[i].proportions.height = 0; |
|
258 |
continue droppablesLoop; |
|
259 |
} |
|
260 |
} |
|
210 | 261 |
|
211 |
if(m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) continue; //No disabled and non-accepted |
|
212 |
for (var j=0; j < list.length; j++) { if(list[j] == m[i].element[0]) { m[i].proportions.height = 0; continue droppablesLoop; } }; //Filter out elements in the current dragged item |
|
213 |
m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; //If the element is not visible, continue |
|
262 |
m[i].visible = m[i].element.css("display") !== "none"; |
|
263 |
if(!m[i].visible) { |
|
264 |
continue; |
|
265 |
} |
|
214 | 266 |
|
215 |
if(type == "mousedown") m[i]._activate.call(m[i], event); //Activate the droppable if used directly from draggables |
|
267 |
//Activate the droppable if used directly from draggables |
|
268 |
if(type === "mousedown") { |
|
269 |
m[i]._activate.call(m[i], event); |
|
270 |
} |
|
216 | 271 |
|
217 | 272 |
m[i].offset = m[i].element.offset(); |
218 | 273 |
m[i].proportions = { width: m[i].element[0].offsetWidth, height: m[i].element[0].offsetHeight }; |
... | ... | |
223 | 278 |
drop: function(draggable, event) { |
224 | 279 |
|
225 | 280 |
var dropped = false; |
226 |
$.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() { |
|
281 |
// Create a copy of the droppables in case the list changes during the drop (#9116) |
|
282 |
$.each(($.ui.ddmanager.droppables[draggable.options.scope] || []).slice(), function() { |
|
227 | 283 |
|
228 |
if(!this.options) return; |
|
229 |
if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance)) |
|
230 |
dropped = dropped || this._drop.call(this, event); |
|
284 |
if(!this.options) { |
|
285 |
return; |
|
286 |
} |
|
287 |
if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance)) { |
|
288 |
dropped = this._drop.call(this, event) || dropped; |
|
289 |
} |
|
231 | 290 |
|
232 | 291 |
if (!this.options.disabled && this.visible && this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) { |
233 |
this.isout = 1; this.isover = 0; |
|
292 |
this.isout = true; |
|
293 |
this.isover = false; |
|
234 | 294 |
this._deactivate.call(this, event); |
235 | 295 |
} |
236 | 296 |
|
... | ... | |
238 | 298 |
return dropped; |
239 | 299 |
|
240 | 300 |
}, |
301 |
dragStart: function( draggable, event ) { |
|
302 |
//Listen for scrolling so that if the dragging causes scrolling the position of the droppables can be recalculated (see #5003) |
|
303 |
draggable.element.parentsUntil( "body" ).bind( "scroll.droppable", function() { |
|
304 |
if( !draggable.options.refreshPositions ) { |
|
305 |
$.ui.ddmanager.prepareOffsets( draggable, event ); |
|
306 |
} |
|
307 |
}); |
|
308 |
}, |
|
241 | 309 |
drag: function(draggable, event) { |
242 | 310 |
|
243 | 311 |
//If you have a highly dynamic page, you might try this option. It renders positions every time you move the mouse. |
244 |
if(draggable.options.refreshPositions) $.ui.ddmanager.prepareOffsets(draggable, event); |
|
312 |
if(draggable.options.refreshPositions) { |
|
313 |
$.ui.ddmanager.prepareOffsets(draggable, event); |
|
314 |
} |
|
245 | 315 |
|
246 | 316 |
//Run through all droppables and check their positions based on specific tolerance options |
247 | 317 |
$.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() { |
248 | 318 |
|
249 |
if(this.options.disabled || this.greedyChild || !this.visible) return; |
|
250 |
var intersects = $.ui.intersect(draggable, this, this.options.tolerance); |
|
319 |
if(this.options.disabled || this.greedyChild || !this.visible) { |
|
320 |
return; |
|
321 |
} |
|
251 | 322 |
|
252 |
var c = !intersects && this.isover == 1 ? 'isout' : (intersects && this.isover == 0 ? 'isover' : null); |
|
253 |
if(!c) return; |
|
323 |
var parentInstance, scope, parent, |
|
324 |
intersects = $.ui.intersect(draggable, this, this.options.tolerance), |
|
325 |
c = !intersects && this.isover ? "isout" : (intersects && !this.isover ? "isover" : null); |
|
326 |
if(!c) { |
|
327 |
return; |
|
328 |
} |
|
254 | 329 |
|
255 |
var parentInstance; |
|
256 | 330 |
if (this.options.greedy) { |
257 |
var parent = this.element.parents(':data(droppable):eq(0)'); |
|
331 |
// find droppable parents with same scope |
|
332 |
scope = this.options.scope; |
|
333 |
parent = this.element.parents(":data(ui-droppable)").filter(function () { |
|
334 |
return $.data(this, "ui-droppable").options.scope === scope; |
|
335 |
}); |
|
336 |
|
|
258 | 337 |
if (parent.length) { |
259 |
parentInstance = $.data(parent[0], 'droppable');
|
|
260 |
parentInstance.greedyChild = (c == 'isover' ? 1 : 0);
|
|
338 |
parentInstance = $.data(parent[0], "ui-droppable");
|
|
339 |
parentInstance.greedyChild = (c === "isover");
|
|
261 | 340 |
} |
262 | 341 |
} |
263 | 342 |
|
264 | 343 |
// we just moved into a greedy child |
265 |
if (parentInstance && c == 'isover') {
|
|
266 |
parentInstance['isover'] = 0;
|
|
267 |
parentInstance['isout'] = 1;
|
|
344 |
if (parentInstance && c === "isover") {
|
|
345 |
parentInstance.isover = false;
|
|
346 |
parentInstance.isout = true;
|
|
268 | 347 |
parentInstance._out.call(parentInstance, event); |
269 | 348 |
} |
270 | 349 |
|
271 |
this[c] = 1; this[c == 'isout' ? 'isover' : 'isout'] = 0; |
|
272 |
this[c == "isover" ? "_over" : "_out"].call(this, event); |
|
350 |
this[c] = true; |
|
351 |
this[c === "isout" ? "isover" : "isout"] = false; |
|
352 |
this[c === "isover" ? "_over" : "_out"].call(this, event); |
|
273 | 353 |
|
274 | 354 |
// we just moved out of a greedy child |
275 |
if (parentInstance && c == 'isout') {
|
|
276 |
parentInstance['isout'] = 0;
|
|
277 |
parentInstance['isover'] = 1;
|
|
355 |
if (parentInstance && c === "isout") {
|
|
356 |
parentInstance.isout = false;
|
|
357 |
parentInstance.isover = true;
|
|
278 | 358 |
parentInstance._over.call(parentInstance, event); |
279 | 359 |
} |
280 | 360 |
}); |
281 | 361 |
|
362 |
}, |
|
363 |
dragStop: function( draggable, event ) { |
|
364 |
draggable.element.parentsUntil( "body" ).unbind( "scroll.droppable" ); |
|
365 |
//Call prepareOffsets one final time since IE does not fire return scroll events when overflow was caused by drag (see #5003) |
|
366 |
if( !draggable.options.refreshPositions ) { |
|
367 |
$.ui.ddmanager.prepareOffsets( draggable, event ); |
|
368 |
} |
|
282 | 369 |
} |
283 | 370 |
}; |
284 | 371 |
|
Formats disponibles : Unified diff
Weekly update of contrib modules