Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sortable Fix-Up #1793

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
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
  • Loading branch information
borgboyone committed Feb 18, 2017
commit 93f77d9eb4343a5ae6fce98f4ee33361b525689f
131 changes: 72 additions & 59 deletions ui/widgets/sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 );
Expand Down Expand Up @@ -1036,6 +1041,8 @@ return $.widget( "ui.sortable", $.ui.mouse, {

}

this.innermostContainer = innermostContainer;

// If no intersecting containers found, return
if ( !innermostContainer ) {
return;
Expand Down Expand Up @@ -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;
}
Expand Down