Skip to content

Commit 932c644

Browse files
committed
Sortable: Redetermine floating flag when recalculating positions
This addresses a bug where users initialize empty sortable lists are add items dynamically. In this situation refresh() should recognize the position and orientation of the new items. Fixes #7498
1 parent e9643f6 commit 932c644

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

tests/unit/sortable/sortable_methods.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,30 @@ test( "disable", function() {
9090
equal( chainable, element, "disable is chainable" );
9191
});
9292

93+
test( "refresh() should update the positions of initially empty lists (see #7498)", function() {
94+
expect( 1 );
95+
96+
var changeCount = 0,
97+
element = $( "#qunit-fixture" ).html( "<ul></ul>" ).find( "ul" );
98+
99+
element
100+
.css({ "float": "left", width: "100px" })
101+
.sortable({
102+
change: function() {
103+
changeCount++;
104+
}
105+
})
106+
.append( "<li>a</li><li>a</li>" )
107+
.find( "li" )
108+
.css({ "float": "left", width: "50px", height: "50px" });
109+
110+
// Switch the order of the two li elements
111+
element.find( "li:first" ).simulate( "drag", {
112+
dx: 55,
113+
moves: 15
114+
});
115+
116+
equal( changeCount, 1 );
117+
});
118+
93119
})(jQuery);

ui/sortable.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,12 @@ return $.widget("ui.sortable", $.ui.mouse, {
7777
},
7878

7979
_create: function() {
80-
81-
var o = this.options;
8280
this.containerCache = {};
8381
this.element.addClass("ui-sortable");
8482

8583
//Get the items
8684
this.refresh();
8785

88-
//Let's determine if the items are being displayed horizontally
89-
this.floating = this.items.length ? o.axis === "x" || this._isFloating(this.items[0].item) : false;
90-
9186
//Let's determine the parent's offset
9287
this.offset = this.element.offset();
9388

@@ -731,6 +726,10 @@ return $.widget("ui.sortable", $.ui.mouse, {
731726

732727
refreshPositions: function(fast) {
733728

729+
// Determine whether items are being displayed horizontally
730+
this.floating = this.items.length ? this.options.axis === "x" ||
731+
this._isFloating( this.items[ 0 ].item ) : false;
732+
734733
//This has to be redone because due to the item being moved out/into the offsetParent, the offsetParent's position will change
735734
if(this.offsetParent && this.helper) {
736735
this.offset.parent = this._getParentOffset();

0 commit comments

Comments
 (0)