|
460 | 460 | GridStackEngine.prototype._notify = function() {
|
461 | 461 | if (this._batchMode) { return; }
|
462 | 462 | var args = Array.prototype.slice.call(arguments, 0);
|
463 |
| - args[0] = args[0] === undefined ? [] : [args[0]]; |
464 |
| - args[1] = args[1] === undefined ? true : args[1]; |
| 463 | + args[0] = (args[0] === undefined ? [] : (Array.isArray(args[0]) ? args[0] : [args[0]]) ); |
| 464 | + args[1] = (args[1] === undefined ? true : args[1]); |
465 | 465 | var dirtyNodes = args[0].concat(this.getDirtyNodes());
|
466 | 466 | this.onchange(dirtyNodes, args[1]);
|
467 | 467 | };
|
|
516 | 516 | };
|
517 | 517 |
|
518 | 518 | GridStackEngine.prototype.removeNode = function(node, detachNode) {
|
519 |
| - detachNode = detachNode === undefined ? true : detachNode; |
520 |
| - this._removedNodes.push(Utils.clone(node)); |
| 519 | + detachNode = (detachNode === undefined ? true : detachNode); |
| 520 | + this._removedNodes.push(node); |
521 | 521 | node._id = null;
|
522 | 522 | this.nodes = Utils.without(this.nodes, node);
|
523 | 523 | this._packNodes();
|
524 | 524 | this._notify(node, detachNode);
|
525 | 525 | };
|
526 | 526 |
|
| 527 | + GridStackEngine.prototype.removeAll = function(detachNode) { |
| 528 | + if (this.nodes.length === 0) { return; } |
| 529 | + detachNode = (detachNode === undefined ? true : detachNode); |
| 530 | + this.nodes.forEach(function(n) { n._id = null; }); // hint that node is being removed |
| 531 | + this._removedNodes = this.nodes; |
| 532 | + this.nodes = []; |
| 533 | + this._notify(this._removedNodes, detachNode); |
| 534 | + }; |
| 535 | + |
527 | 536 | GridStackEngine.prototype.canMoveNode = function(node, x, y, width, height) {
|
528 | 537 | if (!this.isNodeChangedPosition(node, x, y, width, height)) {
|
529 | 538 | return false;
|
|
764 | 773 | this._initStyles();
|
765 | 774 |
|
766 | 775 | this.grid = new GridStackEngine(this.opts.column, function(nodes, detachNode) {
|
767 |
| - detachNode = detachNode === undefined ? true : detachNode; |
| 776 | + detachNode = (detachNode === undefined ? true : detachNode); |
768 | 777 | var maxHeight = 0;
|
769 | 778 | this.nodes.forEach(function(n) {
|
770 | 779 | maxHeight = Math.max(maxHeight, n.y + n.height);
|
|
1475 | 1484 | };
|
1476 | 1485 |
|
1477 | 1486 | GridStack.prototype.removeWidget = function(el, detachNode) {
|
1478 |
| - detachNode = detachNode === undefined ? true : detachNode; |
| 1487 | + detachNode = (detachNode === undefined ? true : detachNode); |
1479 | 1488 | el = $(el);
|
1480 | 1489 | var node = el.data('_gridstack_node');
|
1481 |
| - |
1482 | 1490 | // For Meteor support: https://github.com/gridstack/gridstack.js/pull/272
|
1483 | 1491 | if (!node) {
|
1484 | 1492 | node = this.grid.getNodeDataByDOMEl(el);
|
1485 | 1493 | }
|
1486 | 1494 |
|
1487 |
| - this.grid.removeNode(node, detachNode); |
1488 | 1495 | el.removeData('_gridstack_node');
|
1489 |
| - this._updateContainerHeight(); |
1490 |
| - if (detachNode) { |
1491 |
| - el.remove(); |
1492 |
| - } |
| 1496 | + this.grid.removeNode(node, detachNode); |
1493 | 1497 | this._triggerRemoveEvent();
|
1494 | 1498 | // this._triggerChangeEvent(true); already have removeEvent
|
1495 | 1499 | };
|
1496 | 1500 |
|
1497 | 1501 | GridStack.prototype.removeAll = function(detachNode) {
|
| 1502 | + // remove our data structure before list gets emptied (in case detachNode is false) |
1498 | 1503 | this.grid.nodes.forEach(function(node) {
|
1499 |
| - this.removeWidget(node.el, detachNode); |
1500 |
| - }, this); |
1501 |
| - this.grid.nodes = []; |
1502 |
| - this._updateContainerHeight(); |
| 1504 | + node.el.removeData('_gridstack_node'); |
| 1505 | + }); |
| 1506 | + this.grid.removeAll(detachNode); |
| 1507 | + this._triggerRemoveEvent(); |
1503 | 1508 | };
|
1504 | 1509 |
|
1505 | 1510 | GridStack.prototype.destroy = function(detachGrid) {
|
|
1761 | 1766 |
|
1762 | 1767 | GridStack.prototype.commit = function() {
|
1763 | 1768 | this.grid.commit();
|
1764 |
| - this._updateContainerHeight(); |
1765 | 1769 | this._triggerRemoveEvent();
|
1766 | 1770 | this._triggerAddEvent();
|
1767 | 1771 | this._triggerChangeEvent();
|
|
0 commit comments