Skip to content

Commit d1e0182

Browse files
authored
Merge pull request #1467 from adumesny/h5
h5: fixed dragging from multiple grid to trash
2 parents 5bd8d2f + cfb791c commit d1e0182

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/gridstack.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,22 +1592,24 @@ export class GridStack {
15921592
if (!this.opts.staticGrid && typeof this.opts.removable === 'string') {
15931593
let trashZone = document.querySelector(this.opts.removable) as HTMLElement;
15941594
if (!trashZone) return this;
1595+
// only register ONE dropover/dropout callback for the 'trash', and it will
1596+
// update the passed in item and parent grid because the 'trash' is a shared resource anyway,
1597+
// and Native DD only has 1 event CB (having a list and technically a per grid removableOptions complicates things greatly)
15951598
if (!dd.isDroppable(trashZone)) {
1596-
dd.droppable(trashZone, this.opts.removableOptions);
1599+
dd.droppable(trashZone, this.opts.removableOptions)
1600+
.on(trashZone, 'dropover', function(event, el) { // don't use => notation to avoid using 'this' as grid by mistake...
1601+
let node = el.gridstackNode;
1602+
if (!node || !node.grid) return;
1603+
el.dataset.inTrashZone = 'true';
1604+
node.grid._setupRemovingTimeout(el);
1605+
})
1606+
.on(trashZone, 'dropout', function(event, el) { // same
1607+
let node = el.gridstackNode;
1608+
if (!node || !node.grid) return;
1609+
delete el.dataset.inTrashZone;
1610+
node.grid._clearRemovingTimeout(el);
1611+
});
15971612
}
1598-
dd
1599-
.on(trashZone, 'dropover', (event, el) => {
1600-
let node = el.gridstackNode;
1601-
if (!node || node.grid !== this) return;
1602-
el.dataset.inTrashZone = 'true';
1603-
this._setupRemovingTimeout(el);
1604-
})
1605-
.on(trashZone, 'dropout', (event, el) => {
1606-
let node = el.gridstackNode;
1607-
if (!node || node.grid !== this) return;
1608-
delete el.dataset.inTrashZone;
1609-
this._clearRemovingTimeout(el);
1610-
});
16111613
}
16121614
return this;
16131615
}

0 commit comments

Comments
 (0)