Skip to content

Commit 3a5c675

Browse files
committed
‘auto’ value for cellHeight
1 parent c4f30b3 commit 3a5c675

File tree

6 files changed

+38
-16
lines changed

6 files changed

+38
-16
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ Changes
440440
- fix `batchUpdate`/`commit` (Thank to @radiolips)
441441
- remove dependency of FontAwesome
442442
- RTL support
443+
- `'auto'` value for `cellHeight` option
443444

444445
#### v0.2.4 (2016-02-15)
445446

dist/gridstack.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@
444444

445445
var GridStack = function(el, opts) {
446446
var self = this;
447-
var oneColumnMode;
447+
var oneColumnMode, isAutoCellHeight;
448448

449449
opts = opts || {};
450450

@@ -542,7 +542,12 @@
542542

543543
this.opts.isNested = isNested;
544544

545-
this.cellHeight(this.opts.cellHeight, true);
545+
isAutoCellHeight = this.opts.cellHeight === 'auto';
546+
if (isAutoCellHeight) {
547+
self.cellHeight(self.cellWidth(), true);
548+
} else {
549+
this.cellHeight(this.opts.cellHeight, true);
550+
}
546551
this.verticalMargin(this.opts.verticalMargin, true);
547552

548553
this.container.addClass(this.opts._class);
@@ -596,7 +601,15 @@
596601

597602
this._updateContainerHeight();
598603

604+
this._updateHeightsOnResize = _.throttle(function() {
605+
self.cellHeight(self.cellWidth(), false);
606+
}, 100);
607+
599608
this.onResizeHandler = function() {
609+
if (isAutoCellHeight) {
610+
self._updateHeightsOnResize();
611+
}
612+
600613
if (self._isOneColumnMode()) {
601614
if (oneColumnMode) {
602615
return;
@@ -660,9 +673,6 @@
660673
};
661674

662675
GridStack.prototype._initStyles = function() {
663-
if (!this.opts.cellHeight) { // That will be handled by CSS
664-
return ;
665-
}
666676
if (this._stylesId) {
667677
$('[data-gs-id="' + this._stylesId + '"]').remove();
668678
}
@@ -674,7 +684,7 @@
674684
};
675685

676686
GridStack.prototype._updateStyles = function(maxHeight) {
677-
if (this._styles === null) {
687+
if (this._styles === null || typeof this._styles === 'undefined') {
678688
return;
679689
}
680690

dist/gridstack.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gridstack.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ gridstack.js API
5959
- `cellHeight` - one cell height (default: `60`). Can be:
6060
- an integer (px)
6161
- a string (ex: '10em', '100px', '10rem')
62-
- 0 or null, in which case the library will not generate styles for rows. Everything will have to be defined in CSS files.
62+
- 0 or null, in which case the library will not generate styles for rows. Everything must be defined in CSS files.
63+
- `'auto'` - height will be calculated from cell width.
6364
- `disableDrag` - disallows dragging of widgets (default: `false`).
6465
- `disableResize` - disallows resizing of widgets (default: `false`).
6566
- `draggable` - allows to override jQuery UI draggable options. (default: `{handle: '.grid-stack-item-content', scroll: true, appendTo: 'body'}`)

src/gridstack.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@
444444

445445
var GridStack = function(el, opts) {
446446
var self = this;
447-
var oneColumnMode;
447+
var oneColumnMode, isAutoCellHeight;
448448

449449
opts = opts || {};
450450

@@ -542,7 +542,12 @@
542542

543543
this.opts.isNested = isNested;
544544

545-
this.cellHeight(this.opts.cellHeight, true);
545+
isAutoCellHeight = this.opts.cellHeight === 'auto';
546+
if (isAutoCellHeight) {
547+
self.cellHeight(self.cellWidth(), true);
548+
} else {
549+
this.cellHeight(this.opts.cellHeight, true);
550+
}
546551
this.verticalMargin(this.opts.verticalMargin, true);
547552

548553
this.container.addClass(this.opts._class);
@@ -596,7 +601,15 @@
596601

597602
this._updateContainerHeight();
598603

604+
this._updateHeightsOnResize = _.throttle(function() {
605+
self.cellHeight(self.cellWidth(), false);
606+
}, 100);
607+
599608
this.onResizeHandler = function() {
609+
if (isAutoCellHeight) {
610+
self._updateHeightsOnResize();
611+
}
612+
600613
if (self._isOneColumnMode()) {
601614
if (oneColumnMode) {
602615
return;
@@ -660,9 +673,6 @@
660673
};
661674

662675
GridStack.prototype._initStyles = function() {
663-
if (!this.opts.cellHeight) { // That will be handled by CSS
664-
return ;
665-
}
666676
if (this._stylesId) {
667677
$('[data-gs-id="' + this._stylesId + '"]').remove();
668678
}
@@ -674,7 +684,7 @@
674684
};
675685

676686
GridStack.prototype._updateStyles = function(maxHeight) {
677-
if (this._styles === null) {
687+
if (this._styles === null || typeof this._styles === 'undefined') {
678688
return;
679689
}
680690

0 commit comments

Comments
 (0)