Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sortable: Redetermine floating flag when recalculating positions #1381

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions tests/unit/sortable/sortable_methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,39 @@ test( "disable", function() {
equal( chainable, element, "disable is chainable" );
});

test( "refresh() should update the positions of initially empty lists (see #7498)", function() {
expect( 1 );

var changeCount = 0,
element = $( "#qunit-fixture" ).html( "<ul></ul>" ).find( "ul" );

element
.css({
"float": "left",
width: "100px"
})
.sortable({
change: function() {
changeCount++;
}
})
.append( "<li>a</li><li>a</li>" )
.find( "li" )
.css({
"float": "left",
width: "50px",
height: "50px"
});

element.sortable( "refresh" );

// Switch the order of the two li elements
element.find( "li" ).eq( 0 ).simulate( "drag", {
dx: 55,
moves: 15
});

equal( changeCount, 1 );
});

})(jQuery);
10 changes: 5 additions & 5 deletions ui/sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,12 @@ return $.widget("ui.sortable", $.ui.mouse, {
},

_create: function() {

var o = this.options;
this.containerCache = {};
this.element.addClass("ui-sortable");

//Get the items
this.refresh();

//Let's determine if the items are being displayed horizontally
this.floating = this.items.length ? o.axis === "x" || this._isFloating(this.items[0].item) : false;

//Let's determine the parent's offset
this.offset = this.element.offset();

Expand Down Expand Up @@ -731,6 +726,11 @@ return $.widget("ui.sortable", $.ui.mouse, {

refreshPositions: function(fast) {

// Determine whether items are being displayed horizontally
this.floating = this.items.length ?
this.options.axis === "x" || this._isFloating( this.items[ 0 ].item ) :
false;

//This has to be redone because due to the item being moved out/into the offsetParent, the offsetParent's position will change
if(this.offsetParent && this.helper) {
this.offset.parent = this._getParentOffset();
Expand Down