Skip to content

Commit a04a247

Browse files
authored
Merge pull request #502 from radiolips/bugfix/notify-fix
Bugfix/notify fix - #411
2 parents 1079cd4 + 34213e6 commit a04a247

File tree

6 files changed

+42
-33
lines changed

6 files changed

+42
-33
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,9 @@ Changes
476476

477477
#### v0.2.6-dev (Development version)
478478

479-
- update requirements to the latest versions
480-
- fix jQuery `size()`
479+
- update requirements to the latest versions of jQuery and jquery-ui.
480+
- fix jQuery `size()` ([#486](https://github.com/troolee/gridstack.js/issues/486)).
481+
- update _notify to allow detach ([#411](https://github.com/troolee/gridstack.js/issues/411)).
481482

482483
#### v0.2.5 (2016-03-02)
483484

dist/gridstack.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,14 @@
281281
};
282282

283283
GridStackEngine.prototype._notify = function() {
284+
var args = Array.prototype.slice.call(arguments, 0);
285+
args[0] = typeof args[0] === 'undefined' ? [] : [args[0]];
286+
args[1] = typeof args[1] === 'undefined' ? true : args[1];
284287
if (this._updateCounter) {
285288
return;
286289
}
287-
var deletedNodes = Array.prototype.slice.call(arguments, 0);
288-
deletedNodes = deletedNodes.concat(this.getDirtyNodes());
289-
this.onchange(deletedNodes);
290+
var deletedNodes = args[0].concat(this.getDirtyNodes());
291+
this.onchange(deletedNodes, args[1]);
290292
};
291293

292294
GridStackEngine.prototype.cleanNodes = function() {
@@ -345,9 +347,7 @@
345347
node._id = null;
346348
this.nodes = _.without(this.nodes, node);
347349
this._packNodes();
348-
if (detachNode) {
349-
this._notify(node);
350-
}
350+
this._notify(node, detachNode);
351351
};
352352

353353
GridStackEngine.prototype.canMoveNode = function(node, x, y, width, height) {
@@ -578,10 +578,11 @@
578578

579579
this._initStyles();
580580

581-
this.grid = new GridStackEngine(this.opts.width, function(nodes) {
581+
this.grid = new GridStackEngine(this.opts.width, function(nodes, detachNode) {
582+
detachNode = typeof detachNode === 'undefined' ? true : detachNode;
582583
var maxHeight = 0;
583584
_.each(nodes, function(n) {
584-
if (n._id === null) {
585+
if (detachNode && n._id === null) {
585586
if (n.el) {
586587
n.el.remove();
587588
}

dist/gridstack.min.js

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gridstack.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/gridstack-engine-spec.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,31 @@ describe('gridstack engine', function() {
176176
expect(spy.callback).toHaveBeenCalledWith([
177177
engine.nodes[0],
178178
engine.nodes[1]
179-
]);
179+
], true);
180180
});
181181

182-
it('should by called with extra passed dirty nodes', function() {
183-
var n1 = {idx: -1},
184-
n2 = {idx: -2};
182+
it('should by called with extra passed node to be removed', function() {
183+
var n1 = {idx: -1};
185184

186-
engine._notify(n1, n2);
185+
engine._notify(n1);
187186

188187
expect(spy.callback).toHaveBeenCalledWith([
189188
n1,
190-
n2,
191189
engine.nodes[0],
192190
engine.nodes[1]
193-
]);
191+
], true);
192+
});
193+
194+
it('should by called with extra passed node to be removed and should maintain false parameter', function() {
195+
var n1 = {idx: -1};
196+
197+
engine._notify(n1, false);
198+
199+
expect(spy.callback).toHaveBeenCalledWith([
200+
n1,
201+
engine.nodes[0],
202+
engine.nodes[1]
203+
], false);
194204
});
195205
});
196206

src/gridstack.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,14 @@
281281
};
282282

283283
GridStackEngine.prototype._notify = function() {
284+
var args = Array.prototype.slice.call(arguments, 0);
285+
args[0] = typeof args[0] === 'undefined' ? [] : [args[0]];
286+
args[1] = typeof args[1] === 'undefined' ? true : args[1];
284287
if (this._updateCounter) {
285288
return;
286289
}
287-
var deletedNodes = Array.prototype.slice.call(arguments, 0);
288-
deletedNodes = deletedNodes.concat(this.getDirtyNodes());
289-
this.onchange(deletedNodes);
290+
var deletedNodes = args[0].concat(this.getDirtyNodes());
291+
this.onchange(deletedNodes, args[1]);
290292
};
291293

292294
GridStackEngine.prototype.cleanNodes = function() {
@@ -345,9 +347,7 @@
345347
node._id = null;
346348
this.nodes = _.without(this.nodes, node);
347349
this._packNodes();
348-
if (detachNode) {
349-
this._notify(node);
350-
}
350+
this._notify(node, detachNode);
351351
};
352352

353353
GridStackEngine.prototype.canMoveNode = function(node, x, y, width, height) {
@@ -578,10 +578,11 @@
578578

579579
this._initStyles();
580580

581-
this.grid = new GridStackEngine(this.opts.width, function(nodes) {
581+
this.grid = new GridStackEngine(this.opts.width, function(nodes, detachNode) {
582+
detachNode = typeof detachNode === 'undefined' ? true : detachNode;
582583
var maxHeight = 0;
583584
_.each(nodes, function(n) {
584-
if (n._id === null) {
585+
if (detachNode && n._id === null) {
585586
if (n.el) {
586587
n.el.remove();
587588
}

0 commit comments

Comments
 (0)