]> source.dussan.org Git - jquery-ui.git/commitdiff
Sortable: Redetermine floating flag when recalculating positions
authorTJ VanToll <tj.vantoll@gmail.com>
Fri, 31 Oct 2014 13:46:41 +0000 (09:46 -0400)
committerScott González <scott.gonzalez@gmail.com>
Tue, 10 Mar 2015 15:59:14 +0000 (11:59 -0400)
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
Closes gh-1381
(cherry picked from commit f656aebe3f99356b7eb91ffdafe6689ecc8fb4ae)

tests/unit/sortable/sortable_methods.js
ui/sortable.js

index f3fe240e701635d7a373c14aa0d82b18fb2bd5c1..9c0a86a359b214f5fa065414bf7d1a4e081ff5c9 100644 (file)
@@ -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);
index 13a57e897b4b523dd367519782eae8ebf51e24a7..4cfb28979a007c6f4c3b33fa228c62f2cc1d0708 100644 (file)
@@ -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();
 
@@ -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();