Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cfb791c

Browse files
committed
h5: fixed dragging from multiple grid to trash
* you can now drag from either grids in two.html to the trash to delete. html5 native D7D only supports sinlge callback, which si fine for all but the drop to erase target, gridstack now sets a single callback and tell that grid to update.
1 parent a40f498 commit cfb791c

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)