|
342 | 342 | while (true) {
|
343 | 343 | var collisionNode = this.nodes.find(Utils._collisionNodeCheck, {node: node, nn: nn});
|
344 | 344 | if (!collisionNode) { return; }
|
345 |
| - this.moveNode(collisionNode, collisionNode.x, node.y + node.height, |
| 345 | + var moved = this.moveNode(collisionNode, collisionNode.x, node.y + node.height, |
346 | 346 | collisionNode.width, collisionNode.height, true);
|
| 347 | + if (!moved) { return; } // break inf loop if we couldn't move after all (ex: maxRow, fixed) |
347 | 348 | }
|
348 | 349 | };
|
349 | 350 |
|
|
432 | 433 | if (Number.isNaN(node.width)) { node.width = defaults.width; }
|
433 | 434 | if (Number.isNaN(node.height)) { node.height = defaults.height; }
|
434 | 435 |
|
| 436 | + if (node.maxWidth !== undefined) { node.width = Math.min(node.width, node.maxWidth); } |
| 437 | + if (node.maxHeight !== undefined) { node.height = Math.min(node.height, node.maxHeight); } |
| 438 | + if (node.minWidth !== undefined) { node.width = Math.max(node.width, node.minWidth); } |
| 439 | + if (node.minHeight !== undefined) { node.height = Math.max(node.height, node.minHeight); } |
| 440 | + |
435 | 441 | if (node.width > this.column) {
|
436 | 442 | node.width = this.column;
|
437 | 443 | } else if (node.width < 1) {
|
438 | 444 | node.width = 1;
|
439 | 445 | }
|
440 |
| - |
441 |
| - if (node.height < 1) { |
| 446 | + if (this.maxRow && node.height > this.maxRow) { |
| 447 | + node.height = this.maxRow; |
| 448 | + } else if (node.height < 1) { |
442 | 449 | node.height = 1;
|
443 | 450 | }
|
444 | 451 |
|
445 | 452 | if (node.x < 0) {
|
446 | 453 | node.x = 0;
|
447 | 454 | }
|
| 455 | + if (node.y < 0) { |
| 456 | + node.y = 0; |
| 457 | + } |
448 | 458 |
|
449 | 459 | if (node.x + node.width > this.column) {
|
450 | 460 | if (resizing) {
|
|
453 | 463 | node.x = this.column - node.width;
|
454 | 464 | }
|
455 | 465 | }
|
456 |
| - |
457 |
| - if (node.y < 0) { |
458 |
| - node.y = 0; |
| 466 | + if (this.maxRow && node.y + node.height > this.maxRow) { |
| 467 | + if (resizing) { |
| 468 | + node.height = this.maxRow - node.y; |
| 469 | + } else { |
| 470 | + node.y = this.maxRow - node.height; |
| 471 | + } |
459 | 472 | }
|
460 | 473 |
|
461 | 474 | return node;
|
|
497 | 510 | GridStackEngine.prototype.addNode = function(node, triggerAddEvent) {
|
498 | 511 | node = this._prepareNode(node);
|
499 | 512 |
|
500 |
| - if (node.maxWidth !== undefined) { node.width = Math.min(node.width, node.maxWidth); } |
501 |
| - if (node.maxHeight !== undefined) { node.height = Math.min(node.height, node.maxHeight); } |
502 |
| - if (node.minWidth !== undefined) { node.width = Math.max(node.width, node.minWidth); } |
503 |
| - if (node.minHeight !== undefined) { node.height = Math.max(node.height, node.minHeight); } |
504 |
| - |
505 | 513 | node._id = node._id || ++idSeq;
|
506 | 514 |
|
507 | 515 | if (node.autoPosition) {
|
|
632 | 640 | if (typeof width !== 'number') { width = node.width; }
|
633 | 641 | if (typeof height !== 'number') { height = node.height; }
|
634 | 642 |
|
635 |
| - if (node.maxWidth !== undefined) { width = Math.min(width, node.maxWidth); } |
636 |
| - if (node.maxHeight !== undefined) { height = Math.min(height, node.maxHeight); } |
637 |
| - if (node.minWidth !== undefined) { width = Math.max(width, node.minWidth); } |
638 |
| - if (node.minHeight !== undefined) { height = Math.max(height, node.minHeight); } |
639 |
| - |
640 |
| - if (node.x === x && node.y === y && node.width === width && node.height === height) { |
641 |
| - return node; |
| 643 | + // constrain the passed in values and check if we're still changing our node |
| 644 | + var resizing = (node.width !== width || node.height !== height); |
| 645 | + var nn = { x: x, y: y, width: width, height: height, |
| 646 | + maxWidth: node.maxWidth, maxHeight: NodeIterator.maxHeight, minWidth: node.minWidth, minHeight: node.minHeight}; |
| 647 | + nn = this._prepareNode(nn, resizing); |
| 648 | + if (node.x === nn.x && node.y === nn.y && node.width === nn.width && node.height === nn.height) { |
| 649 | + return null; |
642 | 650 | }
|
643 | 651 |
|
644 |
| - var resizing = node.width !== width; |
645 | 652 | node._dirty = true;
|
646 | 653 |
|
647 |
| - node.x = x; |
648 |
| - node.y = y; |
649 |
| - node.width = width; |
650 |
| - node.height = height; |
651 |
| - |
652 |
| - node.lastTriedX = x; |
653 |
| - node.lastTriedY = y; |
654 |
| - node.lastTriedWidth = width; |
655 |
| - node.lastTriedHeight = height; |
656 |
| - |
657 |
| - node = this._prepareNode(node, resizing); |
| 654 | + node.x = node.lastTriedX = nn.x; |
| 655 | + node.y = node.lastTriedY = nn.y; |
| 656 | + node.width = node.lastTriedWidth = nn.width; |
| 657 | + node.height = node.lastTriedHeight = nn.height; |
658 | 658 |
|
659 | 659 | this._fixCollisions(node);
|
660 | 660 | if (!noPack) {
|
|
1462 | 1462 | // Tempting to initialize the passed in opt with default and valid values, but this break knockout demos
|
1463 | 1463 | // as the actual value are filled in when _prepareElement() calls el.attr('data-gs-xyz) before adding the node.
|
1464 | 1464 | // opt = this.engine._prepareNode(opt);
|
1465 |
| - opt = opt || {}; |
1466 | 1465 | } else {
|
1467 | 1466 | // old legacy way of calling with items spelled out - call us back with single object instead (so we can properly initialized values)
|
1468 | 1467 | return this.addWidget(el, {x: opt, y: y, width: width, height: height, autoPosition: autoPosition,
|
1469 | 1468 | minWidth: minWidth, maxWidth: maxWidth, minHeight: minHeight, maxHeight: maxHeight, id: id});
|
1470 | 1469 | }
|
1471 | 1470 |
|
1472 | 1471 | el = $(el);
|
| 1472 | + if (opt) { // see knockout above |
| 1473 | + this.engine._prepareNode(opt); |
| 1474 | + } |
1473 | 1475 | this._writeAttr(el, opt);
|
1474 | 1476 | this.$el.append(el);
|
1475 | 1477 | return this.makeWidget(el);
|
|
0 commit comments