diff --git a/plugins/OnSpill/OnSpill.js b/plugins/OnSpill/OnSpill.js index 78efc19b153958e0c8ada5a5a74cb8c1bb38c199..7c36af97ec44ff1a29b6c347d6fb7eae940d9a8b 100644 --- a/plugins/OnSpill/OnSpill.js +++ b/plugins/OnSpill/OnSpill.js @@ -17,7 +17,7 @@ const drop = function({ if (toSortable && !toSortable.el.contains(target)) { dispatchSortableEvent('spill'); - this.onSpill(dragEl); + this.onSpill({ dragEl, putSortable }); } }; @@ -28,8 +28,11 @@ Revert.prototype = { dragStart({ oldDraggableIndex }) { this.startIndex = oldDraggableIndex; }, - onSpill(dragEl) { + onSpill({ dragEl, putSortable }) { this.sortable.captureAnimationState(); + if (putSortable) { + putSortable.captureAnimationState(); + } let nextSibling = getChild(this.sortable.el, this.startIndex, this.sortable.options); if (nextSibling) { @@ -38,6 +41,9 @@ Revert.prototype = { this.sortable.el.appendChild(dragEl); } this.sortable.animateAll(); + if (putSortable) { + putSortable.animateAll(); + } }, drop }; @@ -50,10 +56,11 @@ Object.assign(Revert, { function Remove() {} Remove.prototype = { - onSpill(dragEl) { - this.sortable.captureAnimationState(); + onSpill({ dragEl, putSortable }) { + const parentSortable = putSortable || this.sortable; + parentSortable.captureAnimationState(); dragEl.parentNode && dragEl.parentNode.removeChild(dragEl); - this.sortable.animateAll(); + parentSortable.animateAll(); }, drop }; diff --git a/plugins/OnSpill/README.md b/plugins/OnSpill/README.md index 088d0c6ffb38d8dce2c645ee2e09b140fd6d0f63..d852898bda175b4eefca953e92bf967d28791dfe 100644 --- a/plugins/OnSpill/README.md +++ b/plugins/OnSpill/README.md @@ -28,7 +28,11 @@ This plugin, when enabled, will cause the dragged item to be reverted to it's or ```js new Sortable(el, { - revertOnSpill: false // Enable plugin + revertOnSpill: false, // Enable plugin + // Called when item is spilled + onSpill: function(/**Event*/evt) { + evt.item // The spilled item + } }); ``` @@ -47,6 +51,10 @@ This plugin, when enabled, will cause the dragged item to be removed from the DO ```js new Sortable(el, { - removeOnSpill: false // Enable plugin + removeOnSpill: false, // Enable plugin + // Called when item is spilled + onSpill: function(/**Event*/evt) { + evt.item // The spilled item + } }); ``` diff --git a/src/Sortable.js b/src/Sortable.js index 334e5b8ed50942b43526d5a0b911eab4f270213c..af901a538ce84538929b5f832cb6fb4f65573889 100644 --- a/src/Sortable.js +++ b/src/Sortable.js @@ -1284,6 +1284,8 @@ Sortable.prototype = /** @lends Sortable.prototype */ { evt }); + parentEl = dragEl.parentNode; + // Get again after plugin event newIndex = index(dragEl); newDraggableIndex = index(dragEl, options.draggable);