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

Skip to content

Commit a349b76

Browse files
committed
Merge pull request gridstack#1 from troolee/master
Merge latest commit to fork
2 parents 187e13a + e0e9eec commit a349b76

File tree

5 files changed

+92
-16
lines changed

5 files changed

+92
-16
lines changed

README.md

Lines changed: 7 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:
@@ -687,6 +692,8 @@ Changes
687692

688693
- fix closure compiler/linter warnings
689694
- add `static_grid` option.
695+
- add `min_width`/`min_height` methods (Thanks to @cvillemure)
696+
- add `destroy` method (Thanks to @zspitzer)
690697

691698
#### v0.2.3 (2015-06-23)
692699

dist/gridstack.js

Lines changed: 68 additions & 10 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,23 @@
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();
513+
};
514+
515+
GridStack.prototype._trigger_change_event = function(forceTrigger) {
516+
var elements = this.grid.get_dirty_nodes();
517+
var hasChanges = false;
518+
519+
var eventParams = [];
520+
if (elements && elements.length) {
521+
eventParams.push(elements);
522+
hasChanges = true;
523+
}
524+
525+
if (hasChanges || forceTrigger === true) {
526+
this.container.trigger('change', eventParams);
527+
}
511528
};
512529

513530
GridStack.prototype._init_styles = function() {
@@ -638,9 +655,7 @@
638655
.attr('data-gs-height', node.height)
639656
.removeAttr('style');
640657
self._update_container_height();
641-
var elements = self.grid.get_dirty_nodes();
642-
if (elements && elements.length)
643-
self.container.trigger('change', [elements]);
658+
self._trigger_change_event();
644659

645660
self.grid.end_update();
646661
};
@@ -704,6 +719,7 @@
704719
this.container.append(el);
705720
this._prepare_element(el);
706721
this._update_container_height();
722+
this._trigger_change_event(true);
707723

708724
return el;
709725
};
@@ -722,6 +738,7 @@
722738
this._update_container_height();
723739
if (detach_node)
724740
el.remove();
741+
this._trigger_change_event(true);
725742
};
726743

727744
GridStack.prototype.remove_all = function(detach_node) {
@@ -732,6 +749,15 @@
732749
this._update_container_height();
733750
};
734751

752+
GridStack.prototype.destroy = function() {
753+
$(window).off("resize", this.on_resize_handler);
754+
this.disable();
755+
this.container.remove();
756+
Utils.remove_stylesheet(this._styles_id);
757+
if (this.grid)
758+
this.grid = null;
759+
};
760+
735761
GridStack.prototype.resizable = function(el, val) {
736762
el = $(el);
737763
el.each(function(index, el) {
@@ -797,6 +823,40 @@
797823
return this;
798824
};
799825

826+
GridStack.prototype.min_height = function (el, val) {
827+
el = $(el);
828+
el.each(function (index, el) {
829+
el = $(el);
830+
var node = el.data('_gridstack_node');
831+
if (typeof node == 'undefined' || node == null) {
832+
return;
833+
}
834+
835+
if(!isNaN(val)){
836+
node.min_height = (val || false);
837+
el.attr('data-gs-min-height', val);
838+
}
839+
});
840+
return this;
841+
};
842+
843+
GridStack.prototype.min_width = function (el, val) {
844+
el = $(el);
845+
el.each(function (index, el) {
846+
el = $(el);
847+
var node = el.data('_gridstack_node');
848+
if (typeof node == 'undefined' || node == null) {
849+
return;
850+
}
851+
852+
if(!isNaN(val)){
853+
node.min_width = (val || false);
854+
el.attr('data-gs-min-width', val);
855+
}
856+
});
857+
return this;
858+
};
859+
800860
GridStack.prototype._update_element = function(el, callback) {
801861
el = $(el).first();
802862
var node = el.data('_gridstack_node');
@@ -812,9 +872,7 @@
812872
callback.call(this, el, node);
813873

814874
self._update_container_height();
815-
var elements = self.grid.get_dirty_nodes();
816-
if (elements && elements.length)
817-
self.container.trigger('change', [elements]);
875+
self._trigger_change_event();
818876

819877
self.grid.end_update();
820878
};

0 commit comments

Comments
 (0)