|
296 | 296 |
|
297 | 297 | var idSeq = 0; |
298 | 298 |
|
299 | | - var GridStackEngine = function(column, onchange, float, maxRow, items) { |
| 299 | + var GridStackEngine = function(row, column, onchange, float, minRow, maxRow, items) { |
| 300 | + this.row = row || 0; |
300 | 301 | this.column = column || 12; |
301 | 302 | this.float = float || false; |
302 | | - this.maxRow = maxRow || 0; |
| 303 | + this.minRow = minRow || 0; |
| 304 | + this.maxRow = this.row ? this.row : maxRow || 0; |
303 | 305 |
|
304 | 306 | this.nodes = items || []; |
305 | 307 | this.onchange = onchange || function() {}; |
|
558 | 560 | } |
559 | 561 | var hasLocked = Boolean(this.nodes.find(function(n) { return n.locked; })); |
560 | 562 |
|
561 | | - if (!this.maxRow && !hasLocked) { |
| 563 | + if (!this.maxRow && !this.row && !hasLocked) { |
562 | 564 | return true; |
563 | 565 | } |
564 | 566 |
|
565 | 567 | var clonedNode; |
566 | 568 | var clone = new GridStackEngine( |
| 569 | + 0, |
567 | 570 | this.column, |
568 | 571 | null, |
569 | 572 | this.float, |
570 | 573 | 0, |
| 574 | + 0, |
571 | 575 | this.nodes.map(function(n) { |
572 | 576 | if (n === node) { |
573 | 577 | clonedNode = $.extend({}, n); |
|
587 | 591 | return n !== clonedNode && Boolean(n.locked) && Boolean(n._dirty); |
588 | 592 | })); |
589 | 593 | } |
590 | | - if (this.maxRow) { |
| 594 | + if (this.maxRow || this.row) { |
591 | 595 | res &= clone.getRow() <= this.maxRow; |
592 | 596 | } |
593 | 597 |
|
594 | 598 | return res; |
595 | 599 | }; |
596 | 600 |
|
597 | 601 | GridStackEngine.prototype.canBePlacedWithRespectToHeight = function(node) { |
598 | | - if (!this.maxRow) { |
| 602 | + if (!this.maxRow && !this.row) { |
599 | 603 | return true; |
600 | 604 | } |
601 | | - |
602 | 605 | var clone = new GridStackEngine( |
| 606 | + 0, |
603 | 607 | this.column, |
604 | 608 | null, |
605 | 609 | this.float, |
606 | 610 | 0, |
| 611 | + 0, |
607 | 612 | this.nodes.map(function(n) { return $.extend({}, n); })); |
608 | 613 | clone.addNode(node); |
609 | 614 | return clone.getRow() <= this.maxRow; |
|
665 | 670 | }; |
666 | 671 |
|
667 | 672 | GridStackEngine.prototype.getRow = function() { |
668 | | - return this.nodes.reduce(function(memo, n) { return Math.max(memo, n.y + n.height); }, 0); |
| 673 | + return this.row ? this.row : this.nodes.reduce(function(memo, n) { return Math.max(memo, n.y + n.height); }, 0); |
669 | 674 | }; |
670 | 675 |
|
671 | 676 | GridStackEngine.prototype.beginUpdate = function(node) { |
|
709 | 714 | var isNested = this.$el.closest('.' + opts.itemClass).length > 0; |
710 | 715 |
|
711 | 716 | this.opts = Utils.defaults(opts, { |
| 717 | + row: parseInt(this.$el.attr('data-gs-row')) || 0, |
712 | 718 | column: parseInt(this.$el.attr('data-gs-column')) || 12, |
713 | | - maxRow: parseInt(this.$el.attr('data-gs-max-row')) || 0, |
| 719 | + maxRow: parseInt(this.$el.attr('data-gs-row')) || 0 ? parseInt(this.$el.attr('data-gs-row')) : parseInt(this.$el.attr('data-gs-max-row')) || 0, |
| 720 | + minRow: parseInt(this.$el.attr('data-gs-min-row')) || 0, |
714 | 721 | itemClass: 'grid-stack-item', |
715 | 722 | placeholderClass: 'grid-stack-placeholder', |
716 | 723 | placeholderText: '', |
|
787 | 794 |
|
788 | 795 | this._initStyles(); |
789 | 796 |
|
790 | | - this.engine = new GridStackEngine(this.opts.column, function(nodes, detachNode) { |
| 797 | + this.engine = new GridStackEngine(this.opts.row, this.opts.column, function(nodes, detachNode) { |
791 | 798 | detachNode = (detachNode === undefined ? true : detachNode); |
792 | 799 | var maxHeight = 0; |
793 | 800 | this.nodes.forEach(function(n) { |
|
807 | 814 | } |
808 | 815 | }); |
809 | 816 | self._updateStyles(maxHeight + 10); |
810 | | - }, this.opts.float, this.opts.maxRow); |
| 817 | + }, this.opts.float, this.opts.minRow, this.opts.maxRow); |
811 | 818 |
|
812 | 819 | if (this.opts.auto) { |
813 | 820 | var elements = []; |
|
1155 | 1162 |
|
1156 | 1163 | GridStack.prototype._updateContainerHeight = function() { |
1157 | 1164 | if (this.engine._batchMode) { return; } |
1158 | | - var row = this.engine.getRow(); |
| 1165 | + var row = this.opts.minRow > this.engine.getRow() ? this.opts.minRow : this.engine.getRow(); |
1159 | 1166 | // check for css min height. Each row is cellHeight + verticalMargin, until last one which has no margin below |
1160 | 1167 | var cssMinHeight = parseInt(this.$el.css('min-height')); |
1161 | 1168 | if (cssMinHeight > 0) { |
1162 | 1169 | var verticalMargin = this.opts.verticalMargin; |
1163 | | - var minRow = Math.round((cssMinHeight + verticalMargin) / (this.cellHeight() + verticalMargin)); |
| 1170 | + var minRow = Math.round((cssMinHeight + verticalMargin) / (this.cellHeight() + verticalMargin)); |
1164 | 1171 | if (row < minRow) { |
1165 | 1172 | row = minRow; |
1166 | 1173 | } |
|
0 commit comments