|
174 | 174 |
|
175 | 175 | for (var i = 0; ; ++i) {
|
176 | 176 | var x = i % this.width, y = Math.floor(i / this.width);
|
| 177 | + if (x + node.width > this.width) { |
| 178 | + continue; |
| 179 | + } |
177 | 180 | if (!_.find(this.nodes, function (n) {
|
178 | 181 | return Utils.is_intercepted({x: x, y: y, width: node.width, height: node.height}, n);
|
179 | 182 | })) {
|
|
216 | 219 | return clone.get_grid_height() <= this.height;
|
217 | 220 | };
|
218 | 221 |
|
| 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 | + |
219 | 236 | GridStackEngine.prototype.move_node = function (node, x, y, width, height, no_pack) {
|
220 | 237 | if (typeof x != 'number') x = node.x;
|
221 | 238 | if (typeof y != 'number') y = node.y;
|
|
489 | 506 | else {
|
490 | 507 | this.container.removeClass('grid-stack-animate');
|
491 | 508 | }
|
492 |
| - } |
| 509 | + }; |
493 | 510 |
|
494 | 511 | GridStack.prototype.add_widget = function (el, x, y, width, height, auto_position) {
|
495 | 512 | el = $(el);
|
|
503 | 520 | this._update_container_height();
|
504 | 521 | };
|
505 | 522 |
|
| 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 | + |
506 | 528 | GridStack.prototype.remove_widget = function (el) {
|
507 | 529 | el = $(el);
|
508 | 530 | var node = el.data('_gridstack_node');
|
|
0 commit comments