diff options
author | Mike Sherov <mike.sherov@gmail.com> | 2014-08-22 15:16:41 -0400 |
---|---|---|
committer | Mike Sherov <mike.sherov@gmail.com> | 2014-08-23 15:08:54 -0400 |
commit | 95546c5d045f8055b121f24d3e35468e2a570c1b (patch) | |
tree | 61038aba83e98454e532711a4651ff39b56d04d2 /tests/unit/draggable | |
parent | a62612ce42d4ac95130d0eee47ed6b62e6588515 (diff) | |
download | jquery-ui-95546c5d045f8055b121f24d3e35468e2a570c1b.tar.gz jquery-ui-95546c5d045f8055b121f24d3e35468e2a570c1b.zip |
Draggable: No cloning in connectToSortable and ensure correct position
Draggables now forcefully recalculate their position when dragged out
of a sortable. Sortables now override draggable position when a
draggable is dragged into it. Lastly, no longer remove sortable helper
when dragging a draggable out, which allows us to not use a clone.
Fixes #7734
Fixes #8809
Closes gh-1322
Diffstat (limited to 'tests/unit/draggable')
-rw-r--r-- | tests/unit/draggable/draggable.html | 40 | ||||
-rw-r--r-- | tests/unit/draggable/draggable_options.js | 66 |
2 files changed, 105 insertions, 1 deletions
diff --git a/tests/unit/draggable/draggable.html b/tests/unit/draggable/draggable.html index 8a19fc046..3b4db9921 100644 --- a/tests/unit/draggable/draggable.html +++ b/tests/unit/draggable/draggable.html @@ -46,6 +46,31 @@ #draggable3, #draggable4 { z-index: 100; } + #sortable { + position: relative; + top: 8000px; + left: 10px; + } + #sortable2 { + position: relative; + top: 9000px; + left: 10px; + } + .sortable { + width: 300px; + height: 100px; + padding: 0; + margin: 0; + border: 0; + } + .sortable li { + height: 100px; + padding: 0; + margin: 0; + border: 0; + list-style: none; + display: inline-block; + } </style> <script src="../../../external/qunit/qunit.js"></script> @@ -60,7 +85,8 @@ "ui/mouse.js", "ui/resizable.js", "ui/draggable.js", - "ui/droppable.js" + "ui/droppable.js", + "ui/sortable.js" ] }); </script> @@ -90,6 +116,18 @@ </div> <div style="width: 1px; height: 1000px;"></div> <div style="position: absolute; width: 1px; height: 2000px;"></div> + <ul id="sortable" class="sortable"> + <li>Item 0</li> + <li id="draggableSortable">Item 1</li> + <li>Item 2</li> + <li>Item 3</li> + </ul> + <ul id="sortable2" class="sortable"> + <li id="draggableSortableClone">Item 0</li> + <li>Item 1</li> + <li>Item 2</li> + <li>Item 3</li> + </ul> </div> </body> diff --git a/tests/unit/draggable/draggable_options.js b/tests/unit/draggable/draggable_options.js index abce62a46..f724decbc 100644 --- a/tests/unit/draggable/draggable_options.js +++ b/tests/unit/draggable/draggable_options.js @@ -252,6 +252,72 @@ test( "{ connectToSortable: selector }, default", function() { }); */ +test( "connectToSortable, dragging out of a sortable", function() { + expect( 3 ); + + var sortItem, dragHelper, + element = $( "#draggableSortable" ).draggable({ + scroll: false, + connectToSortable: "#sortable" + }), + sortable = $( "#sortable" ).sortable(), + dx = 50, + dy = 50, + offsetBefore = element.offset(), + offsetExpected = { + left: offsetBefore.left + dx, + top: offsetBefore.top + dy + }; + + $( sortable ).one( "sortstart", function( event, ui ) { + sortItem = ui.item; + }); + + $( element ).one( "drag", function( event, ui ) { + dragHelper = ui.helper; + }); + + $( element ).one( "dragstop", function( event, ui ) { + // http://bugs.jqueryui.com/ticket/8809 + // Position issue when connected to sortable + deepEqual( ui.helper.offset(), offsetExpected, "draggable offset is correct" ); + + // http://bugs.jqueryui.com/ticket/7734 + // HTML IDs are removed when dragging to a Sortable + equal( sortItem[ 0 ], dragHelper[ 0 ], "both have the same helper" ); + equal( sortItem.attr( "id" ), dragHelper.attr( "id" ), "both have the same id" ); + }); + + element.simulate( "drag", { + dx: dx, + dy: dy + }); +}); + +test( "connectToSortable, dragging clone into sortable", function() { + expect( 1 ); + + var element = $( "#draggableSortableClone" ).draggable({ + scroll: false, + connectToSortable: "#sortable", + helper: "clone" + }), + sortable = $( "#sortable" ).sortable(), + offsetSortable = sortable.offset(); + + $( sortable ).one( "sortbeforestop", function( event, ui ) { + // http://bugs.jqueryui.com/ticket/8809 + // Position issue when connected to sortable + deepEqual( ui.helper.offset(), offsetSortable, "sortable offset is correct" ); + }); + + element.simulate( "drag", { + x: offsetSortable.left + 1, + y: offsetSortable.top + 1, + moves: 1 + }); +}); + test( "{ containment: Element }", function() { expect( 1 ); |