Skip to content

Commit 1fed4ee

Browse files
committed
Improve OnSpill support with multiple sortables + fix drop events
1 parent 99c8695 commit 1fed4ee

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

plugins/OnSpill/OnSpill.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const drop = function({
1717

1818
if (toSortable && !toSortable.el.contains(target)) {
1919
dispatchSortableEvent('spill');
20-
this.onSpill(dragEl);
20+
this.onSpill({ dragEl, putSortable });
2121
}
2222
};
2323

@@ -28,8 +28,11 @@ Revert.prototype = {
2828
dragStart({ oldDraggableIndex }) {
2929
this.startIndex = oldDraggableIndex;
3030
},
31-
onSpill(dragEl) {
31+
onSpill({ dragEl, putSortable }) {
3232
this.sortable.captureAnimationState();
33+
if (putSortable) {
34+
putSortable.captureAnimationState();
35+
}
3336
let nextSibling = getChild(this.sortable.el, this.startIndex, this.sortable.options);
3437

3538
if (nextSibling) {
@@ -38,6 +41,9 @@ Revert.prototype = {
3841
this.sortable.el.appendChild(dragEl);
3942
}
4043
this.sortable.animateAll();
44+
if (putSortable) {
45+
putSortable.animateAll();
46+
}
4147
},
4248
drop
4349
};
@@ -50,10 +56,11 @@ Object.assign(Revert, {
5056
function Remove() {}
5157

5258
Remove.prototype = {
53-
onSpill(dragEl) {
54-
this.sortable.captureAnimationState();
59+
onSpill({ dragEl, putSortable }) {
60+
const parentSortable = putSortable || this.sortable;
61+
parentSortable.captureAnimationState();
5562
dragEl.parentNode && dragEl.parentNode.removeChild(dragEl);
56-
this.sortable.animateAll();
63+
parentSortable.animateAll();
5764
},
5865
drop
5966
};

plugins/OnSpill/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ This plugin, when enabled, will cause the dragged item to be reverted to it's or
2828

2929
```js
3030
new Sortable(el, {
31-
revertOnSpill: false // Enable plugin
31+
revertOnSpill: false, // Enable plugin
32+
// Called when item is spilled
33+
onSpill: function(/**Event*/evt) {
34+
evt.item // The spilled item
35+
}
3236
});
3337
```
3438

@@ -47,6 +51,10 @@ This plugin, when enabled, will cause the dragged item to be removed from the DO
4751

4852
```js
4953
new Sortable(el, {
50-
removeOnSpill: false // Enable plugin
54+
removeOnSpill: false, // Enable plugin
55+
// Called when item is spilled
56+
onSpill: function(/**Event*/evt) {
57+
evt.item // The spilled item
58+
}
5159
});
5260
```

src/Sortable.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,8 @@ Sortable.prototype = /** @lends Sortable.prototype */ {
12841284
evt
12851285
});
12861286

1287+
parentEl = dragEl.parentNode;
1288+
12871289
// Get again after plugin event
12881290
newIndex = index(dragEl);
12891291
newDraggableIndex = index(dragEl, options.draggable);

0 commit comments

Comments
 (0)