]> source.dussan.org Git - jquery-ui.git/commitdiff
Sortable: Adjust itemWithLeastDistance algorithm in _contactContainers to properly...
authorKris Borchers <kris.borchers@gmail.com>
Wed, 30 Oct 2013 05:00:18 +0000 (00:00 -0500)
committerKris Borchers <kris.borchers@gmail.com>
Fri, 1 Nov 2013 20:17:05 +0000 (15:17 -0500)
tests/unit/sortable/sortable.html
tests/unit/sortable/sortable_core.js
ui/jquery.ui.sortable.js

index 8e0bac501f41801705d208bf9c5877693e04b065..b03c786e1ad9f8d766ef22d1a1be807d1ffb311e 100644 (file)
@@ -38,7 +38,7 @@
                margin: 1px;
                border-width: 0;
        }
-       #sortable li{
+       #sortable li, #sortable2 li{
                padding: 0;
                margin: 0;
                border-width: 0;
 <ol id="qunit-tests"></ol>
 <div id="qunit-fixture">
 
-<ul id="sortable">
+<ul id="sortable" class="connectWith">
+       <li>Item 1</li>
+       <li>Item 2</li>
+       <li>Item 3</li>
+       <li>Item 4</li>
+       <li>Item 5</li>
+</ul>
+
+<ul id="sortable2" class="connectWith">
        <li>Item 1</li>
        <li>Item 2</li>
        <li>Item 3</li>
index 211f8ac954f1da6f1ed520a603dea79dcd4727ba..18e7dae0864f12610848870dbcab416631539673 100644 (file)
@@ -1,3 +1,19 @@
 /*
  * sortable_core.js
- */
\ No newline at end of file
+ */
+
+(function( $ ) {
+
+module( "sortable: core" );
+
+test( "#9314: Sortable: Items cannot be dragged directly into bottom position", function() {
+       expect( 1 );
+
+       var el = $( ".connectWith" ).sortable({
+                       connectWith: ".connectWith"
+               });
+
+       TestHelpers.sortable.sort( $( "li", el[ 1 ] )[ 0 ], 0, -12, 5, "Dragging the sortable into connected sortable" );
+});
+
+})( jQuery );
index 9553da5dce69fef52f0f7c6fd8f9dcc6f853ffad..4ba2576c1bc79136cc9354a74740a7ce65dadabb 100644 (file)
@@ -799,7 +799,7 @@ $.widget("ui.sortable", $.ui.mouse, {
        },
 
        _contactContainers: function(event) {
-               var i, j, dist, itemWithLeastDistance, posProperty, sizeProperty, base, cur, nearBottom, floating,
+               var i, j, dist, itemWithLeastDistance, posProperty, sizeProperty, cur, nearBottom, floating, axis,
                        innermostContainer = null,
                        innermostIndex = null;
 
@@ -850,7 +850,8 @@ $.widget("ui.sortable", $.ui.mouse, {
                        floating = innermostContainer.floating || this._isFloating(this.currentItem);
                        posProperty = floating ? "left" : "top";
                        sizeProperty = floating ? "width" : "height";
-                       base = this.positionAbs[posProperty] + this.offset.click[posProperty];
+                       axis = floating ? "clientX" : "clientY";
+
                        for (j = this.items.length - 1; j >= 0; j--) {
                                if(!$.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) {
                                        continue;
@@ -858,18 +859,16 @@ $.widget("ui.sortable", $.ui.mouse, {
                                if(this.items[j].item[0] === this.currentItem[0]) {
                                        continue;
                                }
-                               if (floating && !this._isOverAxis(this.positionAbs.top + this.offset.click.top, this.items[j].top, this.items[j].height)) {
-                                       continue;
-                               }
+
                                cur = this.items[j].item.offset()[posProperty];
                                nearBottom = false;
-                               if(Math.abs(cur - base) > Math.abs(cur + this.items[j][sizeProperty] - base)){
+                               if ( event[ axis ] - cur > this.items[ j ][ sizeProperty ] / 2 ) {
                                        nearBottom = true;
-                                       cur += this.items[j][sizeProperty];
                                }
 
-                               if(Math.abs(cur - base) < dist) {
-                                       dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j];
+                               if ( Math.abs( event[ axis ] - cur ) < dist ) {
+                                       dist = Math.abs( event[ axis ] - cur );
+                                       itemWithLeastDistance = this.items[ j ];
                                        this.direction = nearBottom ? "up": "down";
                                }
                        }