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

Skip to content

Commit a37fd74

Browse files
committed
update gridstack.js
1 parent 71c6607 commit a37fd74

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

gridstack.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@
174174

175175
for (var i = 0; ; ++i) {
176176
var x = i % this.width, y = Math.floor(i / this.width);
177+
if (x + node.width > this.width) {
178+
continue;
179+
}
177180
if (!_.find(this.nodes, function (n) {
178181
return Utils.is_intercepted({x: x, y: y, width: node.width, height: node.height}, n);
179182
})) {
@@ -216,6 +219,20 @@
216219
return clone.get_grid_height() <= this.height;
217220
};
218221

222+
GridStackEngine.prototype.can_be_placed_with_respect_to_height = function (node) {
223+
if (!this.height)
224+
return true;
225+
226+
var clone = new GridStackEngine(
227+
this.width,
228+
null,
229+
this.float,
230+
0,
231+
_.map(this.nodes, function (n) { return $.extend({}, n) }));
232+
clone.add_node(node);
233+
return clone.get_grid_height() <= this.height;
234+
};
235+
219236
GridStackEngine.prototype.move_node = function (node, x, y, width, height, no_pack) {
220237
if (typeof x != 'number') x = node.x;
221238
if (typeof y != 'number') y = node.y;
@@ -489,7 +506,7 @@
489506
else {
490507
this.container.removeClass('grid-stack-animate');
491508
}
492-
}
509+
};
493510

494511
GridStack.prototype.add_widget = function (el, x, y, width, height, auto_position) {
495512
el = $(el);
@@ -503,6 +520,11 @@
503520
this._update_container_height();
504521
};
505522

523+
GridStack.prototype.will_it_fit = function (x, y, width, height, auto_position) {
524+
var node = {x: x, y: y, width: width, height: height, auto_position: auto_position};
525+
return this.grid.can_be_placed_with_respect_to_height(node);
526+
};
527+
506528
GridStack.prototype.remove_widget = function (el) {
507529
el = $(el);
508530
var node = el.data('_gridstack_node');

0 commit comments

Comments
 (0)