From aa9de1a01fcb2bc8dc1fe9ef31e5942f2ce53673 Mon Sep 17 00:00:00 2001 From: "A. Wells" Date: Thu, 16 Feb 2017 13:48:45 -0500 Subject: [PATCH 01/12] Update sortable.js * Created _scroll extension point and migrated scroll code from _mouseDrag * Cleaned up logic for scrolled * Fixed appendTo functionality to match documentation * Remove unnecessary function calls * Move set-up position functions to appropriate place * Base scrollParent on placeholder and not helper * Update scrollParent when switching containers --- ui/widgets/sortable.js | 146 +++++++++++++++++++++++------------------ 1 file changed, 82 insertions(+), 64 deletions(-) diff --git a/ui/widgets/sortable.js b/ui/widgets/sortable.js index fcb33ace145..3bb5fc4250b 100644 --- a/ui/widgets/sortable.js +++ b/ui/widgets/sortable.js @@ -195,6 +195,11 @@ return $.widget( "ui.sortable", $.ui.mouse, { // mouseCapture this.refreshPositions(); + //Prepare the dragged items parent + this.appendTo = $( o.appendTo !== "parent" ? + o.appendTo : + this.currentItem.parent() ); + //Create and append the visible helper this.helper = this._createHelper( event ); @@ -209,9 +214,6 @@ return $.widget( "ui.sortable", $.ui.mouse, { //Cache the margins of the original element this._cacheMargins(); - //Get the next scrolling parent - this.scrollParent = this.helper.scrollParent(); - //The element's absolute position on the page minus margins this.offset = this.currentItem.offset(); this.offset = { @@ -240,11 +242,6 @@ return $.widget( "ui.sortable", $.ui.mouse, { parent: this._getParentOffset() } ); - //Generate the original position - this.originalPosition = this._generatePosition( event ); - this.originalPageX = event.pageX; - this.originalPageY = event.pageY; - //Adjust the mouse offset relative to the helper if "cursorAt" is supplied ( o.cursorAt && this._adjustOffsetFromHelper( o.cursorAt ) ); @@ -263,6 +260,9 @@ return $.widget( "ui.sortable", $.ui.mouse, { //Create the placeholder this._createPlaceholder(); + //Get the next scrolling parent (based on the placeholder in case the helper is appended) + this.scrollParent = this.placeholder.scrollParent(); + //Set a containment if given in the options if ( o.containment ) { this._setContainment(); @@ -330,13 +330,73 @@ return $.widget( "ui.sortable", $.ui.mouse, { this._addClass( this.helper, "ui-sortable-helper" ); - // Execute the drag once - this causes the helper not to be visiblebefore getting its - // correct position - this._mouseDrag( event ); + //Move the helper, if needed + if (!this.helper.parent().is(this.appendTo)) { + this.helper.detach().appendTo(this.appendTo); + // update position + this.offset.parent = this._getParentOffset(); + } + + //Generate the original position + this.position = this.originalPosition = this._generatePosition( event ); + this.originalPageX = event.pageX; + this.originalPageY = event.pageY; + this.lastPositionAbs = this.positionAbs = this._convertPositionTo( "absolute" ); + return true; }, + _scroll: function( event ) { + var o = this.options, + scrolled = false; + + if ( this.scrollParent[ 0 ] !== this.document[ 0 ] && + this.scrollParent[ 0 ].tagName !== "HTML" ) { + + if ( ( this.overflowOffset.top + this.scrollParent[ 0 ].offsetHeight ) - + event.pageY < o.scrollSensitivity ) { + this.scrollParent[ 0 ].scrollTop = + scrolled = this.scrollParent[ 0 ].scrollTop + o.scrollSpeed; + } else if ( event.pageY - this.overflowOffset.top < o.scrollSensitivity ) { + this.scrollParent[ 0 ].scrollTop = + scrolled = this.scrollParent[ 0 ].scrollTop - o.scrollSpeed; + } + + if ( ( this.overflowOffset.left + this.scrollParent[ 0 ].offsetWidth ) - + event.pageX < o.scrollSensitivity ) { + this.scrollParent[ 0 ].scrollLeft = scrolled = + this.scrollParent[ 0 ].scrollLeft + o.scrollSpeed; + } else if ( event.pageX - this.overflowOffset.left < o.scrollSensitivity ) { + this.scrollParent[ 0 ].scrollLeft = scrolled = + this.scrollParent[ 0 ].scrollLeft - o.scrollSpeed; + } + + } else { + + if ( event.pageY - this.document.scrollTop() < o.scrollSensitivity ) { + scrolled = this.document.scrollTop( this.document.scrollTop() - o.scrollSpeed ); + } else if ( this.window.height() - ( event.pageY - this.document.scrollTop() ) < + o.scrollSensitivity ) { + scrolled = this.document.scrollTop( this.document.scrollTop() + o.scrollSpeed ); + } + + if ( event.pageX - this.document.scrollLeft() < o.scrollSensitivity ) { + scrolled = this.document.scrollLeft( + this.document.scrollLeft() - o.scrollSpeed + ); + } else if ( this.window.width() - ( event.pageX - this.document.scrollLeft() ) < + o.scrollSensitivity ) { + scrolled = this.document.scrollLeft( + this.document.scrollLeft() + o.scrollSpeed + ); + } + + } + + return scrolled; + }, + _mouseDrag: function( event ) { var i, item, itemElement, intersection, o = this.options, @@ -346,63 +406,20 @@ return $.widget( "ui.sortable", $.ui.mouse, { this.position = this._generatePosition( event ); this.positionAbs = this._convertPositionTo( "absolute" ); - if ( !this.lastPositionAbs ) { - this.lastPositionAbs = this.positionAbs; - } - //Do scrolling if ( this.options.scroll ) { - if ( this.scrollParent[ 0 ] !== this.document[ 0 ] && - this.scrollParent[ 0 ].tagName !== "HTML" ) { - - if ( ( this.overflowOffset.top + this.scrollParent[ 0 ].offsetHeight ) - - event.pageY < o.scrollSensitivity ) { - this.scrollParent[ 0 ].scrollTop = - scrolled = this.scrollParent[ 0 ].scrollTop + o.scrollSpeed; - } else if ( event.pageY - this.overflowOffset.top < o.scrollSensitivity ) { - this.scrollParent[ 0 ].scrollTop = - scrolled = this.scrollParent[ 0 ].scrollTop - o.scrollSpeed; - } - - if ( ( this.overflowOffset.left + this.scrollParent[ 0 ].offsetWidth ) - - event.pageX < o.scrollSensitivity ) { - this.scrollParent[ 0 ].scrollLeft = scrolled = - this.scrollParent[ 0 ].scrollLeft + o.scrollSpeed; - } else if ( event.pageX - this.overflowOffset.left < o.scrollSensitivity ) { - this.scrollParent[ 0 ].scrollLeft = scrolled = - this.scrollParent[ 0 ].scrollLeft - o.scrollSpeed; - } - } else { - - if ( event.pageY - this.document.scrollTop() < o.scrollSensitivity ) { - scrolled = this.document.scrollTop( this.document.scrollTop() - o.scrollSpeed ); - } else if ( this.window.height() - ( event.pageY - this.document.scrollTop() ) < - o.scrollSensitivity ) { - scrolled = this.document.scrollTop( this.document.scrollTop() + o.scrollSpeed ); + if ( scrolled !== false ) { + scrolled = this._scroll( event ); + //Regenerate the absolute position used for position checks + //positionAbs and lastPositionAbs could be adjusted based on the scrolled delta + this.positionAbs = this._convertPositionTo( "absolute" ); + if ( $.ui.ddmanager && !o.dropBehaviour ) { + $.ui.ddmanager.prepareOffsets( this, event ); } - - if ( event.pageX - this.document.scrollLeft() < o.scrollSensitivity ) { - scrolled = this.document.scrollLeft( - this.document.scrollLeft() - o.scrollSpeed - ); - } else if ( this.window.width() - ( event.pageX - this.document.scrollLeft() ) < - o.scrollSensitivity ) { - scrolled = this.document.scrollLeft( - this.document.scrollLeft() + o.scrollSpeed - ); - } - - } - - if ( scrolled !== false && $.ui.ddmanager && !o.dropBehaviour ) { - $.ui.ddmanager.prepareOffsets( this, event ); } } - //Regenerate the absolute position used for position checks - this.positionAbs = this._convertPositionTo( "absolute" ); - //Set the helper position if ( !this.options.axis || this.options.axis !== "y" ) { this.helper[ 0 ].style.left = this.position.left + "px"; @@ -1071,6 +1088,9 @@ return $.widget( "ui.sortable", $.ui.mouse, { //Update the placeholder this.options.placeholder.update( this.currentContainer, this.placeholder ); + //Update scrollParent + this.scrollParent = this.placeholder.scrollParent(); + this.containers[ innermostIndex ]._trigger( "over", event, this._uiHash( this ) ); this.containers[ innermostIndex ].containerCache.over = 1; } @@ -1086,9 +1106,7 @@ return $.widget( "ui.sortable", $.ui.mouse, { //Add the helper to the DOM if that didn't happen already if ( !helper.parents( "body" ).length ) { - $( o.appendTo !== "parent" ? - o.appendTo : - this.currentItem[ 0 ].parentNode )[ 0 ].appendChild( helper[ 0 ] ); + this.appendTo[ 0 ].appendChild( helper[ 0 ] ); } if ( helper[ 0 ] === this.currentItem[ 0 ] ) { From 8b3451339b7b0610079fd0da0a9b7d2879da3af9 Mon Sep 17 00:00:00 2001 From: "A. Wells" Date: Thu, 16 Feb 2017 14:08:26 -0500 Subject: [PATCH 02/12] Update sortable.js * Fixed misplaced merge lines --- ui/widgets/sortable.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui/widgets/sortable.js b/ui/widgets/sortable.js index 3bb5fc4250b..153cc7eb2d9 100644 --- a/ui/widgets/sortable.js +++ b/ui/widgets/sortable.js @@ -408,9 +408,8 @@ return $.widget( "ui.sortable", $.ui.mouse, { //Do scrolling if ( this.options.scroll ) { - + scrolled = this._scroll( event ); if ( scrolled !== false ) { - scrolled = this._scroll( event ); //Regenerate the absolute position used for position checks //positionAbs and lastPositionAbs could be adjusted based on the scrolled delta this.positionAbs = this._convertPositionTo( "absolute" ); From 01cc678b855d3729cfa5624d09b3ef05f5b4a4c1 Mon Sep 17 00:00:00 2001 From: "A. Wells" Date: Thu, 16 Feb 2017 14:51:09 -0500 Subject: [PATCH 03/12] Update sortable.js * Fixed code style issues --- ui/widgets/sortable.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ui/widgets/sortable.js b/ui/widgets/sortable.js index 153cc7eb2d9..91da0a895e5 100644 --- a/ui/widgets/sortable.js +++ b/ui/widgets/sortable.js @@ -331,9 +331,10 @@ return $.widget( "ui.sortable", $.ui.mouse, { this._addClass( this.helper, "ui-sortable-helper" ); //Move the helper, if needed - if (!this.helper.parent().is(this.appendTo)) { - this.helper.detach().appendTo(this.appendTo); - // update position + if ( !this.helper.parent().is( this.appendTo ) ) { + this.helper.detach().appendTo( this.appendTo ); + + //Update position this.offset.parent = this._getParentOffset(); } From aa922110ad8de1520e1ac763003a0643b314bf67 Mon Sep 17 00:00:00 2001 From: "A. Wells" Date: Thu, 16 Feb 2017 14:54:38 -0500 Subject: [PATCH 04/12] Update sortable.js * Fixed code style issue --- ui/widgets/sortable.js | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/widgets/sortable.js b/ui/widgets/sortable.js index 91da0a895e5..8caf6128c3c 100644 --- a/ui/widgets/sortable.js +++ b/ui/widgets/sortable.js @@ -411,6 +411,7 @@ return $.widget( "ui.sortable", $.ui.mouse, { if ( this.options.scroll ) { scrolled = this._scroll( event ); if ( scrolled !== false ) { + //Regenerate the absolute position used for position checks //positionAbs and lastPositionAbs could be adjusted based on the scrolled delta this.positionAbs = this._convertPositionTo( "absolute" ); From 481c37f104b2dd8a50b1e43014d43934e39f7de6 Mon Sep 17 00:00:00 2001 From: "A. Wells" Date: Thu, 16 Feb 2017 15:40:15 -0500 Subject: [PATCH 05/12] Update sortable.js * Removed scrollParent placeholder basis due to unknown difference between local copy and pushed copy functionality --- ui/widgets/sortable.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ui/widgets/sortable.js b/ui/widgets/sortable.js index 8caf6128c3c..c624bee3892 100644 --- a/ui/widgets/sortable.js +++ b/ui/widgets/sortable.js @@ -214,6 +214,9 @@ return $.widget( "ui.sortable", $.ui.mouse, { //Cache the margins of the original element this._cacheMargins(); + //Get the next scrolling parent + this.scrollParent = this.helper.scrollParent(); + //The element's absolute position on the page minus margins this.offset = this.currentItem.offset(); this.offset = { @@ -260,9 +263,6 @@ return $.widget( "ui.sortable", $.ui.mouse, { //Create the placeholder this._createPlaceholder(); - //Get the next scrolling parent (based on the placeholder in case the helper is appended) - this.scrollParent = this.placeholder.scrollParent(); - //Set a containment if given in the options if ( o.containment ) { this._setContainment(); @@ -1086,12 +1086,12 @@ return $.widget( "ui.sortable", $.ui.mouse, { this.containers[ innermostIndex ]._trigger( "change", event, this._uiHash( this ) ); this.currentContainer = this.containers[ innermostIndex ]; + //Update scrollParent + this.scrollParent = this.helper.scrollParent(); + //Update the placeholder this.options.placeholder.update( this.currentContainer, this.placeholder ); - //Update scrollParent - this.scrollParent = this.placeholder.scrollParent(); - this.containers[ innermostIndex ]._trigger( "over", event, this._uiHash( this ) ); this.containers[ innermostIndex ].containerCache.over = 1; } From 64d765571077f8abf5c217aa21e28d76ab97737f Mon Sep 17 00:00:00 2001 From: "A. Wells" Date: Thu, 16 Feb 2017 16:42:39 -0500 Subject: [PATCH 06/12] Update sortable.js * Fixed merge issue with position of _getParentOffset() and reinstated scrollParent based on placeholder --- ui/widgets/sortable.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ui/widgets/sortable.js b/ui/widgets/sortable.js index c624bee3892..000488ebf6a 100644 --- a/ui/widgets/sortable.js +++ b/ui/widgets/sortable.js @@ -214,9 +214,6 @@ return $.widget( "ui.sortable", $.ui.mouse, { //Cache the margins of the original element this._cacheMargins(); - //Get the next scrolling parent - this.scrollParent = this.helper.scrollParent(); - //The element's absolute position on the page minus margins this.offset = this.currentItem.offset(); this.offset = { @@ -241,10 +238,6 @@ return $.widget( "ui.sortable", $.ui.mouse, { this.helper.css( "position", "absolute" ); this.cssPosition = this.helper.css( "position" ); - $.extend( this.offset, { - parent: this._getParentOffset() - } ); - //Adjust the mouse offset relative to the helper if "cursorAt" is supplied ( o.cursorAt && this._adjustOffsetFromHelper( o.cursorAt ) ); @@ -263,6 +256,13 @@ return $.widget( "ui.sortable", $.ui.mouse, { //Create the placeholder this._createPlaceholder(); + //Get the next scrolling parent + this.scrollParent = this.placeholder.scrollParent(); + + $.extend( this.offset, { + parent: this._getParentOffset() + } ); + //Set a containment if given in the options if ( o.containment ) { this._setContainment(); @@ -1086,12 +1086,12 @@ return $.widget( "ui.sortable", $.ui.mouse, { this.containers[ innermostIndex ]._trigger( "change", event, this._uiHash( this ) ); this.currentContainer = this.containers[ innermostIndex ]; - //Update scrollParent - this.scrollParent = this.helper.scrollParent(); - //Update the placeholder this.options.placeholder.update( this.currentContainer, this.placeholder ); + //Update scrollParent + this.scrollParent = this.placeholder.scrollParent(); + this.containers[ innermostIndex ]._trigger( "over", event, this._uiHash( this ) ); this.containers[ innermostIndex ].containerCache.over = 1; } From 35215a8d9ddcea4b6edf94d5a248b4f9cdb59e44 Mon Sep 17 00:00:00 2001 From: "A. Wells" Date: Thu, 16 Feb 2017 19:19:33 -0500 Subject: [PATCH 07/12] Update sortable.js * Restored _mouseDrag call from _mouseStart --- ui/widgets/sortable.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ui/widgets/sortable.js b/ui/widgets/sortable.js index 000488ebf6a..16f045660b2 100644 --- a/ui/widgets/sortable.js +++ b/ui/widgets/sortable.js @@ -344,6 +344,8 @@ return $.widget( "ui.sortable", $.ui.mouse, { this.originalPageY = event.pageY; this.lastPositionAbs = this.positionAbs = this._convertPositionTo( "absolute" ); + this._mouseDrag( event ); + return true; }, From 764b6b2432674f9688a0651909d5e54d49757f58 Mon Sep 17 00:00:00 2001 From: "A. Wells" Date: Fri, 17 Feb 2017 14:19:20 -0500 Subject: [PATCH 08/12] Update sortable.js * Fix item intersection after scroll --- ui/widgets/sortable.js | 55 ++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/ui/widgets/sortable.js b/ui/widgets/sortable.js index 16f045660b2..93e0c29abb6 100644 --- a/ui/widgets/sortable.js +++ b/ui/widgets/sortable.js @@ -352,52 +352,61 @@ return $.widget( "ui.sortable", $.ui.mouse, { _scroll: function( event ) { var o = this.options, - scrolled = false; + scrolled = { top: 0, left: 0 }; if ( this.scrollParent[ 0 ] !== this.document[ 0 ] && this.scrollParent[ 0 ].tagName !== "HTML" ) { if ( ( this.overflowOffset.top + this.scrollParent[ 0 ].offsetHeight ) - event.pageY < o.scrollSensitivity ) { - this.scrollParent[ 0 ].scrollTop = - scrolled = this.scrollParent[ 0 ].scrollTop + o.scrollSpeed; + scrolled.top = this.scrollParent[ 0 ].scrollTop; + this.scrollParent[ 0 ].scrollTop = scrolled.top + o.scrollSpeed; + scrolled.top -= this.scrollParent[ 0 ].scrollTop; } else if ( event.pageY - this.overflowOffset.top < o.scrollSensitivity ) { - this.scrollParent[ 0 ].scrollTop = - scrolled = this.scrollParent[ 0 ].scrollTop - o.scrollSpeed; + scrolled.top = this.scrollParent[ 0 ].scrollTop; + this.scrollParent[ 0 ].scrollTop = scrolled.top - o.scrollSpeed; + scrolled.top += -this.scrollParent[ 0 ].scrollTop; } if ( ( this.overflowOffset.left + this.scrollParent[ 0 ].offsetWidth ) - event.pageX < o.scrollSensitivity ) { - this.scrollParent[ 0 ].scrollLeft = scrolled = - this.scrollParent[ 0 ].scrollLeft + o.scrollSpeed; + scrolled.left = this.scrollParent[ 0 ].scrollLeft; + this.scrollParent[ 0 ].scrollLeft = scroll.left + o.scrollSpeed; + scrolled.left -= this.scrollParent[ 0 ].scrollLeft; } else if ( event.pageX - this.overflowOffset.left < o.scrollSensitivity ) { - this.scrollParent[ 0 ].scrollLeft = scrolled = - this.scrollParent[ 0 ].scrollLeft - o.scrollSpeed; + scrolled.left = this.scrollParent[ 0 ].scrollLeft; + this.scrollParent[ 0 ].scrollLeft = scrolled.left - o.scrollSpeed; + scrolled.left = -this.scrollParent[ 0 ].scrollLeft; } } else { if ( event.pageY - this.document.scrollTop() < o.scrollSensitivity ) { - scrolled = this.document.scrollTop( this.document.scrollTop() - o.scrollSpeed ); + scrolled.top = this.document.scrollTop(); + this.document.scrollTop( scrolled.top - o.scrollSpeed ); + scrolled.top += -this.document.scrollTop(); } else if ( this.window.height() - ( event.pageY - this.document.scrollTop() ) < o.scrollSensitivity ) { - scrolled = this.document.scrollTop( this.document.scrollTop() + o.scrollSpeed ); + scrolled.top = this.document.scrollTop(); + this.document.scrollTop( scrolled.top + o.scrollSpeed ); + scrolled.top -= this.document.scrollTop(); } if ( event.pageX - this.document.scrollLeft() < o.scrollSensitivity ) { - scrolled = this.document.scrollLeft( - this.document.scrollLeft() - o.scrollSpeed - ); + scrolled.left = this.document.scrollLeft(); + this.document.scrollLeft( scrolled.left - o.scrollSpeed ); + scrolled.left += -this.document.scrollLeft(); } else if ( this.window.width() - ( event.pageX - this.document.scrollLeft() ) < o.scrollSensitivity ) { - scrolled = this.document.scrollLeft( - this.document.scrollLeft() + o.scrollSpeed - ); + scrolled.left = this.document.scrollLeft(); + this.document.scrollLeft( scrolled.left + o.scrollSpeed ); + scrolled.left -= this.document.scrollLeft(); } } - return scrolled; + return scrolled === false || + ( ( scrolled.left === 0 ) && ( scrolled.top === 0 ) ) ? false : scrolled; }, _mouseDrag: function( event ) { @@ -414,9 +423,13 @@ return $.widget( "ui.sortable", $.ui.mouse, { scrolled = this._scroll( event ); if ( scrolled !== false ) { - //Regenerate the absolute position used for position checks - //positionAbs and lastPositionAbs could be adjusted based on the scrolled delta - this.positionAbs = this._convertPositionTo( "absolute" ); + //Update all absolute position used for position checks + this.positionAbs.top -= scrolled.top; + this.lastPositionAbs.top -= scrolled.top; + for ( i = this.items.length - 1; i >= 0; i-- ) { + this.items[ i ].top -= scrolled.top; + } + if ( $.ui.ddmanager && !o.dropBehaviour ) { $.ui.ddmanager.prepareOffsets( this, event ); } From 93f77d9eb4343a5ae6fce98f4ee33361b525689f Mon Sep 17 00:00:00 2001 From: "A. Wells" Date: Fri, 17 Feb 2017 19:26:43 -0500 Subject: [PATCH 09/12] Update sortable.js * Update offset as well when moving from sortable with no scrollbar to a sortable with scroll bar * No need to process mouse drag if not in a container --- ui/widgets/sortable.js | 131 ++++++++++++++++++++++------------------- 1 file changed, 72 insertions(+), 59 deletions(-) diff --git a/ui/widgets/sortable.js b/ui/widgets/sortable.js index 93e0c29abb6..60d8150db6f 100644 --- a/ui/widgets/sortable.js +++ b/ui/widgets/sortable.js @@ -418,24 +418,6 @@ return $.widget( "ui.sortable", $.ui.mouse, { this.position = this._generatePosition( event ); this.positionAbs = this._convertPositionTo( "absolute" ); - //Do scrolling - if ( this.options.scroll ) { - scrolled = this._scroll( event ); - if ( scrolled !== false ) { - - //Update all absolute position used for position checks - this.positionAbs.top -= scrolled.top; - this.lastPositionAbs.top -= scrolled.top; - for ( i = this.items.length - 1; i >= 0; i-- ) { - this.items[ i ].top -= scrolled.top; - } - - if ( $.ui.ddmanager && !o.dropBehaviour ) { - $.ui.ddmanager.prepareOffsets( this, event ); - } - } - } - //Set the helper position if ( !this.options.axis || this.options.axis !== "y" ) { this.helper[ 0 ].style.left = this.position.left + "px"; @@ -444,56 +426,79 @@ return $.widget( "ui.sortable", $.ui.mouse, { this.helper[ 0 ].style.top = this.position.top + "px"; } - //Rearrange - for ( i = this.items.length - 1; i >= 0; i-- ) { + //Post events to containers + this._contactContainers( event ); - //Cache variables and intersection, continue if no intersection - item = this.items[ i ]; - itemElement = item.item[ 0 ]; - intersection = this._intersectsWithPointer( item ); - if ( !intersection ) { - continue; - } + if ( this.innermostContainer ) { - // Only put the placeholder inside the current Container, skip all - // items from other containers. This works because when moving - // an item from one container to another the - // currentContainer is switched before the placeholder is moved. - // - // Without this, moving items in "sub-sortables" can cause - // the placeholder to jitter between the outer and inner container. - if ( item.instance !== this.currentContainer ) { - continue; + //Do scrolling + if ( o.scroll ) { + scrolled = this._scroll( event ); + if ( scrolled !== false ) { + this.positionAbs.top -= scrolled.top; + this.lastPositionAbs.top -= scrolled.top; + + //Update all absolute positions used position checks + for ( i = this.items.length - 1; i >= 0; i-- ) { + this.items[ i ].top -= scrolled.top; + } + + if ( $.ui.ddmanager && !o.dropBehaviour ) { + $.ui.ddmanager.prepareOffsets( this, event ); + } + } } - // Cannot intersect with itself - // no useless actions that have been done before - // no action if the item moved is the parent of the item checked - if ( itemElement !== this.currentItem[ 0 ] && - this.placeholder[ intersection === 1 ? "next" : "prev" ]()[ 0 ] !== itemElement && - !$.contains( this.placeholder[ 0 ], itemElement ) && - ( this.options.type === "semi-dynamic" ? - !$.contains( this.element[ 0 ], itemElement ) : - true - ) - ) { - - this.direction = intersection === 1 ? "down" : "up"; - - if ( this.options.tolerance === "pointer" || this._intersectsWithSides( item ) ) { - this._rearrange( event, item ); - } else { - break; + //Rearrange + for ( i = this.items.length - 1; i >= 0; i-- ) { + + //Cache variables and intersection, continue if no intersection + item = this.items[ i ]; + itemElement = item.item[ 0 ]; + intersection = this._intersectsWithPointer( item ); + if ( !intersection ) { + continue; + } + + // Only put the placeholder inside the current Container, skip all + // items from other containers. This works because when moving + // an item from one container to another the + // currentContainer is switched before the placeholder is moved. + // + // Without this, moving items in "sub-sortables" can cause + // the placeholder to jitter between the outer and inner container. + if ( item.instance !== this.currentContainer ) { + continue; } - this._trigger( "change", event, this._uiHash() ); - break; + // Cannot intersect with itself + // no useless actions that have been done before + // no action if the item moved is the parent of the item checked + if ( itemElement !== this.currentItem[ 0 ] && + this.placeholder[ intersection === 1 ? + "next" : "prev" ]()[ 0 ] !== itemElement && + !$.contains( this.placeholder[ 0 ], itemElement ) && + ( this.options.type === "semi-dynamic" ? + !$.contains( this.element[ 0 ], itemElement ) : + true + ) + ) { + + this.direction = intersection === 1 ? "down" : "up"; + + if ( this.options.tolerance === "pointer" || + this._intersectsWithSides( item ) ) { + this._rearrange( event, item ); + } else { + break; + } + + this._trigger( "change", event, this._uiHash() ); + break; + } } } - //Post events to containers - this._contactContainers( event ); - //Interconnect with droppables if ( $.ui.ddmanager ) { $.ui.ddmanager.drag( this, event ); @@ -1036,6 +1041,8 @@ return $.widget( "ui.sortable", $.ui.mouse, { } + this.innermostContainer = innermostContainer; + // If no intersecting containers found, return if ( !innermostContainer ) { return; @@ -1107,6 +1114,12 @@ return $.widget( "ui.sortable", $.ui.mouse, { //Update scrollParent this.scrollParent = this.placeholder.scrollParent(); + //Update overflowOffset + if ( this.scrollParent[ 0 ] !== this.document[ 0 ] && + this.scrollParent[ 0 ].tagName !== "HTML" ) { + this.overflowOffset = this.scrollParent.offset(); + } + this.containers[ innermostIndex ]._trigger( "over", event, this._uiHash( this ) ); this.containers[ innermostIndex ].containerCache.over = 1; } From a8c660dfa6cbe08ba326dd89cc9fc7477dc2dd46 Mon Sep 17 00:00:00 2001 From: "A. Wells" Date: Fri, 17 Feb 2017 19:55:08 -0500 Subject: [PATCH 10/12] Update sortable.js * Missing update of absolute position left component via scroll action --- ui/widgets/sortable.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ui/widgets/sortable.js b/ui/widgets/sortable.js index 60d8150db6f..70571bd3415 100644 --- a/ui/widgets/sortable.js +++ b/ui/widgets/sortable.js @@ -435,12 +435,15 @@ return $.widget( "ui.sortable", $.ui.mouse, { if ( o.scroll ) { scrolled = this._scroll( event ); if ( scrolled !== false ) { + + //Update all absolute positions used in position checks this.positionAbs.top -= scrolled.top; + this.positionAbs.left -= scrolled.left; this.lastPositionAbs.top -= scrolled.top; - - //Update all absolute positions used position checks + this.lastPositionAbs.left -= scrolled.left; for ( i = this.items.length - 1; i >= 0; i-- ) { this.items[ i ].top -= scrolled.top; + this.items[ i ].left -= scrolled.left; } if ( $.ui.ddmanager && !o.dropBehaviour ) { From 5c4becc386515008b24115ca8464468e86a884ae Mon Sep 17 00:00:00 2001 From: "A. Wells" Date: Mon, 20 Feb 2017 15:31:47 -0500 Subject: [PATCH 11/12] Update sortable.js * Scroll values were slightly different from offset values for items so reverted to using offset to update item positions after scroll * Created entry for dragDirection to reduce superflous function calls * Removed unneeded code give fix-up for offsetParent --- ui/widgets/sortable.js | 99 ++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 51 deletions(-) diff --git a/ui/widgets/sortable.js b/ui/widgets/sortable.js index 70571bd3415..f21cf396a68 100644 --- a/ui/widgets/sortable.js +++ b/ui/widgets/sortable.js @@ -352,67 +352,73 @@ return $.widget( "ui.sortable", $.ui.mouse, { _scroll: function( event ) { var o = this.options, - scrolled = { top: 0, left: 0 }; + scrolled = false; if ( this.scrollParent[ 0 ] !== this.document[ 0 ] && this.scrollParent[ 0 ].tagName !== "HTML" ) { if ( ( this.overflowOffset.top + this.scrollParent[ 0 ].offsetHeight ) - event.pageY < o.scrollSensitivity ) { - scrolled.top = this.scrollParent[ 0 ].scrollTop; - this.scrollParent[ 0 ].scrollTop = scrolled.top + o.scrollSpeed; - scrolled.top -= this.scrollParent[ 0 ].scrollTop; + this.scrollParent[ 0 ].scrollTop = + scrolled = this.scrollParent[ 0 ].scrollTop + o.scrollSpeed; } else if ( event.pageY - this.overflowOffset.top < o.scrollSensitivity ) { - scrolled.top = this.scrollParent[ 0 ].scrollTop; - this.scrollParent[ 0 ].scrollTop = scrolled.top - o.scrollSpeed; - scrolled.top += -this.scrollParent[ 0 ].scrollTop; + this.scrollParent[ 0 ].scrollTop = + scrolled = this.scrollParent[ 0 ].scrollTop - o.scrollSpeed; } if ( ( this.overflowOffset.left + this.scrollParent[ 0 ].offsetWidth ) - event.pageX < o.scrollSensitivity ) { - scrolled.left = this.scrollParent[ 0 ].scrollLeft; - this.scrollParent[ 0 ].scrollLeft = scroll.left + o.scrollSpeed; - scrolled.left -= this.scrollParent[ 0 ].scrollLeft; + this.scrollParent[ 0 ].scrollLeft = scrolled = + this.scrollParent[ 0 ].scrollLeft + o.scrollSpeed; } else if ( event.pageX - this.overflowOffset.left < o.scrollSensitivity ) { - scrolled.left = this.scrollParent[ 0 ].scrollLeft; - this.scrollParent[ 0 ].scrollLeft = scrolled.left - o.scrollSpeed; - scrolled.left = -this.scrollParent[ 0 ].scrollLeft; + this.scrollParent[ 0 ].scrollLeft = scrolled = + this.scrollParent[ 0 ].scrollLeft - o.scrollSpeed; } } else { if ( event.pageY - this.document.scrollTop() < o.scrollSensitivity ) { - scrolled.top = this.document.scrollTop(); - this.document.scrollTop( scrolled.top - o.scrollSpeed ); - scrolled.top += -this.document.scrollTop(); + scrolled = this.document.scrollTop( this.document.scrollTop() - o.scrollSpeed ); } else if ( this.window.height() - ( event.pageY - this.document.scrollTop() ) < o.scrollSensitivity ) { - scrolled.top = this.document.scrollTop(); - this.document.scrollTop( scrolled.top + o.scrollSpeed ); - scrolled.top -= this.document.scrollTop(); + scrolled = this.document.scrollTop( this.document.scrollTop() + o.scrollSpeed ); } if ( event.pageX - this.document.scrollLeft() < o.scrollSensitivity ) { - scrolled.left = this.document.scrollLeft(); - this.document.scrollLeft( scrolled.left - o.scrollSpeed ); - scrolled.left += -this.document.scrollLeft(); + scrolled = this.document.scrollLeft( + this.document.scrollLeft() - o.scrollSpeed + ); } else if ( this.window.width() - ( event.pageX - this.document.scrollLeft() ) < o.scrollSensitivity ) { - scrolled.left = this.document.scrollLeft(); - this.document.scrollLeft( scrolled.left + o.scrollSpeed ); - scrolled.left -= this.document.scrollLeft(); + scrolled = this.document.scrollLeft( + this.document.scrollLeft() + o.scrollSpeed + ); } } - return scrolled === false || - ( ( scrolled.left === 0 ) && ( scrolled.top === 0 ) ) ? false : scrolled; + return scrolled; + }, + + _refreshItemPositions: function() { + var i, item, t, p; + + for ( i = this.items.length - 1; i >= 0; i-- ) { + item = this.items[ i ]; + + t = this.options.toleranceElement ? + $( this.options.toleranceElement, item.item ) : + item.item; + + p = t.offset(); + item.left = p.left; + item.top = p.top; + } }, _mouseDrag: function( event ) { var i, item, itemElement, intersection, - o = this.options, - scrolled = false; + o = this.options; //Compute the helpers position this.position = this._generatePosition( event ); @@ -433,18 +439,10 @@ return $.widget( "ui.sortable", $.ui.mouse, { //Do scrolling if ( o.scroll ) { - scrolled = this._scroll( event ); - if ( scrolled !== false ) { - - //Update all absolute positions used in position checks - this.positionAbs.top -= scrolled.top; - this.positionAbs.left -= scrolled.left; - this.lastPositionAbs.top -= scrolled.top; - this.lastPositionAbs.left -= scrolled.left; - for ( i = this.items.length - 1; i >= 0; i-- ) { - this.items[ i ].top -= scrolled.top; - this.items[ i ].left -= scrolled.left; - } + if ( this._scroll( event ) !== false ) { + + //Update item positions used in position checks + this._refreshItemPositions(); if ( $.ui.ddmanager && !o.dropBehaviour ) { $.ui.ddmanager.prepareOffsets( this, event ); @@ -452,6 +450,11 @@ return $.widget( "ui.sortable", $.ui.mouse, { } } + this.dragDirection = { + vertical: this._getDragVerticalDirection(), + horizontal: this._getDragHorizontalDirection() + }; + //Rearrange for ( i = this.items.length - 1; i >= 0; i-- ) { @@ -704,8 +707,8 @@ return $.widget( "ui.sortable", $.ui.mouse, { return false; } - verticalDirection = this._getDragVerticalDirection(); - horizontalDirection = this._getDragHorizontalDirection(); + verticalDirection = this.dragDirection.vertical; + horizontalDirection = this.dragDirection.horizontal; return this.floating ? ( ( horizontalDirection === "right" || verticalDirection === "down" ) ? 2 : 1 ) @@ -719,8 +722,8 @@ return $.widget( "ui.sortable", $.ui.mouse, { 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(); + verticalDirection = this.dragDirection.vertical, + horizontalDirection = this.dragDirection.horizontal; if ( this.floating && horizontalDirection ) { return ( ( horizontalDirection === "right" && isOverRightHalf ) || @@ -869,12 +872,6 @@ return $.widget( "ui.sortable", $.ui.mouse, { this.options.axis === "x" || this._isFloating( this.items[ 0 ].item ) : false; - //This has to be redone because due to the item being moved out/into the offsetParent, - // the offsetParent's position will change - if ( this.offsetParent && this.helper ) { - this.offset.parent = this._getParentOffset(); - } - var i, item, t, p; for ( i = this.items.length - 1; i >= 0; i-- ) { From d76014ec03f4aabe63cf91e2d942364e32a6295c Mon Sep 17 00:00:00 2001 From: "A. Wells" Date: Mon, 20 Feb 2017 19:50:23 -0500 Subject: [PATCH 12/12] Update sortable.js * Worked refreshItemPositions function into existing refreshPosition function --- ui/widgets/sortable.js | 44 +++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/ui/widgets/sortable.js b/ui/widgets/sortable.js index f21cf396a68..78fad26b9b4 100644 --- a/ui/widgets/sortable.js +++ b/ui/widgets/sortable.js @@ -400,22 +400,6 @@ return $.widget( "ui.sortable", $.ui.mouse, { return scrolled; }, - _refreshItemPositions: function() { - var i, item, t, p; - - for ( i = this.items.length - 1; i >= 0; i-- ) { - item = this.items[ i ]; - - t = this.options.toleranceElement ? - $( this.options.toleranceElement, item.item ) : - item.item; - - p = t.offset(); - item.left = p.left; - item.top = p.top; - } - }, - _mouseDrag: function( event ) { var i, item, itemElement, intersection, o = this.options; @@ -435,14 +419,14 @@ return $.widget( "ui.sortable", $.ui.mouse, { //Post events to containers this._contactContainers( event ); - if ( this.innermostContainer ) { + if ( this.innermostContainer !== null ) { //Do scrolling if ( o.scroll ) { if ( this._scroll( event ) !== false ) { //Update item positions used in position checks - this._refreshItemPositions(); + this._refreshItemPositions( true ); if ( $.ui.ddmanager && !o.dropBehaviour ) { $.ui.ddmanager.prepareOffsets( this, event ); @@ -865,20 +849,14 @@ return $.widget( "ui.sortable", $.ui.mouse, { }, - refreshPositions: function( fast ) { - - // Determine whether items are being displayed horizontally - this.floating = this.items.length ? - this.options.axis === "x" || this._isFloating( this.items[ 0 ].item ) : - false; - + _refreshItemPositions: function( fast ) { var i, item, t, p; for ( i = this.items.length - 1; i >= 0; i-- ) { item = this.items[ i ]; //We ignore calculating positions of all connected containers when we're not over them - if ( item.instance !== this.currentContainer && this.currentContainer && + if ( this.currentContainer && item.instance !== this.currentContainer && item.item[ 0 ] !== this.currentItem[ 0 ] ) { continue; } @@ -896,6 +874,20 @@ return $.widget( "ui.sortable", $.ui.mouse, { item.left = p.left; item.top = p.top; } + }, + + refreshPositions: function( fast ) { + + // Determine whether items are being displayed horizontally + this.floating = this.items.length ? + this.options.axis === "x" || this._isFloating( this.items[ 0 ].item ) : + false; + + if ( this.innermostContainer !== null ) { + this._refreshItemPositions( fast ); + } + + var i, p; if ( this.options.custom && this.options.custom.refreshContainers ) { this.options.custom.refreshContainers.call( this );