Révision 503b3f7b
Ajouté par Assos Assos il y a environ 10 ans
drupal7/sites/all/modules/jquery_update/replace/ui/ui/jquery.ui.sortable.js | ||
---|---|---|
1 |
/* |
|
2 |
* jQuery UI Sortable 1.8.11 |
|
1 |
/*! |
|
2 |
* jQuery UI Sortable 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/Sortables
|
|
9 |
* http://api.jqueryui.com/sortable/
|
|
9 | 10 |
* |
10 | 11 |
* Depends: |
11 | 12 |
* jquery.ui.core.js |
... | ... | |
14 | 15 |
*/ |
15 | 16 |
(function( $, undefined ) { |
16 | 17 |
|
18 |
/*jshint loopfunc: true */ |
|
19 |
|
|
20 |
function isOverAxis( x, reference, size ) { |
|
21 |
return ( x > reference ) && ( x < ( reference + size ) ); |
|
22 |
} |
|
23 |
|
|
24 |
function isFloating(item) { |
|
25 |
return (/left|right/).test(item.css("float")) || (/inline|table-cell/).test(item.css("display")); |
|
26 |
} |
|
27 |
|
|
17 | 28 |
$.widget("ui.sortable", $.ui.mouse, { |
29 |
version: "1.10.2", |
|
18 | 30 |
widgetEventPrefix: "sort", |
31 |
ready: false, |
|
19 | 32 |
options: { |
20 | 33 |
appendTo: "parent", |
21 | 34 |
axis: false, |
22 | 35 |
connectWith: false, |
23 | 36 |
containment: false, |
24 |
cursor: 'auto',
|
|
37 |
cursor: "auto",
|
|
25 | 38 |
cursorAt: false, |
26 | 39 |
dropOnEmpty: true, |
27 | 40 |
forcePlaceholderSize: false, |
... | ... | |
29 | 42 |
grid: false, |
30 | 43 |
handle: false, |
31 | 44 |
helper: "original", |
32 |
items: '> *',
|
|
45 |
items: "> *",
|
|
33 | 46 |
opacity: false, |
34 | 47 |
placeholder: false, |
35 | 48 |
revert: false, |
... | ... | |
38 | 51 |
scrollSpeed: 20, |
39 | 52 |
scope: "default", |
40 | 53 |
tolerance: "intersect", |
41 |
zIndex: 1000 |
|
54 |
zIndex: 1000, |
|
55 |
|
|
56 |
// callbacks |
|
57 |
activate: null, |
|
58 |
beforeStop: null, |
|
59 |
change: null, |
|
60 |
deactivate: null, |
|
61 |
out: null, |
|
62 |
over: null, |
|
63 |
receive: null, |
|
64 |
remove: null, |
|
65 |
sort: null, |
|
66 |
start: null, |
|
67 |
stop: null, |
|
68 |
update: null |
|
42 | 69 |
}, |
43 | 70 |
_create: function() { |
44 | 71 |
|
... | ... | |
50 | 77 |
this.refresh(); |
51 | 78 |
|
52 | 79 |
//Let's determine if the items are being displayed horizontally |
53 |
this.floating = this.items.length ? (/left|right/).test(this.items[0].item.css('float')) || (/inline|table-cell/).test(this.items[0].item.css('display')) : false;
|
|
80 |
this.floating = this.items.length ? o.axis === "x" || isFloating(this.items[0].item) : false;
|
|
54 | 81 |
|
55 | 82 |
//Let's determine the parent's offset |
56 | 83 |
this.offset = this.element.offset(); |
... | ... | |
58 | 85 |
//Initialize mouse events for interaction |
59 | 86 |
this._mouseInit(); |
60 | 87 |
|
88 |
//We're ready to go |
|
89 |
this.ready = true; |
|
90 |
|
|
61 | 91 |
}, |
62 | 92 |
|
63 |
destroy: function() { |
|
93 |
_destroy: function() {
|
|
64 | 94 |
this.element |
65 |
.removeClass("ui-sortable ui-sortable-disabled") |
|
66 |
.removeData("sortable") |
|
67 |
.unbind(".sortable"); |
|
95 |
.removeClass("ui-sortable ui-sortable-disabled"); |
|
68 | 96 |
this._mouseDestroy(); |
69 | 97 |
|
70 |
for ( var i = this.items.length - 1; i >= 0; i-- ) |
|
71 |
this.items[i].item.removeData("sortable-item"); |
|
98 |
for ( var i = this.items.length - 1; i >= 0; i-- ) { |
|
99 |
this.items[i].item.removeData(this.widgetName + "-item"); |
|
100 |
} |
|
72 | 101 |
|
73 | 102 |
return this; |
74 | 103 |
}, |
... | ... | |
76 | 105 |
_setOption: function(key, value){ |
77 | 106 |
if ( key === "disabled" ) { |
78 | 107 |
this.options[ key ] = value; |
79 |
|
|
80 |
this.widget() |
|
81 |
[ value ? "addClass" : "removeClass"]( "ui-sortable-disabled" ); |
|
108 |
|
|
109 |
this.widget().toggleClass( "ui-sortable-disabled", !!value ); |
|
82 | 110 |
} else { |
83 | 111 |
// Don't call widget base _setOption for disable as it adds ui-state-disabled class |
84 | 112 |
$.Widget.prototype._setOption.apply(this, arguments); |
... | ... | |
86 | 114 |
}, |
87 | 115 |
|
88 | 116 |
_mouseCapture: function(event, overrideHandle) { |
117 |
var currentItem = null, |
|
118 |
validHandle = false, |
|
119 |
that = this; |
|
89 | 120 |
|
90 | 121 |
if (this.reverting) { |
91 | 122 |
return false; |
92 | 123 |
} |
93 | 124 |
|
94 |
if(this.options.disabled || this.options.type == 'static') return false; |
|
125 |
if(this.options.disabled || this.options.type === "static") { |
|
126 |
return false; |
|
127 |
} |
|
95 | 128 |
|
96 | 129 |
//We have to refresh the items data once first |
97 | 130 |
this._refreshItems(event); |
98 | 131 |
|
99 | 132 |
//Find out if the clicked node (or one of its parents) is a actual item in this.items |
100 |
var currentItem = null, self = this, nodes = $(event.target).parents().each(function() {
|
|
101 |
if($.data(this, 'sortable-item') == self) {
|
|
133 |
$(event.target).parents().each(function() { |
|
134 |
if($.data(this, that.widgetName + "-item") === that) {
|
|
102 | 135 |
currentItem = $(this); |
103 | 136 |
return false; |
104 | 137 |
} |
105 | 138 |
}); |
106 |
if($.data(event.target, 'sortable-item') == self) currentItem = $(event.target); |
|
139 |
if($.data(event.target, that.widgetName + "-item") === that) { |
|
140 |
currentItem = $(event.target); |
|
141 |
} |
|
107 | 142 |
|
108 |
if(!currentItem) return false; |
|
143 |
if(!currentItem) { |
|
144 |
return false; |
|
145 |
} |
|
109 | 146 |
if(this.options.handle && !overrideHandle) { |
110 |
var validHandle = false; |
|
111 |
|
|
112 |
$(this.options.handle, currentItem).find("*").andSelf().each(function() { if(this == event.target) validHandle = true; }); |
|
113 |
if(!validHandle) return false; |
|
147 |
$(this.options.handle, currentItem).find("*").addBack().each(function() { |
|
148 |
if(this === event.target) { |
|
149 |
validHandle = true; |
|
150 |
} |
|
151 |
}); |
|
152 |
if(!validHandle) { |
|
153 |
return false; |
|
154 |
} |
|
114 | 155 |
} |
115 | 156 |
|
116 | 157 |
this.currentItem = currentItem; |
... | ... | |
121 | 162 |
|
122 | 163 |
_mouseStart: function(event, overrideHandle, noActivation) { |
123 | 164 |
|
124 |
var o = this.options, self = this; |
|
165 |
var i, body, |
|
166 |
o = this.options; |
|
167 |
|
|
125 | 168 |
this.currentContainer = this; |
126 | 169 |
|
127 | 170 |
//We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture |
... | ... | |
151 | 194 |
left: this.offset.left - this.margins.left |
152 | 195 |
}; |
153 | 196 |
|
154 |
// Only after we got the offset, we can change the helper's position to absolute |
|
155 |
// TODO: Still need to figure out a way to make relative sorting possible |
|
156 |
this.helper.css("position", "absolute"); |
|
157 |
this.cssPosition = this.helper.css("position"); |
|
158 |
|
|
159 | 197 |
$.extend(this.offset, { |
160 | 198 |
click: { //Where the click happened, relative to the element |
161 | 199 |
left: event.pageX - this.offset.left, |
... | ... | |
165 | 203 |
relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper |
166 | 204 |
}); |
167 | 205 |
|
206 |
// Only after we got the offset, we can change the helper's position to absolute |
|
207 |
// TODO: Still need to figure out a way to make relative sorting possible |
|
208 |
this.helper.css("position", "absolute"); |
|
209 |
this.cssPosition = this.helper.css("position"); |
|
210 |
|
|
168 | 211 |
//Generate the original position |
169 | 212 |
this.originalPosition = this._generatePosition(event); |
170 | 213 |
this.originalPageX = event.pageX; |
171 | 214 |
this.originalPageY = event.pageY; |
172 | 215 |
|
173 |
//Adjust the mouse offset relative to the helper if 'cursorAt' is supplied
|
|
216 |
//Adjust the mouse offset relative to the helper if "cursorAt" is supplied
|
|
174 | 217 |
(o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt)); |
175 | 218 |
|
176 | 219 |
//Cache the former DOM position |
177 | 220 |
this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] }; |
178 | 221 |
|
179 | 222 |
//If the helper is not the original, hide the original so it's not playing any role during the drag, won't cause anything bad this way |
180 |
if(this.helper[0] != this.currentItem[0]) { |
|
223 |
if(this.helper[0] !== this.currentItem[0]) {
|
|
181 | 224 |
this.currentItem.hide(); |
182 | 225 |
} |
183 | 226 |
|
... | ... | |
185 | 228 |
this._createPlaceholder(); |
186 | 229 |
|
187 | 230 |
//Set a containment if given in the options |
188 |
if(o.containment) |
|
231 |
if(o.containment) {
|
|
189 | 232 |
this._setContainment(); |
233 |
} |
|
190 | 234 |
|
191 |
if(o.cursor) { // cursor option |
|
192 |
if ($('body').css("cursor")) this._storedCursor = $('body').css("cursor"); |
|
193 |
$('body').css("cursor", o.cursor); |
|
235 |
if( o.cursor && o.cursor !== "auto" ) { // cursor option |
|
236 |
body = this.document.find( "body" ); |
|
237 |
|
|
238 |
// support: IE |
|
239 |
this.storedCursor = body.css( "cursor" ); |
|
240 |
body.css( "cursor", o.cursor ); |
|
241 |
|
|
242 |
this.storedStylesheet = $( "<style>*{ cursor: "+o.cursor+" !important; }</style>" ).appendTo( body ); |
|
194 | 243 |
} |
195 | 244 |
|
196 | 245 |
if(o.opacity) { // opacity option |
197 |
if (this.helper.css("opacity")) this._storedOpacity = this.helper.css("opacity"); |
|
246 |
if (this.helper.css("opacity")) { |
|
247 |
this._storedOpacity = this.helper.css("opacity"); |
|
248 |
} |
|
198 | 249 |
this.helper.css("opacity", o.opacity); |
199 | 250 |
} |
200 | 251 |
|
201 | 252 |
if(o.zIndex) { // zIndex option |
202 |
if (this.helper.css("zIndex")) this._storedZIndex = this.helper.css("zIndex"); |
|
253 |
if (this.helper.css("zIndex")) { |
|
254 |
this._storedZIndex = this.helper.css("zIndex"); |
|
255 |
} |
|
203 | 256 |
this.helper.css("zIndex", o.zIndex); |
204 | 257 |
} |
205 | 258 |
|
206 | 259 |
//Prepare scrolling |
207 |
if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML')
|
|
260 |
if(this.scrollParent[0] !== document && this.scrollParent[0].tagName !== "HTML") {
|
|
208 | 261 |
this.overflowOffset = this.scrollParent.offset(); |
262 |
} |
|
209 | 263 |
|
210 | 264 |
//Call callbacks |
211 | 265 |
this._trigger("start", event, this._uiHash()); |
212 | 266 |
|
213 | 267 |
//Recache the helper size |
214 |
if(!this._preserveHelperProportions) |
|
268 |
if(!this._preserveHelperProportions) {
|
|
215 | 269 |
this._cacheHelperProportions(); |
270 |
} |
|
216 | 271 |
|
217 | 272 |
|
218 |
//Post 'activate' events to possible containers |
|
219 |
if(!noActivation) { |
|
220 |
for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._trigger("activate", event, self._uiHash(this)); } |
|
273 |
//Post "activate" events to possible containers |
|
274 |
if( !noActivation ) { |
|
275 |
for ( i = this.containers.length - 1; i >= 0; i-- ) { |
|
276 |
this.containers[ i ]._trigger( "activate", event, this._uiHash( this ) ); |
|
277 |
} |
|
221 | 278 |
} |
222 | 279 |
|
223 | 280 |
//Prepare possible droppables |
224 |
if($.ui.ddmanager) |
|
281 |
if($.ui.ddmanager) {
|
|
225 | 282 |
$.ui.ddmanager.current = this; |
283 |
} |
|
226 | 284 |
|
227 |
if ($.ui.ddmanager && !o.dropBehaviour) |
|
285 |
if ($.ui.ddmanager && !o.dropBehaviour) {
|
|
228 | 286 |
$.ui.ddmanager.prepareOffsets(this, event); |
287 |
} |
|
229 | 288 |
|
230 | 289 |
this.dragging = true; |
231 | 290 |
|
... | ... | |
236 | 295 |
}, |
237 | 296 |
|
238 | 297 |
_mouseDrag: function(event) { |
298 |
var i, item, itemElement, intersection, |
|
299 |
o = this.options, |
|
300 |
scrolled = false; |
|
239 | 301 |
|
240 | 302 |
//Compute the helpers position |
241 | 303 |
this.position = this._generatePosition(event); |
... | ... | |
247 | 309 |
|
248 | 310 |
//Do scrolling |
249 | 311 |
if(this.options.scroll) { |
250 |
var o = this.options, scrolled = false; |
|
251 |
if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') { |
|
312 |
if(this.scrollParent[0] !== document && this.scrollParent[0].tagName !== "HTML") { |
|
252 | 313 |
|
253 |
if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) |
|
314 |
if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) {
|
|
254 | 315 |
this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed; |
255 |
else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity)
|
|
316 |
} else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity) {
|
|
256 | 317 |
this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed; |
318 |
} |
|
257 | 319 |
|
258 |
if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) |
|
320 |
if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) {
|
|
259 | 321 |
this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed; |
260 |
else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity)
|
|
322 |
} else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity) {
|
|
261 | 323 |
this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed; |
324 |
} |
|
262 | 325 |
|
263 | 326 |
} else { |
264 | 327 |
|
265 |
if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) |
|
328 |
if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) {
|
|
266 | 329 |
scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed); |
267 |
else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity)
|
|
330 |
} else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) {
|
|
268 | 331 |
scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed); |
332 |
} |
|
269 | 333 |
|
270 |
if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) |
|
334 |
if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) {
|
|
271 | 335 |
scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed); |
272 |
else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
|
|
336 |
} else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) {
|
|
273 | 337 |
scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed); |
338 |
} |
|
274 | 339 |
|
275 | 340 |
} |
276 | 341 |
|
277 |
if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) |
|
342 |
if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) {
|
|
278 | 343 |
$.ui.ddmanager.prepareOffsets(this, event); |
344 |
} |
|
279 | 345 |
} |
280 | 346 |
|
281 | 347 |
//Regenerate the absolute position used for position checks |
282 | 348 |
this.positionAbs = this._convertPositionTo("absolute"); |
283 | 349 |
|
284 | 350 |
//Set the helper position |
285 |
if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px'; |
|
286 |
if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px'; |
|
351 |
if(!this.options.axis || this.options.axis !== "y") { |
|
352 |
this.helper[0].style.left = this.position.left+"px"; |
|
353 |
} |
|
354 |
if(!this.options.axis || this.options.axis !== "x") { |
|
355 |
this.helper[0].style.top = this.position.top+"px"; |
|
356 |
} |
|
287 | 357 |
|
288 | 358 |
//Rearrange |
289 |
for (var i = this.items.length - 1; i >= 0; i--) {
|
|
359 |
for (i = this.items.length - 1; i >= 0; i--) { |
|
290 | 360 |
|
291 | 361 |
//Cache variables and intersection, continue if no intersection |
292 |
var item = this.items[i], itemElement = item.item[0], intersection = this._intersectsWithPointer(item); |
|
293 |
if (!intersection) continue; |
|
294 |
|
|
295 |
if(itemElement != this.currentItem[0] //cannot intersect with itself |
|
296 |
&& this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemElement //no useless actions that have been done before |
|
297 |
&& !$.ui.contains(this.placeholder[0], itemElement) //no action if the item moved is the parent of the item checked |
|
298 |
&& (this.options.type == 'semi-dynamic' ? !$.ui.contains(this.element[0], itemElement) : true) |
|
299 |
//&& itemElement.parentNode == this.placeholder[0].parentNode // only rearrange items within the same container |
|
362 |
item = this.items[i]; |
|
363 |
itemElement = item.item[0]; |
|
364 |
intersection = this._intersectsWithPointer(item); |
|
365 |
if (!intersection) { |
|
366 |
continue; |
|
367 |
} |
|
368 |
|
|
369 |
// Only put the placeholder inside the current Container, skip all |
|
370 |
// items form other containers. This works because when moving |
|
371 |
// an item from one container to another the |
|
372 |
// currentContainer is switched before the placeholder is moved. |
|
373 |
// |
|
374 |
// Without this moving items in "sub-sortables" can cause the placeholder to jitter |
|
375 |
// beetween the outer and inner container. |
|
376 |
if (item.instance !== this.currentContainer) { |
|
377 |
continue; |
|
378 |
} |
|
379 |
|
|
380 |
// cannot intersect with itself |
|
381 |
// no useless actions that have been done before |
|
382 |
// no action if the item moved is the parent of the item checked |
|
383 |
if (itemElement !== this.currentItem[0] && |
|
384 |
this.placeholder[intersection === 1 ? "next" : "prev"]()[0] !== itemElement && |
|
385 |
!$.contains(this.placeholder[0], itemElement) && |
|
386 |
(this.options.type === "semi-dynamic" ? !$.contains(this.element[0], itemElement) : true) |
|
300 | 387 |
) { |
301 | 388 |
|
302 |
this.direction = intersection == 1 ? "down" : "up"; |
|
389 |
this.direction = intersection === 1 ? "down" : "up";
|
|
303 | 390 |
|
304 |
if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) { |
|
391 |
if (this.options.tolerance === "pointer" || this._intersectsWithSides(item)) {
|
|
305 | 392 |
this._rearrange(event, item); |
306 | 393 |
} else { |
307 | 394 |
break; |
... | ... | |
316 | 403 |
this._contactContainers(event); |
317 | 404 |
|
318 | 405 |
//Interconnect with droppables |
319 |
if($.ui.ddmanager) $.ui.ddmanager.drag(this, event); |
|
406 |
if($.ui.ddmanager) { |
|
407 |
$.ui.ddmanager.drag(this, event); |
|
408 |
} |
|
320 | 409 |
|
321 | 410 |
//Call callbacks |
322 |
this._trigger('sort', event, this._uiHash());
|
|
411 |
this._trigger("sort", event, this._uiHash());
|
|
323 | 412 |
|
324 | 413 |
this.lastPositionAbs = this.positionAbs; |
325 | 414 |
return false; |
... | ... | |
328 | 417 |
|
329 | 418 |
_mouseStop: function(event, noPropagation) { |
330 | 419 |
|
331 |
if(!event) return; |
|
420 |
if(!event) { |
|
421 |
return; |
|
422 |
} |
|
332 | 423 |
|
333 | 424 |
//If we are using droppables, inform the manager about the drop |
334 |
if ($.ui.ddmanager && !this.options.dropBehaviour) |
|
425 |
if ($.ui.ddmanager && !this.options.dropBehaviour) {
|
|
335 | 426 |
$.ui.ddmanager.drop(this, event); |
427 |
} |
|
336 | 428 |
|
337 | 429 |
if(this.options.revert) { |
338 |
var self = this; |
|
339 |
var cur = self.placeholder.offset(); |
|
430 |
var that = this, |
|
431 |
cur = this.placeholder.offset(), |
|
432 |
axis = this.options.axis, |
|
433 |
animation = {}; |
|
340 | 434 |
|
341 |
self.reverting = true; |
|
342 |
|
|
343 |
$(this.helper).animate({ |
|
344 |
left: cur.left - this.offset.parent.left - self.margins.left + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollLeft), |
|
345 |
top: cur.top - this.offset.parent.top - self.margins.top + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollTop) |
|
346 |
}, parseInt(this.options.revert, 10) || 500, function() { |
|
347 |
self._clear(event); |
|
435 |
if ( !axis || axis === "x" ) { |
|
436 |
animation.left = cur.left - this.offset.parent.left - this.margins.left + (this.offsetParent[0] === document.body ? 0 : this.offsetParent[0].scrollLeft); |
|
437 |
} |
|
438 |
if ( !axis || axis === "y" ) { |
|
439 |
animation.top = cur.top - this.offset.parent.top - this.margins.top + (this.offsetParent[0] === document.body ? 0 : this.offsetParent[0].scrollTop); |
|
440 |
} |
|
441 |
this.reverting = true; |
|
442 |
$(this.helper).animate( animation, parseInt(this.options.revert, 10) || 500, function() { |
|
443 |
that._clear(event); |
|
348 | 444 |
}); |
349 | 445 |
} else { |
350 | 446 |
this._clear(event, noPropagation); |
... | ... | |
356 | 452 |
|
357 | 453 |
cancel: function() { |
358 | 454 |
|
359 |
var self = this; |
|
360 |
|
|
361 | 455 |
if(this.dragging) { |
362 | 456 |
|
363 | 457 |
this._mouseUp({ target: null }); |
364 | 458 |
|
365 |
if(this.options.helper == "original")
|
|
459 |
if(this.options.helper === "original") {
|
|
366 | 460 |
this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper"); |
367 |
else
|
|
461 |
} else {
|
|
368 | 462 |
this.currentItem.show(); |
463 |
} |
|
369 | 464 |
|
370 | 465 |
//Post deactivating events to containers |
371 | 466 |
for (var i = this.containers.length - 1; i >= 0; i--){ |
372 |
this.containers[i]._trigger("deactivate", null, self._uiHash(this));
|
|
467 |
this.containers[i]._trigger("deactivate", null, this._uiHash(this));
|
|
373 | 468 |
if(this.containers[i].containerCache.over) { |
374 |
this.containers[i]._trigger("out", null, self._uiHash(this));
|
|
469 |
this.containers[i]._trigger("out", null, this._uiHash(this));
|
|
375 | 470 |
this.containers[i].containerCache.over = 0; |
376 | 471 |
} |
377 | 472 |
} |
... | ... | |
380 | 475 |
|
381 | 476 |
if (this.placeholder) { |
382 | 477 |
//$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node! |
383 |
if(this.placeholder[0].parentNode) this.placeholder[0].parentNode.removeChild(this.placeholder[0]); |
|
384 |
if(this.options.helper != "original" && this.helper && this.helper[0].parentNode) this.helper.remove(); |
|
478 |
if(this.placeholder[0].parentNode) { |
|
479 |
this.placeholder[0].parentNode.removeChild(this.placeholder[0]); |
|
480 |
} |
|
481 |
if(this.options.helper !== "original" && this.helper && this.helper[0].parentNode) { |
|
482 |
this.helper.remove(); |
|
483 |
} |
|
385 | 484 |
|
386 | 485 |
$.extend(this, { |
387 | 486 |
helper: null, |
... | ... | |
403 | 502 |
|
404 | 503 |
serialize: function(o) { |
405 | 504 |
|
406 |
var items = this._getItemsAsjQuery(o && o.connected); |
|
407 |
var str = []; o = o || {}; |
|
505 |
var items = this._getItemsAsjQuery(o && o.connected), |
|
506 |
str = []; |
|
507 |
o = o || {}; |
|
408 | 508 |
|
409 | 509 |
$(items).each(function() { |
410 |
var res = ($(o.item || this).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/)); |
|
411 |
if(res) str.push((o.key || res[1]+'[]')+'='+(o.key && o.expression ? res[1] : res[2])); |
|
510 |
var res = ($(o.item || this).attr(o.attribute || "id") || "").match(o.expression || (/(.+)[\-=_](.+)/)); |
|
511 |
if (res) { |
|
512 |
str.push((o.key || res[1]+"[]")+"="+(o.key && o.expression ? res[1] : res[2])); |
|
513 |
} |
|
412 | 514 |
}); |
413 | 515 |
|
414 | 516 |
if(!str.length && o.key) { |
415 |
str.push(o.key + '=');
|
|
517 |
str.push(o.key + "=");
|
|
416 | 518 |
} |
417 | 519 |
|
418 |
return str.join('&');
|
|
520 |
return str.join("&");
|
|
419 | 521 |
|
420 | 522 |
}, |
421 | 523 |
|
422 | 524 |
toArray: function(o) { |
423 | 525 |
|
424 |
var items = this._getItemsAsjQuery(o && o.connected); |
|
425 |
var ret = []; o = o || {}; |
|
526 |
var items = this._getItemsAsjQuery(o && o.connected), |
|
527 |
ret = []; |
|
528 |
|
|
529 |
o = o || {}; |
|
426 | 530 |
|
427 |
items.each(function() { ret.push($(o.item || this).attr(o.attribute || 'id') || ''); });
|
|
531 |
items.each(function() { ret.push($(o.item || this).attr(o.attribute || "id") || ""); });
|
|
428 | 532 |
return ret; |
429 | 533 |
|
430 | 534 |
}, |
... | ... | |
435 | 539 |
var x1 = this.positionAbs.left, |
436 | 540 |
x2 = x1 + this.helperProportions.width, |
437 | 541 |
y1 = this.positionAbs.top, |
438 |
y2 = y1 + this.helperProportions.height; |
|
439 |
|
|
440 |
var l = item.left, |
|
542 |
y2 = y1 + this.helperProportions.height, |
|
543 |
l = item.left, |
|
441 | 544 |
r = l + item.width, |
442 | 545 |
t = item.top, |
443 |
b = t + item.height; |
|
444 |
|
|
445 |
var dyClick = this.offset.click.top, |
|
446 |
dxClick = this.offset.click.left; |
|
447 |
|
|
448 |
var isOverElement = (y1 + dyClick) > t && (y1 + dyClick) < b && (x1 + dxClick) > l && (x1 + dxClick) < r; |
|
449 |
|
|
450 |
if( this.options.tolerance == "pointer" |
|
451 |
|| this.options.forcePointerForContainers |
|
452 |
|| (this.options.tolerance != "pointer" && this.helperProportions[this.floating ? 'width' : 'height'] > item[this.floating ? 'width' : 'height']) |
|
546 |
b = t + item.height, |
|
547 |
dyClick = this.offset.click.top, |
|
548 |
dxClick = this.offset.click.left, |
|
549 |
isOverElement = (y1 + dyClick) > t && (y1 + dyClick) < b && (x1 + dxClick) > l && (x1 + dxClick) < r; |
|
550 |
|
|
551 |
if ( this.options.tolerance === "pointer" || |
|
552 |
this.options.forcePointerForContainers || |
|
553 |
(this.options.tolerance !== "pointer" && this.helperProportions[this.floating ? "width" : "height"] > item[this.floating ? "width" : "height"]) |
|
453 | 554 |
) { |
454 | 555 |
return isOverElement; |
455 | 556 |
} else { |
456 | 557 |
|
457 |
return (l < x1 + (this.helperProportions.width / 2) // Right Half |
|
458 |
&& x2 - (this.helperProportions.width / 2) < r // Left Half
|
|
459 |
&& t < y1 + (this.helperProportions.height / 2) // Bottom Half
|
|
460 |
&& y2 - (this.helperProportions.height / 2) < b ); // Top Half
|
|
558 |
return (l < x1 + (this.helperProportions.width / 2) && // Right Half
|
|
559 |
x2 - (this.helperProportions.width / 2) < r && // Left Half
|
|
560 |
t < y1 + (this.helperProportions.height / 2) && // Bottom Half
|
|
561 |
y2 - (this.helperProportions.height / 2) < b ); // Top Half |
|
461 | 562 |
|
462 | 563 |
} |
463 | 564 |
}, |
464 | 565 |
|
465 | 566 |
_intersectsWithPointer: function(item) { |
466 | 567 |
|
467 |
var isOverElementHeight = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
|
|
468 |
isOverElementWidth = $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
|
|
568 |
var isOverElementHeight = (this.options.axis === "x") || isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
|
|
569 |
isOverElementWidth = (this.options.axis === "y") || isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
|
|
469 | 570 |
isOverElement = isOverElementHeight && isOverElementWidth, |
470 | 571 |
verticalDirection = this._getDragVerticalDirection(), |
471 | 572 |
horizontalDirection = this._getDragHorizontalDirection(); |
472 | 573 |
|
473 |
if (!isOverElement) |
|
574 |
if (!isOverElement) {
|
|
474 | 575 |
return false; |
576 |
} |
|
475 | 577 |
|
476 | 578 |
return this.floating ? |
477 |
( ((horizontalDirection && horizontalDirection == "right") || verticalDirection == "down") ? 2 : 1 )
|
|
478 |
: ( verticalDirection && (verticalDirection == "down" ? 2 : 1) ); |
|
579 |
( ((horizontalDirection && horizontalDirection === "right") || verticalDirection === "down") ? 2 : 1 )
|
|
580 |
: ( verticalDirection && (verticalDirection === "down" ? 2 : 1) );
|
|
479 | 581 |
|
480 | 582 |
}, |
481 | 583 |
|
482 | 584 |
_intersectsWithSides: function(item) { |
483 | 585 |
|
484 |
var isOverBottomHalf = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height),
|
|
485 |
isOverRightHalf = $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
|
|
586 |
var isOverBottomHalf = isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height), |
|
587 |
isOverRightHalf = isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width), |
|
486 | 588 |
verticalDirection = this._getDragVerticalDirection(), |
487 | 589 |
horizontalDirection = this._getDragHorizontalDirection(); |
488 | 590 |
|
489 | 591 |
if (this.floating && horizontalDirection) { |
490 |
return ((horizontalDirection == "right" && isOverRightHalf) || (horizontalDirection == "left" && !isOverRightHalf));
|
|
592 |
return ((horizontalDirection === "right" && isOverRightHalf) || (horizontalDirection === "left" && !isOverRightHalf));
|
|
491 | 593 |
} else { |
492 |
return verticalDirection && ((verticalDirection == "down" && isOverBottomHalf) || (verticalDirection == "up" && !isOverBottomHalf));
|
|
594 |
return verticalDirection && ((verticalDirection === "down" && isOverBottomHalf) || (verticalDirection === "up" && !isOverBottomHalf));
|
|
493 | 595 |
} |
494 | 596 |
|
495 | 597 |
}, |
496 | 598 |
|
497 | 599 |
_getDragVerticalDirection: function() { |
498 | 600 |
var delta = this.positionAbs.top - this.lastPositionAbs.top; |
499 |
return delta != 0 && (delta > 0 ? "down" : "up"); |
|
601 |
return delta !== 0 && (delta > 0 ? "down" : "up");
|
|
500 | 602 |
}, |
501 | 603 |
|
502 | 604 |
_getDragHorizontalDirection: function() { |
503 | 605 |
var delta = this.positionAbs.left - this.lastPositionAbs.left; |
504 |
return delta != 0 && (delta > 0 ? "right" : "left"); |
|
606 |
return delta !== 0 && (delta > 0 ? "right" : "left");
|
|
505 | 607 |
}, |
506 | 608 |
|
507 | 609 |
refresh: function(event) { |
... | ... | |
512 | 614 |
|
513 | 615 |
_connectWith: function() { |
514 | 616 |
var options = this.options; |
515 |
return options.connectWith.constructor == String |
|
516 |
? [options.connectWith] |
|
517 |
: options.connectWith; |
|
617 |
return options.connectWith.constructor === String ? [options.connectWith] : options.connectWith; |
|
518 | 618 |
}, |
519 |
|
|
619 |
|
|
520 | 620 |
_getItemsAsjQuery: function(connected) { |
521 | 621 |
|
522 |
var self = this;
|
|
523 |
var items = [];
|
|
524 |
var queries = [];
|
|
525 |
var connectWith = this._connectWith();
|
|
622 |
var i, j, cur, inst,
|
|
623 |
items = [],
|
|
624 |
queries = [],
|
|
625 |
connectWith = this._connectWith();
|
|
526 | 626 |
|
527 | 627 |
if(connectWith && connected) { |
528 |
for (var i = connectWith.length - 1; i >= 0; i--){
|
|
529 |
var cur = $(connectWith[i]);
|
|
530 |
for (var j = cur.length - 1; j >= 0; j--){
|
|
531 |
var inst = $.data(cur[j], 'sortable');
|
|
532 |
if(inst && inst != this && !inst.options.disabled) { |
|
533 |
queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element) : $(inst.options.items, inst.element).not(".ui-sortable-helper").not('.ui-sortable-placeholder'), inst]);
|
|
628 |
for (i = connectWith.length - 1; i >= 0; i--){ |
|
629 |
cur = $(connectWith[i]); |
|
630 |
for ( j = cur.length - 1; j >= 0; j--){ |
|
631 |
inst = $.data(cur[j], this.widgetFullName);
|
|
632 |
if(inst && inst !== this && !inst.options.disabled) {
|
|
633 |
queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element) : $(inst.options.items, inst.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"), inst]);
|
|
534 | 634 |
} |
535 |
};
|
|
536 |
};
|
|
635 |
} |
|
636 |
} |
|
537 | 637 |
} |
538 | 638 |
|
539 |
queries.push([$.isFunction(this.options.items) ? this.options.items.call(this.element, null, { options: this.options, item: this.currentItem }) : $(this.options.items, this.element).not(".ui-sortable-helper").not('.ui-sortable-placeholder'), this]);
|
|
639 |
queries.push([$.isFunction(this.options.items) ? this.options.items.call(this.element, null, { options: this.options, item: this.currentItem }) : $(this.options.items, this.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"), this]);
|
|
540 | 640 |
|
541 |
for (var i = queries.length - 1; i >= 0; i--){
|
|
641 |
for (i = queries.length - 1; i >= 0; i--){ |
|
542 | 642 |
queries[i][0].each(function() { |
543 | 643 |
items.push(this); |
544 | 644 |
}); |
545 |
};
|
|
645 |
} |
|
546 | 646 |
|
547 | 647 |
return $(items); |
548 | 648 |
|
... | ... | |
550 | 650 |
|
551 | 651 |
_removeCurrentsFromItems: function() { |
552 | 652 |
|
553 |
var list = this.currentItem.find(":data(sortable-item)"); |
|
554 |
|
|
555 |
for (var i=0; i < this.items.length; i++) { |
|
653 |
var list = this.currentItem.find(":data(" + this.widgetName + "-item)"); |
|
556 | 654 |
|
655 |
this.items = $.grep(this.items, function (item) { |
|
557 | 656 |
for (var j=0; j < list.length; j++) { |
558 |
if(list[j] == this.items[i].item[0]) |
|
559 |
this.items.splice(i,1); |
|
560 |
}; |
|
561 |
|
|
562 |
}; |
|
657 |
if(list[j] === item.item[0]) { |
|
658 |
return false; |
|
659 |
} |
|
660 |
} |
|
661 |
return true; |
|
662 |
}); |
|
563 | 663 |
|
564 | 664 |
}, |
565 | 665 |
|
... | ... | |
567 | 667 |
|
568 | 668 |
this.items = []; |
569 | 669 |
this.containers = [this]; |
570 |
var items = this.items; |
|
571 |
var self = this; |
|
572 |
var queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]]; |
|
573 |
var connectWith = this._connectWith(); |
|
574 |
|
|
575 |
if(connectWith) { |
|
576 |
for (var i = connectWith.length - 1; i >= 0; i--){ |
|
577 |
var cur = $(connectWith[i]); |
|
578 |
for (var j = cur.length - 1; j >= 0; j--){ |
|
579 |
var inst = $.data(cur[j], 'sortable'); |
|
580 |
if(inst && inst != this && !inst.options.disabled) { |
|
670 |
|
|
671 |
var i, j, cur, inst, targetData, _queries, item, queriesLength, |
|
672 |
items = this.items, |
|
673 |
queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]], |
|
674 |
connectWith = this._connectWith(); |
|
675 |
|
|
676 |
if(connectWith && this.ready) { //Shouldn't be run the first time through due to massive slow-down |
|
677 |
for (i = connectWith.length - 1; i >= 0; i--){ |
|
678 |
cur = $(connectWith[i]); |
|
679 |
for (j = cur.length - 1; j >= 0; j--){ |
|
680 |
inst = $.data(cur[j], this.widgetFullName); |
|
681 |
if(inst && inst !== this && !inst.options.disabled) { |
|
581 | 682 |
queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element[0], event, { item: this.currentItem }) : $(inst.options.items, inst.element), inst]); |
582 | 683 |
this.containers.push(inst); |
583 | 684 |
} |
584 |
};
|
|
585 |
};
|
|
685 |
} |
|
686 |
} |
|
586 | 687 |
} |
587 | 688 |
|
588 |
for (var i = queries.length - 1; i >= 0; i--) {
|
|
589 |
var targetData = queries[i][1];
|
|
590 |
var _queries = queries[i][0];
|
|
689 |
for (i = queries.length - 1; i >= 0; i--) { |
|
690 |
targetData = queries[i][1]; |
|
691 |
_queries = queries[i][0]; |
|
591 | 692 |
|
592 |
for (var j=0, queriesLength = _queries.length; j < queriesLength; j++) {
|
|
593 |
var item = $(_queries[j]);
|
|
693 |
for (j=0, queriesLength = _queries.length; j < queriesLength; j++) { |
|
694 |
item = $(_queries[j]); |
|
594 | 695 |
|
595 |
item.data('sortable-item', targetData); // Data for target checking (mouse manager)
|
|
696 |
item.data(this.widgetName + "-item", targetData); // Data for target checking (mouse manager)
|
|
596 | 697 |
|
597 | 698 |
items.push({ |
598 | 699 |
item: item, |
... | ... | |
600 | 701 |
width: 0, height: 0, |
601 | 702 |
left: 0, top: 0 |
602 | 703 |
}); |
603 |
};
|
|
604 |
};
|
|
704 |
} |
|
705 |
} |
|
605 | 706 |
|
606 | 707 |
}, |
607 | 708 |
|
... | ... | |
612 | 713 |
this.offset.parent = this._getParentOffset(); |
613 | 714 |
} |
614 | 715 |
|
615 |
for (var i = this.items.length - 1; i >= 0; i--){ |
|
616 |
var item = this.items[i]; |
|
716 |
var i, item, t, p; |
|
717 |
|
|
718 |
for (i = this.items.length - 1; i >= 0; i--){ |
|
719 |
item = this.items[i]; |
|
720 |
|
|
721 |
//We ignore calculating positions of all connected containers when we're not over them |
|
722 |
if(item.instance !== this.currentContainer && this.currentContainer && item.item[0] !== this.currentItem[0]) { |
|
723 |
continue; |
|
724 |
} |
|
617 | 725 |
|
618 |
var t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item;
|
|
726 |
t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item; |
|
619 | 727 |
|
620 | 728 |
if (!fast) { |
621 | 729 |
item.width = t.outerWidth(); |
622 | 730 |
item.height = t.outerHeight(); |
623 | 731 |
} |
624 | 732 |
|
625 |
var p = t.offset();
|
|
733 |
p = t.offset(); |
|
626 | 734 |
item.left = p.left; |
627 | 735 |
item.top = p.top; |
628 |
};
|
|
736 |
} |
|
629 | 737 |
|
630 | 738 |
if(this.options.custom && this.options.custom.refreshContainers) { |
631 | 739 |
this.options.custom.refreshContainers.call(this); |
632 | 740 |
} else { |
633 |
for (var i = this.containers.length - 1; i >= 0; i--){
|
|
634 |
var p = this.containers[i].element.offset();
|
|
741 |
for (i = this.containers.length - 1; i >= 0; i--){ |
|
742 |
p = this.containers[i].element.offset(); |
|
635 | 743 |
this.containers[i].containerCache.left = p.left; |
636 | 744 |
this.containers[i].containerCache.top = p.top; |
637 | 745 |
this.containers[i].containerCache.width = this.containers[i].element.outerWidth(); |
638 | 746 |
this.containers[i].containerCache.height = this.containers[i].element.outerHeight(); |
639 |
};
|
|
747 |
} |
|
640 | 748 |
} |
641 | 749 |
|
642 | 750 |
return this; |
643 | 751 |
}, |
644 | 752 |
|
645 | 753 |
_createPlaceholder: function(that) { |
754 |
that = that || this; |
|
755 |
var className, |
|
756 |
o = that.options; |
|
646 | 757 |
|
647 |
var self = that || this, o = self.options; |
|
648 |
|
|
649 |
if(!o.placeholder || o.placeholder.constructor == String) { |
|
650 |
var className = o.placeholder; |
|
758 |
if(!o.placeholder || o.placeholder.constructor === String) { |
|
759 |
className = o.placeholder; |
|
651 | 760 |
o.placeholder = { |
652 | 761 |
element: function() { |
653 | 762 |
|
654 |
var el = $(document.createElement(self.currentItem[0].nodeName)) |
|
655 |
.addClass(className || self.currentItem[0].className+" ui-sortable-placeholder") |
|
656 |
.removeClass("ui-sortable-helper")[0]; |
|
763 |
var nodeName = that.currentItem[0].nodeName.toLowerCase(), |
|
764 |
element = $( that.document[0].createElement( nodeName ) ) |
|
765 |
.addClass(className || that.currentItem[0].className+" ui-sortable-placeholder") |
|
766 |
.removeClass("ui-sortable-helper"); |
|
767 |
|
|
768 |
if ( nodeName === "tr" ) { |
|
769 |
// Use a high colspan to force the td to expand the full |
|
770 |
// width of the table (browsers are smart enough to |
|
771 |
// handle this properly) |
|
772 |
element.append( "<td colspan='99'> </td>" ); |
|
773 |
} else if ( nodeName === "img" ) { |
|
774 |
element.attr( "src", that.currentItem.attr( "src" ) ); |
|
775 |
} |
|
657 | 776 |
|
658 |
if(!className) |
|
659 |
el.style.visibility = "hidden"; |
|
777 |
if ( !className ) { |
|
778 |
element.css( "visibility", "hidden" ); |
|
779 |
} |
|
660 | 780 |
|
661 |
return el; |
|
781 |
return element;
|
|
662 | 782 |
}, |
663 | 783 |
update: function(container, p) { |
664 | 784 |
|
665 | 785 |
// 1. If a className is set as 'placeholder option, we don't force sizes - the class is responsible for that |
666 | 786 |
// 2. The option 'forcePlaceholderSize can be enabled to force it even if a class name is specified |
667 |
if(className && !o.forcePlaceholderSize) return; |
|
787 |
if(className && !o.forcePlaceholderSize) { |
|
788 |
return; |
|
789 |
} |
|
668 | 790 |
|
669 | 791 |
//If the element doesn't have a actual height by itself (without styles coming from a stylesheet), it receives the inline height from the dragged item |
670 |
if(!p.height()) { p.height(self.currentItem.innerHeight() - parseInt(self.currentItem.css('paddingTop')||0, 10) - parseInt(self.currentItem.css('paddingBottom')||0, 10)); };
|
|
671 |
if(!p.width()) { p.width(self.currentItem.innerWidth() - parseInt(self.currentItem.css('paddingLeft')||0, 10) - parseInt(self.currentItem.css('paddingRight')||0, 10)); };
|
|
792 |
if(!p.height()) { p.height(that.currentItem.innerHeight() - parseInt(that.currentItem.css("paddingTop")||0, 10) - parseInt(that.currentItem.css("paddingBottom")||0, 10)); }
|
|
793 |
if(!p.width()) { p.width(that.currentItem.innerWidth() - parseInt(that.currentItem.css("paddingLeft")||0, 10) - parseInt(that.currentItem.css("paddingRight")||0, 10)); }
|
|
672 | 794 |
} |
673 | 795 |
}; |
674 | 796 |
} |
675 | 797 |
|
676 | 798 |
//Create the placeholder |
677 |
self.placeholder = $(o.placeholder.element.call(self.element, self.currentItem));
|
|
799 |
that.placeholder = $(o.placeholder.element.call(that.element, that.currentItem));
|
|
678 | 800 |
|
679 | 801 |
//Append it after the actual current item |
680 |
self.currentItem.after(self.placeholder);
|
|
802 |
that.currentItem.after(that.placeholder);
|
|
681 | 803 |
|
682 | 804 |
//Update the size of the placeholder (TODO: Logic to fuzzy, see line 316/317) |
683 |
o.placeholder.update(self, self.placeholder);
|
|
805 |
o.placeholder.update(that, that.placeholder);
|
|
684 | 806 |
|
685 | 807 |
}, |
686 | 808 |
|
687 | 809 |
_contactContainers: function(event) { |
688 |
|
|
689 |
// get innermost container that intersects with item
|
|
690 |
var innermostContainer = null, innermostIndex = null;
|
|
691 |
|
|
692 |
|
|
693 |
for (var i = this.containers.length - 1; i >= 0; i--){
|
|
694 |
|
|
695 |
// never consider a container that's located within the item itself
|
|
696 |
if($.ui.contains(this.currentItem[0], this.containers[i].element[0]))
|
|
810 |
var i, j, dist, itemWithLeastDistance, posProperty, sizeProperty, base, cur, nearBottom, floating, |
|
811 |
innermostContainer = null,
|
|
812 |
innermostIndex = null;
|
|
813 |
|
|
814 |
// get innermost container that intersects with item |
|
815 |
for (i = this.containers.length - 1; i >= 0; i--) {
|
|
816 |
|
|
817 |
// never consider a container that's located within the item itself |
|
818 |
if($.contains(this.currentItem[0], this.containers[i].element[0])) {
|
|
697 | 819 |
continue; |
820 |
} |
|
698 | 821 |
|
699 | 822 |
if(this._intersectsWith(this.containers[i].containerCache)) { |
700 | 823 |
|
701 |
// if we've already found a container and it's more "inner" than this, then continue
|
|
702 |
if(innermostContainer && $.ui.contains(this.containers[i].element[0], innermostContainer.element[0]))
|
|
824 |
// if we've already found a container and it's more "inner" than this, then continue |
|
825 |
if(innermostContainer && $.contains(this.containers[i].element[0], innermostContainer.element[0])) {
|
|
703 | 826 |
continue; |
827 |
} |
|
704 | 828 |
|
705 |
innermostContainer = this.containers[i];
|
|
829 |
innermostContainer = this.containers[i]; |
|
706 | 830 |
innermostIndex = i; |
707 |
|
|
831 |
|
|
708 | 832 |
} else { |
709 |
// container doesn't intersect. trigger "out" event if necessary
|
|
833 |
// container doesn't intersect. trigger "out" event if necessary |
|
710 | 834 |
if(this.containers[i].containerCache.over) { |
711 | 835 |
this.containers[i]._trigger("out", event, this._uiHash(this)); |
712 | 836 |
this.containers[i].containerCache.over = 0; |
... | ... | |
714 | 838 |
} |
715 | 839 |
|
716 | 840 |
} |
717 |
|
|
718 |
// if no intersecting containers found, return |
|
719 |
if(!innermostContainer) return; |
|
841 |
|
|
842 |
// if no intersecting containers found, return |
|
843 |
if(!innermostContainer) { |
|
844 |
return; |
|
845 |
} |
|
720 | 846 |
|
721 | 847 |
// move the item into the container if it's not there already |
722 | 848 |
if(this.containers.length === 1) { |
849 |
if (!this.containers[innermostIndex].containerCache.over) { |
|
850 |
this.containers[innermostIndex]._trigger("over", event, this._uiHash(this)); |
|
851 |
this.containers[innermostIndex].containerCache.over = 1; |
|
852 |
} |
|
853 |
} else { |
|
854 |
|
|
855 |
//When entering a new container, we will find the item with the least distance and append our item near it |
|
856 |
dist = 10000; |
|
857 |
itemWithLeastDistance = null; |
|
858 |
floating = innermostContainer.floating || isFloating(this.currentItem); |
|
859 |
posProperty = floating ? "left" : "top"; |
|
860 |
sizeProperty = floating ? "width" : "height"; |
|
861 |
base = this.positionAbs[posProperty] + this.offset.click[posProperty]; |
|
862 |
for (j = this.items.length - 1; j >= 0; j--) { |
|
863 |
if(!$.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) { |
|
864 |
continue; |
|
865 |
} |
|
866 |
if(this.items[j].item[0] === this.currentItem[0]) { |
|
867 |
continue; |
|
868 |
} |
|
869 |
if (floating && !isOverAxis(this.positionAbs.top + this.offset.click.top, this.items[j].top, this.items[j].height)) { |
|
870 |
continue; |
|
871 |
} |
|
872 |
cur = this.items[j].item.offset()[posProperty]; |
|
873 |
nearBottom = false; |
|
874 |
if(Math.abs(cur - base) > Math.abs(cur + this.items[j][sizeProperty] - base)){ |
|
875 |
nearBottom = true; |
|
876 |
cur += this.items[j][sizeProperty]; |
|
877 |
} |
|
878 |
|
|
879 |
if(Math.abs(cur - base) < dist) { |
|
880 |
dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j]; |
|
881 |
this.direction = nearBottom ? "up": "down"; |
|
882 |
} |
|
883 |
} |
|
884 |
|
|
885 |
//Check if dropOnEmpty is enabled |
|
886 |
if(!itemWithLeastDistance && !this.options.dropOnEmpty) { |
|
887 |
return; |
|
888 |
} |
|
889 |
|
|
890 |
if(this.currentContainer === this.containers[innermostIndex]) { |
|
891 |
return; |
|
892 |
} |
|
893 |
|
|
894 |
itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true); |
|
895 |
this._trigger("change", event, this._uiHash()); |
|
896 |
this.containers[innermostIndex]._trigger("change", event, this._uiHash(this)); |
|
897 |
this.currentContainer = this.containers[innermostIndex]; |
|
898 |
|
|
899 |
//Update the placeholder |
|
900 |
this.options.placeholder.update(this.currentContainer, this.placeholder); |
|
901 |
|
|
723 | 902 |
this.containers[innermostIndex]._trigger("over", event, this._uiHash(this)); |
724 | 903 |
this.containers[innermostIndex].containerCache.over = 1; |
725 |
} else if(this.currentContainer != this.containers[innermostIndex]) { |
|
726 |
|
|
727 |
//When entering a new container, we will find the item with the least distance and append our item near it |
|
728 |
var dist = 10000; var itemWithLeastDistance = null; var base = this.positionAbs[this.containers[innermostIndex].floating ? 'left' : 'top']; |
|
729 |
for (var j = this.items.length - 1; j >= 0; j--) { |
|
730 |
if(!$.ui.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) continue; |
|
731 |
var cur = this.items[j][this.containers[innermostIndex].floating ? 'left' : 'top']; |
|
732 |
if(Math.abs(cur - base) < dist) { |
|
733 |
dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j]; |
|
734 |
} |
|
735 |
} |
|
736 |
|
|
737 |
if(!itemWithLeastDistance && !this.options.dropOnEmpty) //Check if dropOnEmpty is enabled |
|
738 |
return; |
|
739 |
|
|
740 |
this.currentContainer = this.containers[innermostIndex]; |
|
741 |
itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true); |
|
742 |
this._trigger("change", event, this._uiHash()); |
|
743 |
this.containers[innermostIndex]._trigger("change", event, this._uiHash(this)); |
|
744 |
|
|
745 |
//Update the placeholder |
|
746 |
this.options.placeholder.update(this.currentContainer, this.placeholder); |
|
747 |
|
|
748 |
this.containers[innermostIndex]._trigger("over", event, this._uiHash(this)); |
|
749 |
this.containers[innermostIndex].containerCache.over = 1; |
|
750 |
} |
|
751 |
|
|
752 |
|
|
904 |
} |
|
905 |
|
|
906 |
|
|
753 | 907 |
}, |
754 | 908 |
|
755 | 909 |
_createHelper: function(event) { |
756 | 910 |
|
757 |
var o = this.options;
|
|
758 |
var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event, this.currentItem])) : (o.helper == 'clone' ? this.currentItem.clone() : this.currentItem);
|
|
911 |
var o = this.options,
|
|
912 |
helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event, this.currentItem])) : (o.helper === "clone" ? this.currentItem.clone() : this.currentItem);
|
|
759 | 913 |
|
760 |
if(!helper.parents('body').length) //Add the helper to the DOM if that didn't happen already |
|
761 |
$(o.appendTo != 'parent' ? o.appendTo : this.currentItem[0].parentNode)[0].appendChild(helper[0]); |
|
914 |
//Add the helper to the DOM if that didn't happen already |
|
915 |
if(!helper.parents("body").length) { |
|
916 |
$(o.appendTo !== "parent" ? o.appendTo : this.currentItem[0].parentNode)[0].appendChild(helper[0]); |
|
917 |
} |
|
762 | 918 |
|
763 |
if(helper[0] == this.currentItem[0])
|
|
919 |
if(helper[0] === this.currentItem[0]) {
|
|
764 | 920 |
this._storedCSS = { width: this.currentItem[0].style.width, height: this.currentItem[0].style.height, position: this.currentItem.css("position"), top: this.currentItem.css("top"), left: this.currentItem.css("left") }; |
921 |
} |
|
765 | 922 |
|
766 |
if(helper[0].style.width == '' || o.forceHelperSize) helper.width(this.currentItem.width()); |
|
767 |
if(helper[0].style.height == '' || o.forceHelperSize) helper.height(this.currentItem.height()); |
|
923 |
if(!helper[0].style.width || o.forceHelperSize) { |
|
924 |
helper.width(this.currentItem.width()); |
|
925 |
} |
|
926 |
if(!helper[0].style.height || o.forceHelperSize) { |
|
927 |
helper.height(this.currentItem.height()); |
|
928 |
} |
|
768 | 929 |
|
769 | 930 |
return helper; |
770 | 931 |
|
771 | 932 |
}, |
772 | 933 |
|
773 | 934 |
_adjustOffsetFromHelper: function(obj) { |
774 |
if (typeof obj == 'string') {
|
|
775 |
obj = obj.split(' ');
|
|
935 |
if (typeof obj === "string") {
|
|
936 |
obj = obj.split(" ");
|
|
776 | 937 |
} |
777 | 938 |
if ($.isArray(obj)) { |
778 | 939 |
obj = {left: +obj[0], top: +obj[1] || 0}; |
779 | 940 |
} |
780 |
if ('left' in obj) {
|
|
941 |
if ("left" in obj) {
|
|
781 | 942 |
this.offset.click.left = obj.left + this.margins.left; |
782 | 943 |
} |
783 |
if ('right' in obj) {
|
|
944 |
if ("right" in obj) {
|
|
784 | 945 |
this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left; |
785 | 946 |
} |
786 |
if ('top' in obj) {
|
|
947 |
if ("top" in obj) {
|
|
787 | 948 |
this.offset.click.top = obj.top + this.margins.top; |
788 | 949 |
} |
789 |
if ('bottom' in obj) {
|
|
950 |
if ("bottom" in obj) {
|
|
790 | 951 |
this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top; |
791 | 952 |
} |
792 | 953 |
}, |
... | ... | |
802 | 963 |
// 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent |
803 | 964 |
// 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that |
804 | 965 |
// the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag |
805 |
if(this.cssPosition == 'absolute' && this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) {
|
|
966 |
if(this.cssPosition === "absolute" && this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) {
|
|
806 | 967 |
po.left += this.scrollParent.scrollLeft(); |
807 | 968 |
po.top += this.scrollParent.scrollTop(); |
808 | 969 |
} |
809 | 970 |
|
810 |
if((this.offsetParent[0] == document.body) //This needs to be actually done for all browsers, since pageX/pageY includes this information |
|
811 |
|| (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.browser.msie)) //Ugly IE fix |
|
971 |
// This needs to be actually done for all browsers, since pageX/pageY includes this information |
|
972 |
// with an ugly IE fix |
|
973 |
if( this.offsetParent[0] === document.body || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() === "html" && $.ui.ie)) { |
|
812 | 974 |
po = { top: 0, left: 0 }; |
975 |
} |
|
813 | 976 |
|
814 | 977 |
return { |
815 | 978 |
top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0), |
... | ... | |
820 | 983 |
|
821 | 984 |
_getRelativeOffset: function() { |
822 | 985 |
|
823 |
if(this.cssPosition == "relative") { |
|
986 |
if(this.cssPosition === "relative") {
|
|
824 | 987 |
var p = this.currentItem.position(); |
825 | 988 |
return { |
826 | 989 |
top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(), |
... | ... | |
848 | 1011 |
|
849 | 1012 |
_setContainment: function() { |
850 | 1013 |
|
851 |
var o = this.options; |
|
852 |
if(o.containment == 'parent') o.containment = this.helper[0].parentNode; |
|
853 |
if(o.containment == 'document' || o.containment == 'window') this.containment = [ |
|
854 |
0 - this.offset.relative.left - this.offset.parent.left, |
|
855 |
0 - this.offset.relative.top - this.offset.parent.top, |
|
856 |
$(o.containment == 'document' ? document : window).width() - this.helperProportions.width - this.margins.left, |
|
857 |
($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top |
|
858 |
]; |
|
1014 |
var ce, co, over, |
|
1015 |
o = this.options; |
|
1016 |
if(o.containment === "parent") { |
|
1017 |
o.containment = this.helper[0].parentNode; |
|
1018 |
} |
|
1019 |
if(o.containment === "document" || o.containment === "window") { |
|
1020 |
this.containment = [ |
|
1021 |
0 - this.offset.relative.left - this.offset.parent.left, |
|
1022 |
0 - this.offset.relative.top - this.offset.parent.top, |
|
1023 |
$(o.containment === "document" ? document : window).width() - this.helperProportions.width - this.margins.left, |
|
1024 |
($(o.containment === "document" ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top |
|
1025 |
]; |
|
1026 |
} |
|
859 | 1027 |
|
860 | 1028 |
if(!(/^(document|window|parent)$/).test(o.containment)) { |
861 |
var ce = $(o.containment)[0];
|
|
862 |
var co = $(o.containment).offset();
|
|
863 |
var over = ($(ce).css("overflow") != 'hidden');
|
|
1029 |
ce = $(o.containment)[0]; |
|
1030 |
co = $(o.containment).offset(); |
|
1031 |
over = ($(ce).css("overflow") !== "hidden");
|
|
864 | 1032 |
|
865 | 1033 |
this.containment = [ |
866 | 1034 |
co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0) - this.margins.left, |
... | ... | |
874 | 1042 |
|
875 | 1043 |
_convertPositionTo: function(d, pos) { |
876 | 1044 |
|
877 |
if(!pos) pos = this.position; |
|
878 |
var mod = d == "absolute" ? 1 : -1; |
|
879 |
var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); |
|
1045 |
if(!pos) { |
|
1046 |
pos = this.position; |
|
1047 |
} |
|
1048 |
var mod = d === "absolute" ? 1 : -1, |
|
1049 |
scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, |
|
1050 |
scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); |
|
880 | 1051 |
|
881 | 1052 |
return { |
882 | 1053 |
top: ( |
883 |
pos.top // The absolute mouse position |
|
884 |
+ this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent
|
|
885 |
+ this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border)
|
|
886 |
- ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
|
|
1054 |
pos.top + // The absolute mouse position
|
|
1055 |
this.offset.relative.top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
|
|
1056 |
this.offset.parent.top * mod - // The offsetParent's offset without borders (offset + border)
|
|
1057 |
( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
|
|
887 | 1058 |
), |
888 | 1059 |
left: ( |
889 |
pos.left // The absolute mouse position |
|
890 |
+ this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent
|
|
891 |
+ this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border)
|
|
892 |
- ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
|
|
1060 |
pos.left + // The absolute mouse position
|
|
1061 |
this.offset.relative.left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
|
|
1062 |
this.offset.parent.left * mod - // The offsetParent's offset without borders (offset + border)
|
|
1063 |
( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
|
|
893 | 1064 |
) |
894 | 1065 |
}; |
895 | 1066 |
|
... | ... | |
897 | 1068 |
|
898 | 1069 |
_generatePosition: function(event) { |
899 | 1070 |
|
900 |
var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); |
|
1071 |
var top, left, |
|
1072 |
o = this.options, |
|
1073 |
pageX = event.pageX, |
|
1074 |
pageY = event.pageY, |
|
1075 |
scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); |
|
901 | 1076 |
|
902 | 1077 |
// This is another very weird special case that only happens for relative elements: |
903 | 1078 |
// 1. If the css position is relative |
904 | 1079 |
// 2. and the scroll parent is the document or similar to the offset parent |
905 | 1080 |
// we have to refresh the relative offset during the scroll so there are no jumps |
906 |
if(this.cssPosition == 'relative' && !(this.scrollParent[0] != document && this.scrollParent[0] != this.offsetParent[0])) {
|
|
1081 |
if(this.cssPosition === "relative" && !(this.scrollParent[0] !== document && this.scrollParent[0] !== this.offsetParent[0])) {
|
|
907 | 1082 |
this.offset.relative = this._getRelativeOffset(); |
908 | 1083 |
} |
909 | 1084 |
|
910 |
var pageX = event.pageX; |
|
911 |
var pageY = event.pageY; |
|
912 |
|
|
913 | 1085 |
/* |
914 | 1086 |
* - Position constraining - |
915 | 1087 |
* Constrain the position to a mix of grid, containment. |
... | ... | |
918 | 1090 |
if(this.originalPosition) { //If we are not dragging yet, we won't check for options |
919 | 1091 |
|
920 | 1092 |
if(this.containment) { |
921 |
if(event.pageX - this.offset.click.left < this.containment[0]) pageX = this.containment[0] + this.offset.click.left; |
|
922 |
if(event.pageY - this.offset.click.top < this.containment[1]) pageY = this.containment[1] + this.offset.click.top; |
|
923 |
if(event.pageX - this.offset.click.left > this.containment[2]) pageX = this.containment[2] + this.offset.click.left; |
|
924 |
if(event.pageY - this.offset.click.top > this.containment[3]) pageY = this.containment[3] + this.offset.click.top; |
|
1093 |
if(event.pageX - this.offset.click.left < this.containment[0]) { |
|
1094 |
pageX = this.containment[0] + this.offset.click.left; |
|
1095 |
} |
|
1096 |
if(event.pageY - this.offset.click.top < this.containment[1]) { |
|
1097 |
pageY = this.containment[1] + this.offset.click.top; |
|
1098 |
} |
|
1099 |
if(event.pageX - this.offset.click.left > this.containment[2]) { |
|
1100 |
pageX = this.containment[2] + this.offset.click.left; |
|
1101 |
} |
|
1102 |
if(event.pageY - this.offset.click.top > this.containment[3]) { |
|
1103 |
pageY = this.containment[3] + this.offset.click.top; |
|
1104 |
} |
|
925 | 1105 |
} |
926 | 1106 |
|
927 | 1107 |
if(o.grid) { |
928 |
var top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1];
|
|
929 |
pageY = this.containment ? (!(top - this.offset.click.top < this.containment[1] || top - this.offset.click.top > this.containment[3]) ? top : (!(top - this.offset.click.top < this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
|
|
1108 |
top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1]; |
|
1109 |
pageY = this.containment ? ( (top - this.offset.click.top >= this.containment[1] && top - this.offset.click.top <= this.containment[3]) ? top : ((top - this.offset.click.top >= this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
|
|
930 | 1110 |
|
931 |
var left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0];
|
|
932 |
pageX = this.containment ? (!(left - this.offset.click.left < this.containment[0] || left - this.offset.click.left > this.containment[2]) ? left : (!(left - this.offset.click.left < this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
|
|
1111 |
left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0]; |
|
1112 |
pageX = this.containment ? ( (left - this.offset.click.left >= this.containment[0] && left - this.offset.click.left <= this.containment[2]) ? left : ((left - this.offset.click.left >= this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
|
|
933 | 1113 |
} |
934 | 1114 |
|
935 | 1115 |
} |
936 | 1116 |
|
937 | 1117 |
return { |
938 | 1118 |
top: ( |
939 |
pageY // The absolute mouse position |
|
940 |
- this.offset.click.top // Click offset (relative to the element)
|
|
941 |
- this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent
|
|
942 |
- this.offset.parent.top // The offsetParent's offset without borders (offset + border)
|
|
943 |
+ ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
|
|
1119 |
pageY - // The absolute mouse position
|
|
1120 |
this.offset.click.top - // Click offset (relative to the element)
|
|
1121 |
this.offset.relative.top - // Only for relative positioned nodes: Relative offset from element to offset parent
|
|
1122 |
this.offset.parent.top + // The offsetParent's offset without borders (offset + border)
|
|
1123 |
( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
|
|
944 | 1124 |
), |
945 | 1125 |
left: ( |
946 |
pageX // The absolute mouse position |
|
947 |
- this.offset.click.left // Click offset (relative to the element)
|
|
948 |
- this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent
|
|
949 |
- this.offset.parent.left // The offsetParent's offset without borders (offset + border)
|
|
950 |
+ ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
|
|
1126 |
pageX - // The absolute mouse position
|
|
1127 |
this.offset.click.left - // Click offset (relative to the element)
|
|
1128 |
this.offset.relative.left - // Only for relative positioned nodes: Relative offset from element to offset parent
|
|
1129 |
this.offset.parent.left + // The offsetParent's offset without borders (offset + border)
|
|
1130 |
( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
|
|
951 | 1131 |
) |
952 | 1132 |
}; |
953 | 1133 |
|
... | ... | |
955 | 1135 |
|
956 | 1136 |
_rearrange: function(event, i, a, hardRefresh) { |
957 | 1137 |
|
958 |
a ? a[0].appendChild(this.placeholder[0]) : i.item[0].parentNode.insertBefore(this.placeholder[0], (this.direction == 'down' ? i.item[0] : i.item[0].nextSibling));
|
|
1138 |
a ? a[0].appendChild(this.placeholder[0]) : i.item[0].parentNode.insertBefore(this.placeholder[0], (this.direction === "down" ? i.item[0] : i.item[0].nextSibling));
|
|
959 | 1139 |
|
960 | 1140 |
//Various things done here to improve the performance: |
961 | 1141 |
// 1. we create a setTimeout, that calls refreshPositions |
... | ... | |
963 | 1143 |
// 3. on the local scope, we copy the counter variable, and check in the timeout, if it's still the same |
964 | 1144 |
// 4. this lets only the last addition to the timeout stack through |
965 | 1145 |
this.counter = this.counter ? ++this.counter : 1; |
966 |
var self = this, counter = this.counter;
|
|
1146 |
var counter = this.counter; |
|
967 | 1147 |
|
968 |
window.setTimeout(function() { |
|
969 |
if(counter == self.counter) self.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove |
|
970 |
},0); |
|
1148 |
this._delay(function() { |
|
1149 |
if(counter === this.counter) { |
|
1150 |
this.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove |
|
1151 |
} |
|
1152 |
}); |
|
971 | 1153 |
|
972 | 1154 |
}, |
973 | 1155 |
|
... | ... | |
976 | 1158 |
this.reverting = false; |
977 | 1159 |
// We delay all events that have to be triggered to after the point where the placeholder has been removed and |
978 | 1160 |
// everything else normalized again |
979 |
var delayedTriggers = [], self = this; |
|
1161 |
var i, |
|
1162 |
delayedTriggers = []; |
|
980 | 1163 |
|
981 | 1164 |
// We first have to update the dom position of the actual currentItem |
982 | 1165 |
// Note: don't do it if the current item is already removed (by a user), or it gets reappended (see #4088) |
983 |
if(!this._noFinalSort && this.currentItem[0].parentNode) this.placeholder.before(this.currentItem); |
|
1166 |
if(!this._noFinalSort && this.currentItem.parent().length) { |
|
1167 |
this.placeholder.before(this.currentItem); |
|
1168 |
} |
|
984 | 1169 |
this._noFinalSort = null; |
985 | 1170 |
|
986 |
if(this.helper[0] == this.currentItem[0]) { |
|
987 |
for(var i in this._storedCSS) { |
|
988 |
if(this._storedCSS[i] == 'auto' || this._storedCSS[i] == 'static') this._storedCSS[i] = ''; |
|
1171 |
if(this.helper[0] === this.currentItem[0]) { |
|
1172 |
for(i in this._storedCSS) { |
|
1173 |
if(this._storedCSS[i] === "auto" || this._storedCSS[i] === "static") { |
|
1174 |
this._storedCSS[i] = ""; |
|
1175 |
} |
|
989 | 1176 |
} |
990 | 1177 |
this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper"); |
991 | 1178 |
} else { |
992 | 1179 |
this.currentItem.show(); |
993 | 1180 |
} |
994 | 1181 |
|
995 |
if(this.fromOutside && !noPropagation) delayedTriggers.push(function(event) { this._trigger("receive", event, this._uiHash(this.fromOutside)); }); |
|
996 |
if((this.fromOutside || this.domPosition.prev != this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) && !noPropagation) delayedTriggers.push(function(event) { this._trigger("update", event, this._uiHash()); }); //Trigger update callback if the DOM position has changed |
|
997 |
if(!$.ui.contains(this.element[0], this.currentItem[0])) { //Node was moved out of the current element |
|
998 |
if(!noPropagation) delayedTriggers.push(function(event) { this._trigger("remove", event, this._uiHash()); }); |
|
999 |
for (var i = this.containers.length - 1; i >= 0; i--){ |
|
1000 |
if($.ui.contains(this.containers[i].element[0], this.currentItem[0]) && !noPropagation) { |
|
1001 |
delayedTriggers.push((function(c) { return function(event) { c._trigger("receive", event, this._uiHash(this)); }; }).call(this, this.containers[i])); |
|
1002 |
delayedTriggers.push((function(c) { return function(event) { c._trigger("update", event, this._uiHash(this)); }; }).call(this, this.containers[i])); |
|
1003 |
} |
|
1004 |
}; |
|
1005 |
}; |
|
1182 |
if(this.fromOutside && !noPropagation) { |
|
1183 |
delayedTriggers.push(function(event) { this._trigger("receive", event, this._uiHash(this.fromOutside)); }); |
|
1184 |
} |
|
1185 |
if((this.fromOutside || this.domPosition.prev !== this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent !== this.currentItem.parent()[0]) && !noPropagation) { |
|
1186 |
delayedTriggers.push(function(event) { this._trigger("update", event, this._uiHash()); }); //Trigger update callback if the DOM position has changed |
|
1187 |
} |
|
1188 |
|
|
1189 |
// Check if the items Container has Changed and trigger appropriate |
|
1190 |
// events. |
|
1191 |
if (this !== this.currentContainer) { |
|
1192 |
if(!noPropagation) { |
|
1193 |
delayedTriggers.push(function(event) { this._trigger("remove", event, this._uiHash()); }); |
|
1194 |
delayedTriggers.push((function(c) { return function(event) { c._trigger("receive", event, this._uiHash(this)); }; }).call(this, this.currentContainer)); |
|
1195 |
delayedTriggers.push((function(c) { return function(event) { c._trigger("update", event, this._uiHash(this)); }; }).call(this, this.currentContainer)); |
|
1196 |
} |
|
1197 |
} |
|
1198 |
|
|
1006 | 1199 |
|
1007 | 1200 |
//Post events to containers |
1008 |
for (var i = this.containers.length - 1; i >= 0; i--){ |
|
1009 |
if(!noPropagation) delayedTriggers.push((function(c) { return function(event) { c._trigger("deactivate", event, this._uiHash(this)); }; }).call(this, this.containers[i])); |
|
1201 |
for (i = this.containers.length - 1; i >= 0; i--){ |
|
1202 |
if(!noPropagation) { |
|
1203 |
delayedTriggers.push((function(c) { return function(event) { c._trigger("deactivate", event, this._uiHash(this)); }; }).call(this, this.containers[i])); |
|
1204 |
} |
|
1010 | 1205 |
if(this.containers[i].containerCache.over) { |
1011 | 1206 |
delayedTriggers.push((function(c) { return function(event) { c._trigger("out", event, this._uiHash(this)); }; }).call(this, this.containers[i])); |
1012 | 1207 |
this.containers[i].containerCache.over = 0; |
... | ... | |
1014 | 1209 |
} |
1015 | 1210 |
|
1016 | 1211 |
//Do what was originally in plugins |
1017 |
if(this._storedCursor) $('body').css("cursor", this._storedCursor); //Reset cursor |
|
1018 |
if(this._storedOpacity) this.helper.css("opacity", this._storedOpacity); //Reset opacity |
|
1019 |
if(this._storedZIndex) this.helper.css("zIndex", this._storedZIndex == 'auto' ? '' : this._storedZIndex); //Reset z-index |
|
1212 |
if ( this.storedCursor ) { |
|
1213 |
this.document.find( "body" ).css( "cursor", this.storedCursor ); |
|
1214 |
this.storedStylesheet.remove(); |
|
1215 |
} |
|
1216 |
if(this._storedOpacity) { |
|
1217 |
this.helper.css("opacity", this._storedOpacity); |
|
1218 |
} |
|
1219 |
if(this._storedZIndex) { |
|
1220 |
this.helper.css("zIndex", this._storedZIndex === "auto" ? "" : this._storedZIndex); |
|
1221 |
} |
|
1020 | 1222 |
|
1021 | 1223 |
this.dragging = false; |
1022 | 1224 |
if(this.cancelHelperRemoval) { |
1023 | 1225 |
if(!noPropagation) { |
1024 | 1226 |
this._trigger("beforeStop", event, this._uiHash()); |
1025 |
for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events |
|
1227 |
for (i=0; i < delayedTriggers.length; i++) { |
|
1228 |
delayedTriggers[i].call(this, event); |
|
1229 |
} //Trigger all delayed events |
|
1026 | 1230 |
this._trigger("stop", event, this._uiHash()); |
1027 | 1231 |
} |
1232 |
|
|
1233 |
this.fromOutside = false; |
|
1028 | 1234 |
return false; |
1029 | 1235 |
} |
1030 | 1236 |
|
1031 |
if(!noPropagation) this._trigger("beforeStop", event, this._uiHash()); |
|
1237 |
if(!noPropagation) { |
|
1238 |
this._trigger("beforeStop", event, this._uiHash()); |
|
1239 |
} |
|
1032 | 1240 |
|
1033 | 1241 |
//$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node! |
1034 | 1242 |
this.placeholder[0].parentNode.removeChild(this.placeholder[0]); |
1035 | 1243 |
|
1036 |
if(this.helper[0] != this.currentItem[0]) this.helper.remove(); this.helper = null; |
|
1244 |
if(this.helper[0] !== this.currentItem[0]) { |
|
1245 |
this.helper.remove(); |
|
1246 |
} |
|
1247 |
this.helper = null; |
|
1037 | 1248 |
|
1038 | 1249 |
if(!noPropagation) { |
1039 |
for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events |
|
1250 |
for (i=0; i < delayedTriggers.length; i++) { |
|
1251 |
delayedTriggers[i].call(this, event); |
|
1252 |
} //Trigger all delayed events |
|
1040 | 1253 |
this._trigger("stop", event, this._uiHash()); |
1041 | 1254 |
} |
1042 | 1255 |
|
... | ... | |
1051 | 1264 |
} |
1052 | 1265 |
}, |
1053 | 1266 |
|
1054 |
_uiHash: function(inst) { |
|
1055 |
var self = inst || this;
|
|
1267 |
_uiHash: function(_inst) {
|
|
1268 |
var inst = _inst || this;
|
|
1056 | 1269 |
return { |
1057 |
helper: self.helper, |
|
1058 |
placeholder: self.placeholder || $([]), |
Formats disponibles : Unified diff
Weekly update of contrib modules