Skip to content

Commit 0d87f7a

Browse files
committed
ui: navigation: handle responsiveCutoff
1 parent 5715940 commit 0d87f7a

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

packages/ui-default/components/navigation/navigation.page.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import $ from 'jquery';
2+
import responsiveCutoff from 'vj/breakpoints.json';
23
import Notification from 'vj/components/notification';
34
import selectUser from 'vj/components/selectUser';
45
import { AutoloadPage } from 'vj/misc/Page';
@@ -30,7 +31,7 @@ let $menu;
3031

3132
function handleNavbar() {
3233
let fromHide = false;
33-
if ($(document).width() <= 600) {
34+
if ($(document).width() <= responsiveCutoff.mobile) {
3435
$menu.children().each(function () {
3536
const $ele = $(this);
3637
$ele.addClass('nav__list-item').removeClass('menu__item');
@@ -94,11 +95,16 @@ const navigationPage = new AutoloadPage('navigationPage', () => {
9495
const PADDING = 200;
9596
const TOLERANCE = 70;
9697

98+
function isMobileLayout() {
99+
return $(document).width() <= responsiveCutoff.mobile;
100+
}
101+
97102
function setTranslateX(x) {
98103
panel.style.transform = x ? `translateX(${x}px)` : '';
99104
}
100105

101106
function open() {
107+
if (!isMobileLayout()) return;
102108
isOpen = true;
103109
$('html').addClass('slideout-open');
104110
setTranslateX(-PADDING);
@@ -108,6 +114,9 @@ const navigationPage = new AutoloadPage('navigationPage', () => {
108114

109115
function close() {
110116
isOpen = false;
117+
isSwiping = false;
118+
isScrolling = false;
119+
panel.style.transition = '';
111120
setTranslateX(0);
112121
$hamburger.removeClass('is-active');
113122
$slideoutOverlay.hide();
@@ -122,7 +131,7 @@ const navigationPage = new AutoloadPage('navigationPage', () => {
122131
let isScrolling = false;
123132

124133
panel.addEventListener('touchstart', (e) => {
125-
if (e.target.closest('[data-slideout-ignore]')) return;
134+
if (!isMobileLayout() || e.target.closest('[data-slideout-ignore]')) return;
126135
touchStartX = e.touches[0].clientX;
127136
touchStartY = e.touches[0].clientY;
128137
touchCurrentX = touchStartX;
@@ -131,6 +140,7 @@ const navigationPage = new AutoloadPage('navigationPage', () => {
131140
}, { passive: true });
132141

133142
panel.addEventListener('touchmove', (e) => {
143+
if (!isMobileLayout()) return;
134144
touchCurrentX = e.touches[0].clientX;
135145
const dx = touchStartX - touchCurrentX;
136146
if (!isSwiping) {
@@ -155,7 +165,7 @@ const navigationPage = new AutoloadPage('navigationPage', () => {
155165
}, { passive: true });
156166

157167
panel.addEventListener('touchend', () => {
158-
if (!isSwiping) return;
168+
if (!isMobileLayout() || !isSwiping) return;
159169
panel.style.transition = '';
160170
const dx = touchStartX - touchCurrentX;
161171
if (isOpen) {
@@ -170,7 +180,10 @@ const navigationPage = new AutoloadPage('navigationPage', () => {
170180

171181
$slideoutOverlay.on('click', close);
172182
$('.header__hamburger').on('click', () => (isOpen ? close() : open()));
173-
$(window).on('resize', handleNavbar);
183+
$(window).on('resize', () => {
184+
handleNavbar();
185+
if (!isMobileLayout()) close();
186+
});
174187
setInterval(handleNavbar, 3000);
175188
}, () => {
176189
$trigger = $(tpl`

0 commit comments

Comments
 (0)