Skip to content

Commit 09de0c0

Browse files
Fix a bug where the sidebar would no longer hide automatically on mobile
1 parent c71c151 commit 09de0c0

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

js/check-width.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,31 @@ $(function () {
77
// Store the window width
88
var windowWidth = $window.width();
99

10-
function checkWidth() {
11-
if ($(window).width() != windowWidth) {
12-
var windowsize = $window.width();
13-
if (windowsize <= 768) {
14-
if ($pane.hasClass('toggled')) {
15-
$pane.toggleClass('toggled');
16-
}
10+
function checkWidth(reload) {
11+
console.log(reload)
12+
if (!reload) {
13+
if ($(window).width() === windowWidth) { //prevents the sidebar being opened on scroll on Apple browsers
14+
checkWidthToggleClass();
1715
}
18-
else if (!$pane.hasClass('toggled')) {
19-
$pane.addClass('toggled');
16+
} else {
17+
checkWidthToggleClass();
18+
}
19+
}
20+
21+
function checkWidthToggleClass() {
22+
var windowsize = $window.width();
23+
if (windowsize <= 768) {
24+
if ($pane.hasClass('toggled')) {
25+
$pane.toggleClass('toggled');
2026
}
2127
}
28+
else if (!$pane.hasClass('toggled')) {
29+
$pane.addClass('toggled');
30+
}
2231
}
2332

2433
// Execute on load
25-
checkWidth();
34+
checkWidth(true);
2635
// Bind event listener
27-
$(window).resize(checkWidth);
36+
$(window).resize(checkWidth(false));
2837
});

0 commit comments

Comments
 (0)