From c35a3cad1d4f410ae56a495cad0e606cd7555cdd Mon Sep 17 00:00:00 2001 From: Zac Spitzer Date: Wed, 22 Jul 2015 11:33:41 +1000 Subject: [PATCH] Add Destroy method - added remove_stylesheet - changed on_resize_hander to allow unbinding - added destroy method --- src/gridstack.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/gridstack.js b/src/gridstack.js index 68326eddf..8d284b638 100644 --- a/src/gridstack.js +++ b/src/gridstack.js @@ -39,7 +39,9 @@ document.getElementsByTagName('head')[0].appendChild(style); return style.sheet; }, - + remove_stylesheet: function(id) { + $("STYLE[data-gs-id=" + id +"]").remove(); + }, insert_css_rule: function(sheet, selector, rules, index) { if (typeof sheet.insertRule === 'function') { sheet.insertRule(selector + '{' + rules + '}', index); @@ -463,7 +465,7 @@ this.grid.get_grid_height() * (this.opts.cell_height + this.opts.vertical_margin) - this.opts.vertical_margin); - var on_resize_handler = function() { + this.on_resize_handler = function() { if (self._is_one_column_mode()) { if (one_column_mode) return; @@ -506,8 +508,8 @@ } }; - $(window).resize(on_resize_handler); - on_resize_handler(); + $(window).resize(this.on_resize_handler); + this.on_resize_handler(); }; GridStack.prototype._init_styles = function() { @@ -732,6 +734,15 @@ this._update_container_height(); }; + GridStack.prototype.destroy = function() { + $(window).off("resize", this.on_resize_handler); + this.disable(); + this.container.remove(); + Utils.remove_stylesheet(this._styles_id); + if (this.grid) + this.grid = null; + }; + GridStack.prototype.resizable = function(el, val) { el = $(el); el.each(function(index, el) {