Skip to content

Commit 639d58a

Browse files
author
Alain Dumesny
authored
Merge pull request #1125 from adumesny/develop
oneColumnMode bug fix
2 parents 95f7942 + aed5a23 commit 639d58a

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

doc/CHANGES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ Change log
2929

3030
## v0.6.1-dev (upcoming changes)
3131

32-
- TBD
32+
- fix oneColumnMode to only restore if we auto went to it as window sizes up [#1125](https://github.com/gridstack/gridstack.js/pull/1125)
3333

3434
## v0.6.1 (2020-02-02)
3535

36-
- one column mode (<768px by default) now simply calls `setColumn(1)` and remembers prev columns (so we can restore). This gives
36+
- fix [#37](https://github.com/gridstack/gridstack.js/issues/37) oneColumnMode (<768px by default) now simply calls `setColumn(1)` and remembers prev columns (so we can restore). This gives
3737
us full resize/re-order of items capabilities rather than a locked CSS only layout (see prev rev changes). [#1120](https://github.com/gridstack/gridstack.js/pull/1120)
3838
- fixed responsive.html demo [#1121](https://github.com/gridstack/gridstack.js/pull/1121)
3939

src/gridstack.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@
666666

667667
var GridStack = function(el, opts) {
668668
var self = this;
669-
var _prevColumn, isAutoCellHeight;
669+
var oneColumnMode, _prevColumn, isAutoCellHeight;
670670

671671
opts = opts || {};
672672

@@ -823,17 +823,19 @@
823823
self._updateHeightsOnResize();
824824
}
825825

826-
var oneColumnWidth = (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) <= self.opts.minWidth;
826+
if (self.opts.staticGrid) { return; }
827827

828-
if (oneColumnWidth && !self.opts.disableOneColumnMode) {
829-
if (self._prevColumn || self.opts.staticGrid) { return; }
828+
if (!self.opts.disableOneColumnMode && (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) <= self.opts.minWidth) {
829+
if (self.oneColumnMode) { return; }
830830

831831
self.container.addClass(self.opts.oneColumnModeClass); // TODO: legacy do people still depend on style being there ?
832+
self.oneColumnMode = true;
832833
self.setColumn(1);
833834
} else {
834-
if (!self._prevColumn || self.opts.staticGrid) { return; }
835+
if (!self.oneColumnMode) { return; }
835836

836837
self.container.removeClass(self.opts.oneColumnModeClass);
838+
self.oneColumnMode = false;
837839
self.setColumn(self._prevColumn);
838840
}
839841
};

0 commit comments

Comments
 (0)