diff --git a/gridstack.js b/gridstack.js index dc3624b..b2e9041 100644 --- a/gridstack.js +++ b/gridstack.js @@ -67,6 +67,23 @@ this.nodes = items || []; this.onchange = onchange || function () {}; + + this._update_counter = 0; + this._float = this.float; + }; + + GridStackEngine.prototype.batch_update = function () { + this._update_counter = 1; + this.float = true; + }; + + GridStackEngine.prototype.commit = function () { + this._update_counter = 0; + if (this._update_counter == 0) { + this.float = this._float; + this._pack_nodes(); + this._notify(); + } }; GridStackEngine.prototype._fix_collisions = function (node) { @@ -188,6 +205,9 @@ }; GridStackEngine.prototype._notify = function () { + if (this._update_counter) { + return; + } var deleted_nodes = Array.prototype.slice.call(arguments, 1).concat(this.get_dirty_nodes()); deleted_nodes = deleted_nodes.concat(this.get_dirty_nodes()); this.onchange(deleted_nodes); @@ -502,6 +522,9 @@ }; GridStack.prototype._update_container_height = function () { + if (this.grid._update_counter) { + return; + } this.container.height(this.grid.get_grid_height() * (this.opts.cell_height + this.opts.vertical_margin) - this.opts.vertical_margin); }; @@ -522,7 +545,7 @@ height: el.attr('data-gs-height'), max_width: el.attr('data-gs-max-width'), min_width: el.attr('data-gs-min-width'), - max_height: el.attr('data-gs-max-height') || 100, + max_height: el.attr('data-gs-max-height'), min_height: el.attr('data-gs-min-height'), auto_position: Utils.toBool(el.attr('data-gs-auto-position')), no_resize: Utils.toBool(el.attr('data-gs-no-resize')), @@ -751,6 +774,17 @@ }); }; + GridStack.prototype.update = function (el, x, y, width, height) { + this._update_element(el, function (el, node) { + x = (x != null && typeof x != 'undefined') ? x : node.x; + y = (y != null && typeof y != 'undefined') ? y : node.y; + width = (width != null && typeof width != 'undefined') ? width : node.width; + height = (height != null && typeof height != 'undefined') ? height : node.height; + + this.grid.move_node(node, x, y, width, height); + }); + }; + GridStack.prototype.cell_height = function (val) { if (typeof val == 'undefined') { return this.opts.cell_height; @@ -778,6 +812,15 @@ return {x: Math.floor(relativeLeft / column_width), y: Math.floor(relativeTop / row_height)}; }; + GridStack.prototype.batch_update = function () { + this.grid.batch_update(); + }; + + GridStack.prototype.commit = function () { + this.grid.commit(); + this._update_container_height() + }; + scope.GridStackUI = GridStack; scope.GridStackUI.Utils = Utils;