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.
This commit is contained in:
Javi Sánchez-Marín
2015-04-16 20:26:19 +02:00
parent cda560f4f3
commit 576b5ae3f0
2 changed files with 8 additions and 2 deletions
+6
View File
@@ -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');
+2 -2
View File
@@ -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;
});
});