From a37fd745ddae37bca12f28a6dbcdfd74019e443d Mon Sep 17 00:00:00 2001 From: Pavel Reznikov Date: Fri, 5 Dec 2014 18:29:52 -0800 Subject: [PATCH] update gridstack.js --- gridstack.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/gridstack.js b/gridstack.js index 3ab1cba..7f04d20 100644 --- a/gridstack.js +++ b/gridstack.js @@ -174,6 +174,9 @@ for (var i = 0; ; ++i) { var x = i % this.width, y = Math.floor(i / this.width); + if (x + node.width > this.width) { + continue; + } if (!_.find(this.nodes, function (n) { return Utils.is_intercepted({x: x, y: y, width: node.width, height: node.height}, n); })) { @@ -216,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; @@ -489,7 +506,7 @@ else { this.container.removeClass('grid-stack-animate'); } - } + }; GridStack.prototype.add_widget = function (el, x, y, width, height, auto_position) { el = $(el); @@ -503,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');