Skip to content

Commit 576b5ae

Browse files
committed
fix(gridster): ensure coords instances are destroyed on widgets
…when removing a widget, or when destroying the gridster instance. Before this change, if you called destroy without `remove` set to true, coords instances was leaking jQuery data objects. Also nullified the gridmap, and faux_grid arrays.
1 parent cda560f commit 576b5ae

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/jquery.gridster.js

+6
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@
747747

748748
$el[this.options.hide_method]({
749749
always: $.proxy(function() {
750+
$el.coords().destroy();
750751
$el.remove();
751752

752753
if (!silent) {
@@ -3123,6 +3124,11 @@
31233124
*/
31243125
fn.destroy = function(remove) {
31253126
this.$el.removeData('gridster');
3127+
this.$widgets.each($.proxy(function(i, el){
3128+
$(el).coords().destroy();
3129+
}, this));
3130+
this.gridmap = null;
3131+
this.faux_grid = null;
31263132

31273133
// remove bound callback on window resize
31283134
$(window).unbind('.gridster');

test/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ describe('gridster.js', function() {
328328

329329
it('should clean gridmap array', function() {
330330
this.gridster.destroy();
331-
expect(this.gridster.gridmap).to.be.empty;
332-
expect(this.gridster.faux_grid).to.be.empty;
331+
expect(this.gridster.gridmap).to.not.have.length;
332+
expect(this.gridster.faux_grid).to.not.have.length;
333333
});
334334
});
335335

0 commit comments

Comments
 (0)