Skip to content

Commit 89473f6

Browse files
zhizhangchenmikesherov
authored andcommitted
Sortable: Skip items that are not at the same line as the cursor when floating. Fixes #8792: Issue with floated items in connected lists.
1 parent e0b2644 commit 89473f6

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

ui/jquery.ui.sortable.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ function isOverAxis( x, reference, size ) {
2121
return ( x > reference ) && ( x < ( reference + size ) );
2222
}
2323

24+
function isFloating(item) {
25+
return (/left|right/).test(item.css("float")) || (/inline|table-cell/).test(item.css("display"));
26+
}
27+
2428
$.widget("ui.sortable", $.ui.mouse, {
2529
version: "@VERSION",
2630
widgetEventPrefix: "sort",
@@ -73,7 +77,7 @@ $.widget("ui.sortable", $.ui.mouse, {
7377
this.refresh();
7478

7579
//Let's determine if the items are being displayed horizontally
76-
this.floating = this.items.length ? o.axis === "x" || (/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;
7781

7882
//Let's determine the parent's offset
7983
this.offset = this.element.offset();
@@ -799,7 +803,7 @@ $.widget("ui.sortable", $.ui.mouse, {
799803
},
800804

801805
_contactContainers: function(event) {
802-
var i, j, dist, itemWithLeastDistance, posProperty, sizeProperty, base, cur, nearBottom,
806+
var i, j, dist, itemWithLeastDistance, posProperty, sizeProperty, base, cur, nearBottom, floating,
803807
innermostContainer = null,
804808
innermostIndex = null;
805809

@@ -845,8 +849,9 @@ $.widget("ui.sortable", $.ui.mouse, {
845849
//When entering a new container, we will find the item with the least distance and append our item near it
846850
dist = 10000;
847851
itemWithLeastDistance = null;
848-
posProperty = this.containers[innermostIndex].floating ? "left" : "top";
849-
sizeProperty = this.containers[innermostIndex].floating ? "width" : "height";
852+
floating = innermostContainer.floating || isFloating(this.currentItem);
853+
posProperty = floating ? "left" : "top";
854+
sizeProperty = floating ? "width" : "height";
850855
base = this.positionAbs[posProperty] + this.offset.click[posProperty];
851856
for (j = this.items.length - 1; j >= 0; j--) {
852857
if(!$.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) {
@@ -855,6 +860,9 @@ $.widget("ui.sortable", $.ui.mouse, {
855860
if(this.items[j].item[0] === this.currentItem[0]) {
856861
continue;
857862
}
863+
if (floating && !isOverAxis(this.positionAbs.top + this.offset.click.top, this.items[j].top, this.items[j].height)) {
864+
continue;
865+
}
858866
cur = this.items[j].item.offset()[posProperty];
859867
nearBottom = false;
860868
if(Math.abs(cur - base) > Math.abs(cur + this.items[j][sizeProperty] - base)){
@@ -873,10 +881,14 @@ $.widget("ui.sortable", $.ui.mouse, {
873881
return;
874882
}
875883

876-
this.currentContainer = this.containers[innermostIndex];
884+
if(this.currentContainer === this.containers[innermostIndex]) {
885+
return;
886+
}
887+
877888
itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true);
878889
this._trigger("change", event, this._uiHash());
879890
this.containers[innermostIndex]._trigger("change", event, this._uiHash(this));
891+
this.currentContainer = this.containers[innermostIndex];
880892

881893
//Update the placeholder
882894
this.options.placeholder.update(this.currentContainer, this.placeholder);

0 commit comments

Comments
 (0)