]> source.dussan.org Git - jquery-ui.git/commitdiff
Draggable: Ensure parent is correct after dragging through sortable
authorMike Sherov <mike.sherov@gmail.com>
Sun, 9 Nov 2014 01:23:08 +0000 (20:23 -0500)
committerScott González <scott.gonzalez@gmail.com>
Tue, 10 Mar 2015 15:59:22 +0000 (11:59 -0400)
Fixes #10669
(cherry picked from commit d8077dc562bfca60906a160e20186608a10b7a87)

tests/unit/draggable/draggable_options.js
ui/draggable.js

index e54ae1df46d8d31732f3837b4c679c227a2dbc41..d8bbedc9163a2b6cdb7c2b92dfca9e13655cc581 100644 (file)
@@ -405,6 +405,29 @@ test( "connectToSortable, dragging through one sortable to a second", function()
        element.simulate( "drag", dragParams );
 });
 
+test( "connectToSortable, dragging through a sortable", function() {
+       expect( 1 );
+
+       var draggable = $( "#draggableSortable" ).draggable({
+                       scroll: false,
+                       connectToSortable: "#sortable2"
+               }),
+               sortable = $( "#sortable2" ).sortable(),
+               sortableOffset = sortable.offset();
+
+       // http://bugs.jqueryui.com/ticket/10669
+       // Draggable: Position issue with connectToSortable
+       draggable.one( "dragstop", function() {
+               equal( draggable.parent().attr( "id" ), "sortable", "restored draggable to original parent" );
+       });
+
+       draggable.simulate( "drag", {
+               x: sortableOffset.left + 25,
+               y: sortableOffset.top + sortable.outerHeight() + 400,
+               moves: 20
+       });
+});
+
 test( "{ containment: Element }", function() {
        expect( 1 );
 
index a9d0279c493f8c8f0b368bad2d8d4c95822dee8d..c3821ba8eec185da6472b9e135cc3ffb536ca26b 100644 (file)
@@ -800,6 +800,9 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
                                if ( !sortable.isOver ) {
                                        sortable.isOver = 1;
 
+                                       // Store draggable's parent in case we need to reappend to it later.
+                                       draggable._parent = ui.helper.parent();
+
                                        sortable.currentItem = ui.helper
                                                .appendTo( sortable.element )
                                                .data( "ui-sortable-item", true );
@@ -876,8 +879,9 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
                                                sortable.placeholder.remove();
                                        }
 
-                                       // Recalculate the draggable's offset considering the sortable
-                                       // may have modified them in unexpected ways (#8809)
+                                       // Restore and recalculate the draggable's offset considering the sortable
+                                       // may have modified them in unexpected ways. (#8809, #10669)
+                                       ui.helper.appendTo( draggable._parent );
                                        draggable._refreshOffsets( event );
                                        ui.position = draggable._generatePosition( event, true );