From 576b5ae3f0461b048d8ff9463509b860ffa8b194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20S=C3=A1nchez-Mar=C3=ADn?= Date: Thu, 16 Apr 2015 19:12:00 +0200 Subject: [PATCH] fix(gridster): ensure coords instances are destroyed on widgets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …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. --- src/jquery.gridster.js | 6 ++++++ test/index.js | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/jquery.gridster.js b/src/jquery.gridster.js index 79bd94151..e093b7d56 100755 --- a/src/jquery.gridster.js +++ b/src/jquery.gridster.js @@ -747,6 +747,7 @@ $el[this.options.hide_method]({ always: $.proxy(function() { + $el.coords().destroy(); $el.remove(); if (!silent) { @@ -3123,6 +3124,11 @@ */ fn.destroy = function(remove) { this.$el.removeData('gridster'); + this.$widgets.each($.proxy(function(i, el){ + $(el).coords().destroy(); + }, this)); + this.gridmap = null; + this.faux_grid = null; // remove bound callback on window resize $(window).unbind('.gridster'); diff --git a/test/index.js b/test/index.js index 90bf244e2..b0082fa93 100644 --- a/test/index.js +++ b/test/index.js @@ -328,8 +328,8 @@ describe('gridster.js', function() { it('should clean gridmap array', function() { this.gridster.destroy(); - expect(this.gridster.gridmap).to.be.empty; - expect(this.gridster.faux_grid).to.be.empty; + expect(this.gridster.gridmap).to.not.have.length; + expect(this.gridster.faux_grid).to.not.have.length; }); });