Skip to content

Commit

Permalink
backbutton fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred Heusschen committed Dec 23, 2022
1 parent 2eb2f02 commit 5372a84
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions dist/addons/backbutton/mmenu.backbutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@ export default function () {
const _menu = `#${this.node.menu.id}`;
// Close menu
if (options.close) {
var states = [];
let states = [];
const setStates = () => {
states = [_menu];
DOM.children(this.node.pnls, '.mm-panel--opened, .mm-panel--parent').forEach((panel) => {
states.push('#' + panel.id);
});
};
this.bind('open:after', () => {
history.pushState(null, document.title, _menu);
history.pushState(null, '', location.pathname + location.search + _menu);
});
this.bind('open:after', setStates);
this.bind('openPanel:after', setStates);
this.bind('close:after', () => {
states = [];
history.back();
history.pushState(null, document.title, location.pathname + location.search);
history.pushState(null, '', location.pathname + location.search);
});
window.addEventListener('popstate', (evnt) => {
window.addEventListener('popstate', () => {
if (this.node.menu.matches('.mm-menu--opened')) {
if (states.length) {
states = states.slice(0, -1);
var hash = states[states.length - 1];
const hash = states[states.length - 1];
if (hash == _menu) {
this.close();
}
else {
this.openPanel(this.node.menu.querySelector(hash));
history.pushState(null, document.title, _menu);
history.pushState(null, '', location.pathname + location.search + _menu);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/mmenu.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mmenu-js",
"version": "9.2.2",
"version": "9.2.3",
"main": "dist/mmenu.js",
"module": "src/mmenu.js",
"author": "Fred Heusschen <[email protected]>",
Expand Down
12 changes: 6 additions & 6 deletions src/addons/backbutton/mmenu.backbutton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function (this: Mmenu) {

// Close menu
if (options.close) {
var states = [];
let states = [];

const setStates = () => {
states = [_menu];
Expand All @@ -31,7 +31,7 @@ export default function (this: Mmenu) {
};

this.bind('open:after', () => {
history.pushState(null, document.title, _menu);
history.pushState(null, '', location.pathname + location.search + _menu);
});
this.bind('open:after', setStates);
this.bind('openPanel:after', setStates);
Expand All @@ -40,22 +40,22 @@ export default function (this: Mmenu) {
history.back();
history.pushState(
null,
document.title,
'',
location.pathname + location.search
);
});

window.addEventListener('popstate', (evnt) => {
window.addEventListener('popstate', () => {
if (this.node.menu.matches('.mm-menu--opened')) {
if (states.length) {
states = states.slice(0, -1);
var hash = states[states.length - 1];
const hash = states[states.length - 1];

if (hash == _menu) {
this.close();
} else {
this.openPanel(this.node.menu.querySelector(hash));
history.pushState(null, document.title, _menu);
history.pushState(null, '', location.pathname + location.search + _menu);
}
}
}
Expand Down

0 comments on commit 5372a84

Please sign in to comment.