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

Skip to content

Commit 48c1bf1

Browse files
committed
add will_it_fit API method
1 parent ecc9293 commit 48c1bf1

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/gridstack.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,20 @@
219219
return clone.get_grid_height() <= this.height;
220220
};
221221

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+
222236
GridStackEngine.prototype.move_node = function (node, x, y, width, height, no_pack) {
223237
if (typeof x != 'number') x = node.x;
224238
if (typeof y != 'number') y = node.y;
@@ -492,7 +506,7 @@
492506
else {
493507
this.container.removeClass('grid-stack-animate');
494508
}
495-
}
509+
};
496510

497511
GridStack.prototype.add_widget = function (el, x, y, width, height, auto_position) {
498512
el = $(el);
@@ -506,6 +520,11 @@
506520
this._update_container_height();
507521
};
508522

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+
509528
GridStack.prototype.remove_widget = function (el) {
510529
el = $(el);
511530
var node = el.data('_gridstack_node');

0 commit comments

Comments
 (0)