Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ac219ab

Browse files
committed
Merge pull request gridstack#189 from zspitzer/master
Add Destroy method
2 parents a738ee8 + c35a3ca commit ac219ab

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/gridstack.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
document.getElementsByTagName('head')[0].appendChild(style);
4040
return style.sheet;
4141
},
42-
42+
remove_stylesheet: function(id) {
43+
$("STYLE[data-gs-id=" + id +"]").remove();
44+
},
4345
insert_css_rule: function(sheet, selector, rules, index) {
4446
if (typeof sheet.insertRule === 'function') {
4547
sheet.insertRule(selector + '{' + rules + '}', index);
@@ -463,7 +465,7 @@
463465
this.grid.get_grid_height() * (this.opts.cell_height + this.opts.vertical_margin) -
464466
this.opts.vertical_margin);
465467

466-
var on_resize_handler = function() {
468+
this.on_resize_handler = function() {
467469
if (self._is_one_column_mode()) {
468470
if (one_column_mode)
469471
return;
@@ -506,8 +508,8 @@
506508
}
507509
};
508510

509-
$(window).resize(on_resize_handler);
510-
on_resize_handler();
511+
$(window).resize(this.on_resize_handler);
512+
this.on_resize_handler();
511513
};
512514

513515
GridStack.prototype._init_styles = function() {
@@ -732,6 +734,15 @@
732734
this._update_container_height();
733735
};
734736

737+
GridStack.prototype.destroy = function() {
738+
$(window).off("resize", this.on_resize_handler);
739+
this.disable();
740+
this.container.remove();
741+
Utils.remove_stylesheet(this._styles_id);
742+
if (this.grid)
743+
this.grid = null;
744+
};
745+
735746
GridStack.prototype.resizable = function(el, val) {
736747
el = $(el);
737748
el.each(function(index, el) {

0 commit comments

Comments
 (0)