From 48c1bf1f79bdffd588044f19dba237b0e02794bb Mon Sep 17 00:00:00 2001 From: Pavel Reznikov Date: Fri, 5 Dec 2014 18:31:12 -0800 Subject: [PATCH] add `will_it_fit` API method --- src/gridstack.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/gridstack.js b/src/gridstack.js index 75977af..7f04d20 100644 --- a/src/gridstack.js +++ b/src/gridstack.js @@ -219,6 +219,20 @@ return clone.get_grid_height() <= this.height; }; + GridStackEngine.prototype.can_be_placed_with_respect_to_height = function (node) { + if (!this.height) + return true; + + var clone = new GridStackEngine( + this.width, + null, + this.float, + 0, + _.map(this.nodes, function (n) { return $.extend({}, n) })); + clone.add_node(node); + return clone.get_grid_height() <= this.height; + }; + GridStackEngine.prototype.move_node = function (node, x, y, width, height, no_pack) { if (typeof x != 'number') x = node.x; if (typeof y != 'number') y = node.y; @@ -492,7 +506,7 @@ else { this.container.removeClass('grid-stack-animate'); } - } + }; GridStack.prototype.add_widget = function (el, x, y, width, height, auto_position) { el = $(el); @@ -506,6 +520,11 @@ this._update_container_height(); }; + GridStack.prototype.will_it_fit = function (x, y, width, height, auto_position) { + var node = {x: x, y: y, width: width, height: height, auto_position: auto_position}; + return this.grid.can_be_placed_with_respect_to_height(node); + }; + GridStack.prototype.remove_widget = function (el) { el = $(el); var node = el.data('_gridstack_node');