Skip to content

Commit 9262d9a

Browse files
author
Alain Dumesny
authored
Merge pull request #1209 from adumesny/develop
destroy drag&drop when removing node(s)
2 parents 613cd95 + 4e5dddc commit 9262d9a

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

demo/float.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ <h1>Float grid demo</h1>
2424
<div class="grid-stack"></div>
2525
</div>
2626

27-
2827
<script type="text/javascript">
2928
var grid = GridStack.init({float: true});
3029

30+
grid.on('added removed change', function(e, items) {
31+
var str = '';
32+
items.forEach(function(item) { str += ' (x,y)=' + item.x + ',' + item.y; });
33+
console.log(e.type + ' ' + items.length + ' items:' + str );
34+
});
35+
3136
var items = [
3237
{x: 2, y: 1, width: 1, height: 1},
3338
{x: 2, y: 3, width: 3, height: 1},

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Change log
3535
## 1.1.0-dev (upcoming)
3636

3737
- fix [1187](https://github.com/gridstack/gridstack.js/issues/1187) IE support for `CustomEvent` polyfill - thanks [@phil-blais](https://github.com/phil-blais)
38+
- fix [1204](https://github.com/gridstack/gridstack.js/issues/1204) destroy drag&drop when removing node(s) instead of just disabling it.
3839
- include SASS source files to npm package again [1193](https://github.com/gridstack/gridstack.js/pull/1193)
3940

4041
## 1.1.0 (2020-02-29)

src/gridstack.jQueryUI.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
JQueryUIGridStackDragDropPlugin.prototype.resizable = function(el, opts) {
3333
el = $(el);
34-
if (opts === 'disable' || opts === 'enable') {
34+
if (opts === 'disable' || opts === 'enable' || opts === 'destroy') {
3535
el.resizable(opts);
3636
} else if (opts === 'option') {
3737
var key = arguments[2];
@@ -53,7 +53,7 @@
5353

5454
JQueryUIGridStackDragDropPlugin.prototype.draggable = function(el, opts) {
5555
el = $(el);
56-
if (opts === 'disable' || opts === 'enable') {
56+
if (opts === 'disable' || opts === 'enable' || opts === 'destroy') {
5757
el.draggable(opts);
5858
} else {
5959
el.draggable($.extend({}, this.grid.opts.draggable, {

src/gridstack.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,34 +1505,38 @@
15051505
};
15061506

15071507
GridStack.prototype.removeWidget = function(el, detachNode) {
1508-
detachNode = (detachNode === undefined ? true : detachNode);
15091508
el = $(el);
15101509
var node = el.data('_gridstack_node');
15111510
// For Meteor support: https://github.com/gridstack/gridstack.js/pull/272
15121511
if (!node) {
15131512
node = this.engine.getNodeDataByDOMEl(el.get(0));
15141513
}
1515-
1514+
// remove our DOM data (circular link) and drag&drop permanently
15161515
el.removeData('_gridstack_node');
1516+
this.dd.draggable(el, 'destroy').resizable(el, 'destroy');
1517+
15171518
this.engine.removeNode(node, detachNode);
15181519
this._triggerRemoveEvent();
15191520
this._triggerChangeEvent(true); // trigger any other changes
15201521
};
15211522

15221523
GridStack.prototype.removeAll = function(detachNode) {
1523-
if (detachNode !== false) {
1524-
// remove our data structure before list gets emptied and DOM elements stay behind
1525-
this.engine.nodes.forEach(function(node) { $(node.el).removeData('_gridstack_node') });
1526-
}
1524+
// always remove our DOM data (circular link) before list gets emptied and drag&drop permanently
1525+
this.engine.nodes.forEach(function(node) {
1526+
var el = $(node.el);
1527+
el.removeData('_gridstack_node');
1528+
this.dd.draggable(el, 'destroy').resizable(el, 'destroy');
1529+
}, this);
1530+
15271531
this.engine.removeAll(detachNode);
15281532
this._triggerRemoveEvent();
15291533
};
15301534

15311535
GridStack.prototype.destroy = function(detachGrid) {
15321536
$(window).off('resize', this.onResizeHandler);
1533-
this.disable();
1534-
if (detachGrid !== undefined && !detachGrid) {
1537+
if (detachGrid === false) {
15351538
this.removeAll(false);
1539+
this.$el.removeClass(this.opts._class);
15361540
delete this.$el.get(0).gridstack;
15371541
} else {
15381542
this.$el.remove();

0 commit comments

Comments
 (0)