const mobileMenu=(()=>{let focusable let firstFocusable let lastFocusable function keyHandler(event){event=event||window.event if(document.documentElement.dataset.menuState!=='on')return false const tabKey=9 const escKey=27 switch(event.keyCode){case tabKey:if(focusable.length===1){event.preventDefault() break} if(event.shiftKey){if(document.activeElement===firstFocusable){event.preventDefault() lastFocusable.focus()}}else{if(document.activeElement===lastFocusable){event.preventDefault() firstFocusable.focus()}} break case escKey:document.documentElement.dataset.menuState='off' allowFocus('[data-menu]',false) break default:break}} function clickHandler(event){if(event.target.closest('[data-menu-toggle]')){document.documentElement.dataset.menuState=document.documentElement.dataset.menuState==='on'?'off':'on' if(document.documentElement.dataset.menuState==='on'){sessionStorage.setItem('scroll-position',document.documentElement.scrollTop) document.documentElement.dataset.scrollDisabled='on' allowFocus('[data-menu]',true) trapFocus()}else{document.documentElement.dataset.scrollDisabled='off' document.documentElement.scrollTop=sessionStorage.getItem('scroll-position') allowFocus('[data-menu]',false)}}} function allowFocus(selector,state){const container=document.querySelector(selector) const focusable=container.querySelectorAll('button, [href], input, select, textarea') focusable.forEach(el=>el.setAttribute('tabindex',state?'':'-1')) container.classList.toggle('hidden')} function trapFocus(){focusable=document.querySelector('[data-menu-container]').querySelectorAll('a[href]:not([tabindex="-1"]), area[href]:not([tabindex="-1"]), input:not([disabled]):not([tabindex="-1"]), select:not([disabled]):not([tabindex="-1"]), textarea:not([disabled]):not([tabindex="-1"]), button:not([disabled]):not([tabindex="-1"]), iframe:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"]), [contentEditable=true]:not([tabindex="-1"])') firstFocusable=focusable[0] lastFocusable=focusable[focusable.length-1]} document.addEventListener('click',clickHandler,false) document.addEventListener('keydown',keyHandler,false)})()