Skip to content

Commit 452436a

Browse files
committed
improvements to completed()
1 parent 7742067 commit 452436a

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

Sortable.js

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,18 +1141,30 @@
11411141
return;
11421142
}
11431143

1144-
// Return invocation when no further action is needed in another sortable
1145-
function completed() {
1146-
if (activeSortable) {
1147-
// Set ghost class to new sortable's ghost class
1148-
_toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : activeSortable.options.ghostClass, false);
1149-
_toggleClass(dragEl, options.ghostClass, true);
1150-
}
1144+
// Return invocation when dragEl is inserted (or completed)
1145+
function completed(insertion) {
1146+
if (insertion) {
1147+
if (isOwner) {
1148+
activeSortable._hideClone();
1149+
} else {
1150+
activeSortable._showClone(_this);
1151+
}
11511152

1152-
if (putSortable !== _this && _this !== Sortable.active) {
1153-
putSortable = _this;
1154-
} else if (_this === Sortable.active) {
1155-
putSortable = null;
1153+
if (activeSortable) {
1154+
// Set ghost class to new sortable's ghost class
1155+
_toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : activeSortable.options.ghostClass, false);
1156+
_toggleClass(dragEl, options.ghostClass, true);
1157+
}
1158+
1159+
if (putSortable !== _this && _this !== Sortable.active) {
1160+
putSortable = _this;
1161+
} else if (_this === Sortable.active) {
1162+
putSortable = null;
1163+
}
1164+
1165+
// Animation
1166+
dragRect && _this._animate(dragRect, dragEl);
1167+
target && targetRect && _this._animate(targetRect, target);
11561168
}
11571169

11581170

@@ -1188,7 +1200,7 @@
11881200

11891201
// target is dragEl or target is animated
11901202
if (!!_closest(evt.target, null, dragEl, true) || target.animated) {
1191-
return completed();
1203+
return completed(false);
11921204
}
11931205

11941206
if (target !== dragEl) {
@@ -1221,7 +1233,7 @@
12211233
rootEl.appendChild(dragEl);
12221234
}
12231235

1224-
return completed();
1236+
return completed(true);
12251237
}
12261238

12271239
var elLastChild = _lastChild(el);
@@ -1248,9 +1260,7 @@
12481260
realDragElRect = null;
12491261

12501262
changed();
1251-
this._animate(dragRect, dragEl);
1252-
target && this._animate(targetRect, target);
1253-
return completed();
1263+
return completed(true);
12541264
}
12551265
}
12561266
else if (target && target !== dragEl && target.parentNode === el) {
@@ -1292,10 +1302,10 @@
12921302
lastMode = 'swap';
12931303
} else {
12941304
// Insert at position
1295-
direction = _getInsertDirection(target, options);
1305+
direction = _getInsertDirection(target);
12961306
lastMode = 'insert';
12971307
}
1298-
if (direction === 0) return completed();
1308+
if (direction === 0) return completed(false);
12991309

13001310
realDragElRect = null;
13011311
lastTarget = target;
@@ -1344,15 +1354,12 @@
13441354
}
13451355
changed();
13461356

1347-
!differentLevel && this._animate(targetRect, target);
1348-
this._animate(dragRect, dragEl);
1349-
1350-
return completed();
1357+
return completed(true);
13511358
}
13521359
}
13531360

13541361
if (el.contains(dragEl)) {
1355-
return completed();
1362+
return completed(false);
13561363
}
13571364
}
13581365

@@ -2063,7 +2070,7 @@
20632070
mouseOnAxis > targetS1 + (targetLength * (1 - swapThreshold) / 2) &&
20642071
mouseOnAxis < targetS2 - (targetLength * (1 - swapThreshold) / 2)
20652072
) {
2066-
return ((mouseOnAxis > targetS1 + targetLength / 2) ? -1 : 1);
2073+
return _getInsertDirection(target);
20672074
}
20682075
}
20692076
}
@@ -2088,12 +2095,11 @@
20882095
* Gets the direction dragEl must be swapped relative to target in order to make it
20892096
* seem that dragEl has been "inserted" into that element's position
20902097
* @param {HTMLElement} target The target whose position dragEl is being inserted at
2091-
* @param {Object} options options of the parent sortable
20922098
* @return {Number} Direction dragEl must be swapped
20932099
*/
2094-
function _getInsertDirection(target, options) {
2095-
var dragElIndex = _index(dragEl, options.draggable),
2096-
targetIndex = _index(target, options.draggable);
2100+
function _getInsertDirection(target) {
2101+
var dragElIndex = _index(dragEl),
2102+
targetIndex = _index(target);
20972103

20982104
if (dragElIndex < targetIndex) {
20992105
return 1;

0 commit comments

Comments
 (0)