Skip to content

Commit b76ac30

Browse files
committed
Sortable: calculating item positions on the fly and setting the direction variable when inserting an item into a different sortable. Fixed #8268 - Items may not be inserted into the correct position when dragged between connected sortables
(cherry picked from commit c42bdce) Conflicts: ui/jquery.ui.sortable.js
1 parent 637d102 commit b76ac30

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

ui/jquery.ui.sortable.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -730,30 +730,31 @@ $.widget("ui.sortable", $.ui.mouse, {
730730
if(this.containers.length === 1) {
731731
this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
732732
this.containers[innermostIndex].containerCache.over = 1;
733-
} else if(this.currentContainer != this.containers[innermostIndex]) {
734-
735-
//When entering a new container, we will find the item with the least distance and append our item near it
736-
var dist = 10000; var itemWithLeastDistance = null; var base = this.positionAbs[this.containers[innermostIndex].floating ? 'left' : 'top'];
737-
for (var j = this.items.length - 1; j >= 0; j--) {
738-
if(!$.ui.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) continue;
739-
var cur = this.items[j][this.containers[innermostIndex].floating ? 'left' : 'top'];
740-
if(Math.abs(cur - base) < dist) {
741-
dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j];
742-
}
743-
}
744-
745-
if(!itemWithLeastDistance && !this.options.dropOnEmpty) //Check if dropOnEmpty is enabled
746-
return;
747-
748-
this.currentContainer = this.containers[innermostIndex];
749-
itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true);
750-
this._trigger("change", event, this._uiHash());
751-
this.containers[innermostIndex]._trigger("change", event, this._uiHash(this));
752-
753-
//Update the placeholder
754-
this.options.placeholder.update(this.currentContainer, this.placeholder);
755-
756-
this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
733+
} else if(this.currentContainer != this.containers[innermostIndex]) {
734+
735+
//When entering a new container, we will find the item with the least distance and append our item near it
736+
var dist = 10000; var itemWithLeastDistance = null; var base = this.positionAbs[this.containers[innermostIndex].floating ? 'left' : 'top'];
737+
for (var j = this.items.length - 1; j >= 0; j--) {
738+
if(!$.ui.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) continue;
739+
var cur = this.containers[innermostIndex].floating ? this.items[j].item.offset().left : this.items[j].item.offset().top;
740+
if(Math.abs(cur - base) < dist) {
741+
dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j];
742+
this.direction = (cur - base > 0) ? 'down' : 'up';
743+
}
744+
}
745+
746+
if(!itemWithLeastDistance && !this.options.dropOnEmpty) //Check if dropOnEmpty is enabled
747+
return;
748+
749+
this.currentContainer = this.containers[innermostIndex];
750+
itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true);
751+
this._trigger("change", event, this._uiHash());
752+
this.containers[innermostIndex]._trigger("change", event, this._uiHash(this));
753+
754+
//Update the placeholder
755+
this.options.placeholder.update(this.currentContainer, this.placeholder);
756+
757+
this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
757758
this.containers[innermostIndex].containerCache.over = 1;
758759
}
759760

0 commit comments

Comments
 (0)