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

Skip to content

Commit fcc4a60

Browse files
committed
update gridstack.js
1 parent c7b062b commit fcc4a60

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

gridstack.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@
6767

6868
this.nodes = items || [];
6969
this.onchange = onchange || function () {};
70+
71+
this._update_counter = 0;
72+
this._float = this.float;
73+
};
74+
75+
GridStackEngine.prototype.batch_update = function () {
76+
this._update_counter = 1;
77+
this.float = true;
78+
};
79+
80+
GridStackEngine.prototype.commit = function () {
81+
this._update_counter = 0;
82+
if (this._update_counter == 0) {
83+
this.float = this._float;
84+
this._pack_nodes();
85+
this._notify();
86+
}
7087
};
7188

7289
GridStackEngine.prototype._fix_collisions = function (node) {
@@ -188,6 +205,9 @@
188205
};
189206

190207
GridStackEngine.prototype._notify = function () {
208+
if (this._update_counter) {
209+
return;
210+
}
191211
var deleted_nodes = Array.prototype.slice.call(arguments, 1).concat(this.get_dirty_nodes());
192212
deleted_nodes = deleted_nodes.concat(this.get_dirty_nodes());
193213
this.onchange(deleted_nodes);
@@ -502,6 +522,9 @@
502522
};
503523

504524
GridStack.prototype._update_container_height = function () {
525+
if (this.grid._update_counter) {
526+
return;
527+
}
505528
this.container.height(this.grid.get_grid_height() * (this.opts.cell_height + this.opts.vertical_margin) - this.opts.vertical_margin);
506529
};
507530

@@ -522,7 +545,7 @@
522545
height: el.attr('data-gs-height'),
523546
max_width: el.attr('data-gs-max-width'),
524547
min_width: el.attr('data-gs-min-width'),
525-
max_height: el.attr('data-gs-max-height') || 100,
548+
max_height: el.attr('data-gs-max-height'),
526549
min_height: el.attr('data-gs-min-height'),
527550
auto_position: Utils.toBool(el.attr('data-gs-auto-position')),
528551
no_resize: Utils.toBool(el.attr('data-gs-no-resize')),
@@ -751,6 +774,17 @@
751774
});
752775
};
753776

777+
GridStack.prototype.update = function (el, x, y, width, height) {
778+
this._update_element(el, function (el, node) {
779+
x = (x != null && typeof x != 'undefined') ? x : node.x;
780+
y = (y != null && typeof y != 'undefined') ? y : node.y;
781+
width = (width != null && typeof width != 'undefined') ? width : node.width;
782+
height = (height != null && typeof height != 'undefined') ? height : node.height;
783+
784+
this.grid.move_node(node, x, y, width, height);
785+
});
786+
};
787+
754788
GridStack.prototype.cell_height = function (val) {
755789
if (typeof val == 'undefined') {
756790
return this.opts.cell_height;
@@ -778,6 +812,15 @@
778812
return {x: Math.floor(relativeLeft / column_width), y: Math.floor(relativeTop / row_height)};
779813
};
780814

815+
GridStack.prototype.batch_update = function () {
816+
this.grid.batch_update();
817+
};
818+
819+
GridStack.prototype.commit = function () {
820+
this.grid.commit();
821+
this._update_container_height()
822+
};
823+
781824
scope.GridStackUI = GridStack;
782825

783826
scope.GridStackUI.Utils = Utils;

0 commit comments

Comments
 (0)