1function ready() { 2 3 const menuToggle = document.querySelector('.menu-toggle'); 4 const menu = document.getElementById('menu'); 5 6 if(!menuToggle || !menu) return; 7 8 function inert(value) { 9 10 document.querySelectorAll('main.main, footer.footer, .signup').forEach((el) => el.inert = value); 11 12 } 13 14 function open() { 15 16 document.documentElement.classList.add('menu-open'); 17 menuToggle.setAttribute('aria-expanded', 'true'); 18 menuToggle.setAttribute('aria-label', 'Close navigation'); 19 20 inert(true); 21 22 } 23 24 function close() { 25 26 const wasOpen = document.documentElement.classList.contains('menu-open'); 27 const hadFocus = menu.contains(document.activeElement); 28 29 document.documentElement.classList.remove('menu-open'); 30 menuToggle.setAttribute('aria-expanded', 'false'); 31 menuToggle.setAttribute('aria-label', 'Open navigation'); 32 33 inert(false); 34 35 if(wasOpen && hadFocus) menuToggle.focus(); 36 37 } 38 39 menuToggle.addEventListener('click', () => { 40 41 document.documentElement.classList.contains('menu-open') ? close() : open(); 42 43 }); 44 45 menu.addEventListener('click', (e) => { 46 47 if(e.target !== menu) return; 48 49 close(); 50 51 menuToggle.focus(); 52 53 }); 54 55 document.addEventListener('focusin', (e) => { 56 57 if(menu.contains(e.target) || menuToggle.contains(e.target)) return; 58 59 close(); 60 61 }); 62 63 addEventListener('pageshow', close); 64 65 matchMedia('(min-width: 64em)').addEventListener('change', (e) => { 66 67 if(e.matches) close(); 68 69 }); 70 71 document.addEventListener('keydown', (e) => { 72 73 if(e.key === 'Escape') close(); 74 75 }); 76 77} 78 79export { ready };
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.