From db9eaea0d70548a8975b0f761bf770e735832b4e Mon Sep 17 00:00:00 2001 From: radiolips Date: Sat, 16 Nov 2019 15:06:00 -0500 Subject: [PATCH] Fix multi-grid issue Fix moving widgets when using multiple grids. Fixes #1034 --- doc/CHANGES.md | 1 + src/gridstack.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/CHANGES.md b/doc/CHANGES.md index 819323fc4..5bf1d19bc 100644 --- a/doc/CHANGES.md +++ b/doc/CHANGES.md @@ -24,6 +24,7 @@ Change log ## v0.5.2-dev (upcoming changes) +- fix moving widgets when having multiple grids. jquery-ui workaround ([#1043](https://github.com/gridstack/gridstack.js/issues/1043)). - switch to eslint ([#763](https://github.com/gridstack/gridstack.js/issues/763)). - null values to addWidget() exception fix ([#1042](https://github.com/gridstack/gridstack.js/issues/1042)). diff --git a/src/gridstack.js b/src/gridstack.js index 0de044bd8..ac1e06074 100644 --- a/src/gridstack.js +++ b/src/gridstack.js @@ -974,18 +974,24 @@ draggingElement = el; var node = self.grid._prepareNode({width: width, height: height, _added: false, _temporary: true}); + node.isOutOfGrid = true; el.data('_gridstack_node', node); el.data('_gridstack_node_orig', origNode); el.on('drag', onDrag); }) .on(self.container, 'dropout', function(event, ui) { + // jquery-ui bug. Must verify widget is being dropped out + // check node variable that gets set when widget is out of grid var el = $(ui.draggable); if (!el.data('_gridstack_node')) { return; } - el.unbind('drag', onDrag); var node = el.data('_gridstack_node'); + if (!node.isOutOfGrid) { + return; + } + el.unbind('drag', onDrag); node.el = null; self.grid.removeNode(node); self.placeholder.detach(); @@ -996,6 +1002,7 @@ self.placeholder.detach(); var node = $(ui.draggable).data('_gridstack_node'); + node.isOutOfGrid = false; node._grid = self; var el = $(ui.draggable).clone(false); el.data('_gridstack_node', node);