1
0
mirror of https://github.com/picocms/pico-theme.git synced 2025-01-16 20:08:13 +01:00

JavaScript: Don't setup nav toggle when there's no menu

This commit is contained in:
Daniel Rudolf 2020-08-29 17:07:41 +02:00
parent e385f2ba0e
commit 6821662127
No known key found for this signature in database
GPG Key ID: A061F02CD8DE4538

View File

@ -28,10 +28,12 @@ function main()
// responsive menu
var menu = document.getElementById('nav'),
menuToggle = document.getElementById('nav-toggle'),
toggleMenuEvent = function (event) {
menuToggle = document.getElementById('nav-toggle');
if (menu && menuToggle) {
function toggleMenuEvent(event) {
if (event.type === 'keydown') {
if ((event.keyCode != 13) && (event.keyCode != 32)) {
if ((event.keyCode !== 13) && (event.keyCode !== 32)) {
return;
}
}
@ -49,8 +51,9 @@ function main()
menuToggle.setAttribute('aria-expanded', 'false');
utils.slideUp(menu);
}
},
onResizeEvent = function () {
}
function onResizeEvent() {
if (utils.isElementVisible(menuToggle)) {
menu.className = 'hidden';
menuToggle.addEventListener('click', toggleMenuEvent);
@ -61,10 +64,11 @@ function main()
menuToggle.removeEventListener('click', toggleMenuEvent);
menuToggle.removeEventListener('keydown', toggleMenuEvent);
}
};
}
window.addEventListener('resize', onResizeEvent);
onResizeEvent();
window.addEventListener('resize', onResizeEvent);
onResizeEvent();
}
}
main();