|
877 | 877 | .on(trashZone, 'dropover', function(event, ui) { |
878 | 878 | var el = $(ui.draggable); |
879 | 879 | var node = el.data('_gridstack_node'); |
880 | | - if (node._grid !== self) { |
| 880 | + if (!node || node._grid !== self) { |
881 | 881 | return; |
882 | 882 | } |
883 | 883 | el.data('inTrashZone', true); |
|
886 | 886 | .on(trashZone, 'dropout', function(event, ui) { |
887 | 887 | var el = $(ui.draggable); |
888 | 888 | var node = el.data('_gridstack_node'); |
889 | | - if (node._grid !== self) { |
| 889 | + if (!node || node._grid !== self) { |
890 | 890 | return; |
891 | 891 | } |
892 | 892 | el.data('inTrashZone', false); |
|
1028 | 1028 | } |
1029 | 1029 | }; |
1030 | 1030 |
|
1031 | | - GridStack.prototype._triggerChangeEvent = function(forceTrigger) { |
| 1031 | + GridStack.prototype._triggerChangeEvent = function(/*forceTrigger*/) { |
1032 | 1032 | if (this.grid._batchMode) { return; } |
1033 | 1033 | // TODO: compare original X,Y,W,H (or entire node?) instead as _dirty can be a temporary state |
1034 | 1034 | var elements = this.grid.getDirtyNodes(); |
1035 | | - var hasChanges = false; |
1036 | | - |
1037 | | - var eventParams = []; // eventParams[0] has to be the list of items... |
1038 | 1035 | if (elements && elements.length) { |
1039 | | - eventParams[0] = elements; |
1040 | | - hasChanges = true; |
1041 | | - } |
1042 | | - |
1043 | | - if (hasChanges || forceTrigger === true) { |
1044 | | - this.container.trigger('change', eventParams); |
| 1036 | + this.container.trigger('change', [elements]); |
1045 | 1037 | this.grid.cleanNodes(); // clear dirty flags now that we called |
1046 | 1038 | } |
1047 | 1039 | }; |
1048 | 1040 |
|
1049 | 1041 | GridStack.prototype._triggerAddEvent = function() { |
1050 | 1042 | if (this.grid._batchMode) { return; } |
1051 | 1043 | if (this.grid._addedNodes && this.grid._addedNodes.length > 0) { |
1052 | | - this.container.trigger('added', [this.grid._addedNodes.map(Utils.clone)]); |
| 1044 | + this.container.trigger('added', [this.grid._addedNodes]); |
1053 | 1045 | this.grid._addedNodes = []; |
1054 | 1046 | } |
1055 | 1047 | }; |
1056 | 1048 |
|
1057 | 1049 | GridStack.prototype._triggerRemoveEvent = function() { |
1058 | 1050 | if (this.grid._batchMode) { return; } |
1059 | 1051 | if (this.grid._removedNodes && this.grid._removedNodes.length > 0) { |
1060 | | - this.container.trigger('removed', [this.grid._removedNodes.map(Utils.clone)]); |
| 1052 | + this.container.trigger('removed', [this.grid._removedNodes]); |
1061 | 1053 | this.grid._removedNodes = []; |
1062 | 1054 | } |
1063 | 1055 | }; |
|
1319 | 1311 | return; |
1320 | 1312 | } |
1321 | 1313 |
|
1322 | | - var forceNotify = false; |
| 1314 | + // var forceNotify = false; what is the point of calling 'change' event with no data, when the 'removed' event is already called ? |
1323 | 1315 | self.placeholder.detach(); |
1324 | 1316 | node.el = o; |
1325 | 1317 | self.placeholder.hide(); |
1326 | 1318 |
|
1327 | 1319 | if (node._isAboutToRemove) { |
1328 | | - forceNotify = true; |
| 1320 | + // forceNotify = true; |
1329 | 1321 | var gridToNotify = el.data('_gridstack_node')._grid; |
1330 | 1322 | gridToNotify._triggerRemoveEvent(); |
1331 | 1323 | el.removeData('_gridstack_node'); |
|
1353 | 1345 | } |
1354 | 1346 | } |
1355 | 1347 | self._updateContainerHeight(); |
1356 | | - self._triggerChangeEvent(forceNotify); |
| 1348 | + self._triggerChangeEvent(/*forceNotify*/); |
1357 | 1349 |
|
1358 | 1350 | self.grid.endUpdate(); |
1359 | 1351 |
|
|
1770 | 1762 | GridStack.prototype.commit = function() { |
1771 | 1763 | this.grid.commit(); |
1772 | 1764 | this._updateContainerHeight(); |
1773 | | - this._triggerAddEvent(); |
1774 | 1765 | this._triggerRemoveEvent(); |
| 1766 | + this._triggerAddEvent(); |
1775 | 1767 | this._triggerChangeEvent(); |
1776 | 1768 | }; |
1777 | 1769 |
|
|
0 commit comments