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

Skip to content

Commit ed29eed

Browse files
committed
destroy method
1 parent ac219ab commit ed29eed

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Inspired by [gridster.js](http://gridster.net). Built with love.
3131
- [cell_height(val)](#cell_heightval)
3232
- [cell_width()](#cell_width)
3333
- [commit()](#commit)
34+
- [destroy()](#destroy)
3435
- [disable()](#disable)
3536
- [enable()](#enable)
3637
- [get_cell_from_pixel(position)](#get_cell_from_pixelposition)
@@ -255,6 +256,10 @@ Gets current cell width.
255256

256257
Finishes batch updates. Updates DOM nodes. You must call it after `batch_update`.
257258

259+
### destroy()
260+
261+
Destroys a grid instance.
262+
258263
### disable()
259264

260265
Disables widgets moving/resizing. This is a shortcut for:
@@ -688,6 +693,7 @@ Changes
688693
- fix closure compiler/linter warnings
689694
- add `static_grid` option.
690695
- add `min_width`/`min_height` methods (Thanks to @cvillemure)
696+
- add `destroy` method (Thanks to @zspitzer)
691697

692698
#### v0.2.3 (2015-06-23)
693699

dist/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) {

dist/gridstack.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)