From 604e0949e33ac53d07c707d1cd6934a73cc6e44b Mon Sep 17 00:00:00 2001 From: Scott González Date: Tue, 17 Sep 2013 09:56:00 -0400 Subject: Sortable: Moved helper methods into the widget prototype. --- ui/jquery.ui.sortable.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'ui/jquery.ui.sortable.js') diff --git a/ui/jquery.ui.sortable.js b/ui/jquery.ui.sortable.js index c76a02397..9553da5dc 100644 --- a/ui/jquery.ui.sortable.js +++ b/ui/jquery.ui.sortable.js @@ -15,14 +15,6 @@ */ (function( $, undefined ) { -function isOverAxis( x, reference, size ) { - return ( x >= reference ) && ( x < ( reference + size ) ); -} - -function isFloating(item) { - return (/left|right/).test(item.css("float")) || (/inline|table-cell/).test(item.css("display")); -} - $.widget("ui.sortable", $.ui.mouse, { version: "@VERSION", widgetEventPrefix: "sort", @@ -65,6 +57,15 @@ $.widget("ui.sortable", $.ui.mouse, { stop: null, update: null }, + + _isOverAxis: function( x, reference, size ) { + return ( x >= reference ) && ( x < ( reference + size ) ); + }, + + _isFloating: function( item ) { + return (/left|right/).test(item.css("float")) || (/inline|table-cell/).test(item.css("display")); + }, + _create: function() { var o = this.options; @@ -75,7 +76,7 @@ $.widget("ui.sortable", $.ui.mouse, { this.refresh(); //Let's determine if the items are being displayed horizontally - this.floating = this.items.length ? o.axis === "x" || isFloating(this.items[0].item) : false; + 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(); @@ -554,8 +555,8 @@ $.widget("ui.sortable", $.ui.mouse, { _intersectsWithPointer: function(item) { - var isOverElementHeight = (this.options.axis === "x") || isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height), - isOverElementWidth = (this.options.axis === "y") || isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width), + var isOverElementHeight = (this.options.axis === "x") || this._isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height), + isOverElementWidth = (this.options.axis === "y") || this._isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width), isOverElement = isOverElementHeight && isOverElementWidth, verticalDirection = this._getDragVerticalDirection(), horizontalDirection = this._getDragHorizontalDirection(); @@ -572,8 +573,8 @@ $.widget("ui.sortable", $.ui.mouse, { _intersectsWithSides: function(item) { - var isOverBottomHalf = isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height), - isOverRightHalf = isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width), + var isOverBottomHalf = this._isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height), + isOverRightHalf = this._isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width), verticalDirection = this._getDragVerticalDirection(), horizontalDirection = this._getDragHorizontalDirection(); @@ -846,7 +847,7 @@ $.widget("ui.sortable", $.ui.mouse, { //When entering a new container, we will find the item with the least distance and append our item near it dist = 10000; itemWithLeastDistance = null; - floating = innermostContainer.floating || isFloating(this.currentItem); + floating = innermostContainer.floating || this._isFloating(this.currentItem); posProperty = floating ? "left" : "top"; sizeProperty = floating ? "width" : "height"; base = this.positionAbs[posProperty] + this.offset.click[posProperty]; @@ -857,7 +858,7 @@ $.widget("ui.sortable", $.ui.mouse, { if(this.items[j].item[0] === this.currentItem[0]) { continue; } - if (floating && !isOverAxis(this.positionAbs.top + this.offset.click.top, this.items[j].top, this.items[j].height)) { + 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]; -- cgit v1.2.3 From 601ad962e0a417bb369378ed7704a0b493eac365 Mon Sep 17 00:00:00 2001 From: Kris Borchers Date: Wed, 30 Oct 2013 00:00:18 -0500 Subject: Sortable: Adjust itemWithLeastDistance algorithm in _contactContainers to properly handle dragging items to the beginning and ends of lists. Fixes #9314 - Sortable: Items cannot be dragged directly into bottom position. Fixes #9381 - Sortable: Connected list placeholders have an inaccurate initial position --- tests/unit/sortable/sortable.html | 12 ++++++++++-- tests/unit/sortable/sortable_core.js | 18 +++++++++++++++++- ui/jquery.ui.sortable.js | 17 ++++++++--------- 3 files changed, 35 insertions(+), 12 deletions(-) (limited to 'ui/jquery.ui.sortable.js') diff --git a/tests/unit/sortable/sortable.html b/tests/unit/sortable/sortable.html index 8e0bac501..b03c786e1 100644 --- a/tests/unit/sortable/sortable.html +++ b/tests/unit/sortable/sortable.html @@ -38,7 +38,7 @@ margin: 1px; border-width: 0; } - #sortable li{ + #sortable li, #sortable2 li{ padding: 0; margin: 0; border-width: 0; @@ -58,7 +58,15 @@
    -
      +
        +
      • Item 1
      • +
      • Item 2
      • +
      • Item 3
      • +
      • Item 4
      • +
      • Item 5
      • +
      + +
      • Item 1
      • Item 2
      • Item 3
      • diff --git a/tests/unit/sortable/sortable_core.js b/tests/unit/sortable/sortable_core.js index 211f8ac95..18e7dae08 100644 --- a/tests/unit/sortable/sortable_core.js +++ b/tests/unit/sortable/sortable_core.js @@ -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 ); diff --git a/ui/jquery.ui.sortable.js b/ui/jquery.ui.sortable.js index 9553da5dc..4ba2576c1 100644 --- a/ui/jquery.ui.sortable.js +++ b/ui/jquery.ui.sortable.js @@ -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"; } } -- cgit v1.2.3