themes-wordpress/varia/js/primary-navigation.js
2020-12-17 11:36:48 +01:00

39 lines
No EOL
1,000 B
JavaScript

/**
* File primary-navigation.js.
*
* Locks scroll when the menu is opened on mobile
*/
( function() {
/**
* Menu Toggle Behaviors
*
* @param {Element} element
*/
var navMenu = function ( id ){
var wrapper = document.body; // this is the element to which a CSS class is added when a mobile nav menu is open
if (wrapper.classList.contains('mobile-nav-side')) {
var toggleButton = document.getElementById( 'toggle-menu' );
var toggleInput = document.getElementById( 'toggle' );
if ( toggleButton ){
toggleButton.onclick = function() {
if (toggleInput.checked == true){
wrapper.classList.remove( `${ id }-navigation-open` );
wrapper.classList.remove( 'lock-scrolling' );
} else {
wrapper.classList.add( `${ id }-navigation-open` );
wrapper.classList.add( 'lock-scrolling' );
}
toggleButton.focus();
}
}
}
}
window.addEventListener( 'load', function() {
new navMenu( 'primary' );
});
} )();