|
759 | 759 |
|
760 | 760 | this.opts.isNested = isNested;
|
761 | 761 |
|
762 |
| - isAutoCellHeight = this.opts.cellHeight === 'auto'; |
| 762 | + isAutoCellHeight = (this.opts.cellHeight === 'auto'); |
763 | 763 | if (isAutoCellHeight) {
|
| 764 | + // make the cell square initially |
764 | 765 | self.cellHeight(self.cellWidth(), true);
|
765 | 766 | } else {
|
766 | 767 | this.cellHeight(this.opts.cellHeight, true);
|
|
964 | 965 | var cellWidth = self.cellWidth();
|
965 | 966 | var cellHeight = self.cellHeight();
|
966 | 967 | var origNode = el.data('_gridstack_node');
|
| 968 | + var verticalMargin = self.opts.verticalMargin; |
967 | 969 |
|
968 |
| - var width = origNode ? origNode.width : (Math.ceil(el.outerWidth() / cellWidth)); |
969 |
| - var height = origNode ? origNode.height : (Math.ceil(el.outerHeight() / cellHeight)); |
| 970 | + // height: Each row is cellHeight + verticalMargin, until last one which has no margin below |
| 971 | + var width = origNode ? origNode.width : Math.ceil(el.outerWidth() / cellWidth); |
| 972 | + var height = origNode ? origNode.height : Math.round((el.outerHeight() + verticalMargin) / (cellHeight + verticalMargin)); |
970 | 973 |
|
971 | 974 | draggingElement = el;
|
972 | 975 |
|
|
1148 | 1151 | // check for css min height. Each row is cellHeight + verticalMargin, until last one which has no margin below
|
1149 | 1152 | var cssMinHeight = parseInt(this.container.css('min-height'));
|
1150 | 1153 | if (cssMinHeight > 0) {
|
1151 |
| - var minHeight = (cssMinHeight + this.opts.verticalMargin) / (this.cellHeight() + this.opts.verticalMargin); |
| 1154 | + var verticalMargin = this.opts.verticalMargin; |
| 1155 | + var minHeight = Math.round((cssMinHeight + verticalMargin) / (this.cellHeight() + verticalMargin)); |
1152 | 1156 | if (height < minHeight) {
|
1153 | 1157 | height = minHeight;
|
1154 | 1158 | }
|
|
1285 | 1289 | self.grid.cleanNodes();
|
1286 | 1290 | self.grid.beginUpdate(node);
|
1287 | 1291 | cellWidth = self.cellWidth();
|
1288 |
| - var strictCellHeight = Math.ceil(o.outerHeight() / o.attr('data-gs-height')); |
| 1292 | + var strictCellHeight = self.cellHeight(); |
| 1293 | + // TODO: cellHeight cannot be set to cellHeight() (i.e. remove strictCellHeight) right here otherwise |
| 1294 | + // when sizing up we jump almost right away to next size instead of half way there. Not sure |
| 1295 | + // why as we don't use ceil() is many places but round(). |
1289 | 1296 | cellHeight = self.container.height() / parseInt(self.container.attr('data-gs-current-height'));
|
1290 | 1297 | self.placeholder
|
1291 | 1298 | .attr('data-gs-x', o.attr('data-gs-x'))
|
|
1297 | 1304 | node._beforeDragX = node.x;
|
1298 | 1305 | node._beforeDragY = node.y;
|
1299 | 1306 | node._prevYPix = ui.position.top;
|
| 1307 | + var minHeight = (node.minHeight || 1); |
| 1308 | + var verticalMargin = self.opts.verticalMargin; |
1300 | 1309 |
|
| 1310 | + // mineHeight - Each row is cellHeight + verticalMargin, until last one which has no margin below |
1301 | 1311 | self.dd.resizable(el, 'option', 'minWidth', cellWidth * (node.minWidth || 1));
|
1302 |
| - self.dd.resizable(el, 'option', 'minHeight', strictCellHeight * (node.minHeight || 1)); |
| 1312 | + self.dd.resizable(el, 'option', 'minHeight', (strictCellHeight * minHeight) + (minHeight - 1) * verticalMargin); |
1303 | 1313 |
|
1304 | 1314 | if (event.type == 'resizestart') {
|
1305 | 1315 | o.find('.grid-stack-item').trigger('resizestart');
|
|
1723 | 1733 | }
|
1724 | 1734 | };
|
1725 | 1735 |
|
| 1736 | + /** set/get the current cell height value */ |
1726 | 1737 | GridStack.prototype.cellHeight = function(val, noUpdate) {
|
| 1738 | + // getter - returns the opts stored height else compute it... |
1727 | 1739 | if (typeof val == 'undefined') {
|
1728 |
| - if (this.opts.cellHeight) { |
| 1740 | + if (this.opts.cellHeight && this.opts.cellHeight !== 'auto') { |
1729 | 1741 | return this.opts.cellHeight;
|
1730 | 1742 | }
|
| 1743 | + // compute the height taking margin into account (each row has margin other than last one) |
1731 | 1744 | var o = this.container.children('.' + this.opts.itemClass).first();
|
1732 |
| - return Math.ceil(o.outerHeight() / o.attr('data-gs-height')); |
| 1745 | + var height = o.attr('data-gs-height'); |
| 1746 | + var verticalMargin = this.opts.verticalMargin; |
| 1747 | + return Math.round((o.outerHeight() - (height - 1) * verticalMargin) / height); |
1733 | 1748 | }
|
1734 |
| - var heightData = Utils.parseHeight(val); |
1735 | 1749 |
|
| 1750 | + // setter - updates the cellHeight value if they changed |
| 1751 | + var heightData = Utils.parseHeight(val); |
1736 | 1752 | if (this.opts.cellHeightUnit === heightData.unit && this.opts.cellHeight === heightData.height) {
|
1737 | 1753 | return ;
|
1738 | 1754 | }
|
|
1742 | 1758 | if (!noUpdate) {
|
1743 | 1759 | this._updateStyles();
|
1744 | 1760 | }
|
1745 |
| - |
1746 | 1761 | };
|
1747 | 1762 |
|
1748 | 1763 | GridStack.prototype.cellWidth = function() {
|
|
0 commit comments