Merge pull request #1 from troolee/master

Merge latest commit to fork
This commit is contained in:
cvillemure 2015-07-23 15:19:12 -04:00
commit a349b76156
5 changed files with 92 additions and 16 deletions

View file

@ -31,6 +31,7 @@ Inspired by [gridster.js](http://gridster.net). Built with love.
- [cell_height(val)](#cell_heightval)
- [cell_width()](#cell_width)
- [commit()](#commit)
- [destroy()](#destroy)
- [disable()](#disable)
- [enable()](#enable)
- [get_cell_from_pixel(position)](#get_cell_from_pixelposition)
@ -255,6 +256,10 @@ Gets current cell width.
Finishes batch updates. Updates DOM nodes. You must call it after `batch_update`.
### destroy()
Destroys a grid instance.
### disable()
Disables widgets moving/resizing. This is a shortcut for:
@ -687,6 +692,8 @@ Changes
- fix closure compiler/linter warnings
- add `static_grid` option.
- add `min_width`/`min_height` methods (Thanks to @cvillemure)
- add `destroy` method (Thanks to @zspitzer)
#### v0.2.3 (2015-06-23)

78
dist/gridstack.js vendored
View file

@ -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,23 @@
}
};
$(window).resize(on_resize_handler);
on_resize_handler();
$(window).resize(this.on_resize_handler);
this.on_resize_handler();
};
GridStack.prototype._trigger_change_event = function(forceTrigger) {
var elements = this.grid.get_dirty_nodes();
var hasChanges = false;
var eventParams = [];
if (elements && elements.length) {
eventParams.push(elements);
hasChanges = true;
}
if (hasChanges || forceTrigger === true) {
this.container.trigger('change', eventParams);
}
};
GridStack.prototype._init_styles = function() {
@ -638,9 +655,7 @@
.attr('data-gs-height', node.height)
.removeAttr('style');
self._update_container_height();
var elements = self.grid.get_dirty_nodes();
if (elements && elements.length)
self.container.trigger('change', [elements]);
self._trigger_change_event();
self.grid.end_update();
};
@ -704,6 +719,7 @@
this.container.append(el);
this._prepare_element(el);
this._update_container_height();
this._trigger_change_event(true);
return el;
};
@ -722,6 +738,7 @@
this._update_container_height();
if (detach_node)
el.remove();
this._trigger_change_event(true);
};
GridStack.prototype.remove_all = function(detach_node) {
@ -732,6 +749,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) {
@ -797,6 +823,40 @@
return this;
};
GridStack.prototype.min_height = function (el, val) {
el = $(el);
el.each(function (index, el) {
el = $(el);
var node = el.data('_gridstack_node');
if (typeof node == 'undefined' || node == null) {
return;
}
if(!isNaN(val)){
node.min_height = (val || false);
el.attr('data-gs-min-height', val);
}
});
return this;
};
GridStack.prototype.min_width = function (el, val) {
el = $(el);
el.each(function (index, el) {
el = $(el);
var node = el.data('_gridstack_node');
if (typeof node == 'undefined' || node == null) {
return;
}
if(!isNaN(val)){
node.min_width = (val || false);
el.attr('data-gs-min-width', val);
}
});
return this;
};
GridStack.prototype._update_element = function(el, callback) {
el = $(el).first();
var node = el.data('_gridstack_node');
@ -812,9 +872,7 @@
callback.call(this, el, node);
self._update_container_height();
var elements = self.grid.get_dirty_nodes();
if (elements && elements.length)
self.container.trigger('change', [elements]);
self._trigger_change_event();
self.grid.end_update();
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -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._trigger_change_event = function(forceTrigger) {
@ -747,6 +749,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) {