]> source.dussan.org Git - jquery-ui.git/commitdiff
Draggable: Refresh sortables when draggable is added or removed
authorMike Sherov <mike.sherov@gmail.com>
Mon, 25 Aug 2014 12:21:15 +0000 (08:21 -0400)
committerMike Sherov <mike.sherov@gmail.com>
Mon, 25 Aug 2014 22:23:11 +0000 (18:23 -0400)
Since a sortable grows or shrinks when a draggable element is added
to it, refresh the cached positions of sortables whenever an element
is added or removed from the sortable.

Refs #9675

ui/draggable.js

index 7ad5d0c3765586e1f1d6ce28bcaf355d3ffe9cf8..4e81ac3ebe986dae183e26e41e1b2d1996774c12 100644 (file)
@@ -834,6 +834,12 @@ $.ui.plugin.add("draggable", "connectToSortable", {
                                        // used solely in the revert option to handle "valid/invalid".
                                        draggable.dropped = sortable.element;
 
+                                       // Need to refreshPositions of all sortables in the case that
+                                       // adding to one sortable changes the location of the other sortables (#9675)
+                                       $.each( draggable.sortables, function() {
+                                               this.refreshPositions();
+                                       });
+
                                        // hack so receive/update callbacks work (mostly)
                                        draggable.currentItem = draggable.element;
                                        sortable.fromOutside = draggable;
@@ -882,6 +888,12 @@ $.ui.plugin.add("draggable", "connectToSortable", {
 
                                        // Inform draggable that the helper is no longer in a valid drop zone
                                        draggable.dropped = false;
+
+                                       // Need to refreshPositions of all sortables just in case removing
+                                       // from one sortable changes the location of other sortables (#9675)
+                                       $.each( draggable.sortables, function() {
+                                               this.refreshPositions();
+                                       });
                                }
                        }
                });