1/** 2 * Reimplements functionality specific to the base theme, Twenty Thirteen, without jQuery. 3 * Does not fully reimplement everything, just the portions relevant to the ma.tt theme. 4 */ 5 6( function () { 7 'use strict'; 8 9 const nav = document.querySelector( '#site-navigation' ); 10 const button = nav && nav.querySelector( '.menu-toggle' ); 11 const menu = nav && nav.querySelector( '.nav-menu' ); 12 13 /** 14 * Enables menu toggle for small screens. 15 */ 16 ( function () { 17 if ( ! nav || ! button ) { 18 return; 19 } 20 21 // Hide button if menu is missing or empty. 22 if ( ! menu || menu.childElementCount === 0 ) { 23 button.style.display = 'none'; 24 return; 25 } 26 27 button.addEventListener( 'click', () => { 28 nav.classList.toggle( 'toggled-on' ); 29 if ( nav.classList.contains( 'toggled-on' ) ) { 30 button.setAttribute( 'aria-expanded', 'true' ); 31 menu.setAttribute( 'aria-expanded', 'true' ); 32 } else { 33 button.setAttribute( 'aria-expanded', 'false' ); 34 menu.setAttribute( 'aria-expanded', 'false' ); 35 } 36 } ); 37 38 // Fix sub-menus for touch devices. 39 if ( 'ontouchstart' in window ) { 40 const childLinks = menu.querySelectorAll( 41 '.menu-item-has-children > a, .page_item_has_children > a' 42 ); 43 childLinks.forEach( ( childLink ) => { 44 childLink.addEventListener( 'click', ( e ) => { 45 const el = childLink.closest( 'li' ); 46 47 if ( el && ! el.classList.contains( 'focus' ) ) { 48 e.preventDefault(); 49 el.classList.add( 'focus' ); 50 el.parentElement.children.forEach( ( sibling ) => { 51 if ( sibling !== el ) { 52 sibling.classList.remove( 'focus' ); 53 } 54 } ); 55 } 56 } ); 57 } ); 58 } 59 60 // Better focus for hidden submenu items for accessibility. 61 const links = menu.querySelectorAll( 'a' ); 62 links.forEach( ( link ) => { 63 const handleFocusChange = () => { 64 link.closest( '.menu-item, .page_item' ).classList.toggle( 'focus' ); 65 }; 66 link.addEventListener( 'focus', handleFocusChange ); 67 link.addEventListener( 'blur', handleFocusChange ); 68 } ); 69 } )(); 70 71 /** 72 * Add or remove ARIA attributes. 73 */ 74 function onResizeARIA() { 75 if ( 643 > window.innerWidth ) { 76 button.setAttribute( 'aria-expanded', 'false' ); 77 menu.setAttribute( 'aria-expanded', 'false' ); 78 button.setAttribute( 'aria-controls', 'primary-menu' ); 79 } else { 80 button.removeAttribute( 'aria-expanded' ); 81 menu.removeAttribute( 'aria-expanded' ); 82 button.removeAttribute( 'aria-controls' ); 83 } 84 } 85 86 window.addEventListener( 'load', onResizeARIA ); 87 window.addEventListener( 'resize', onResizeARIA ); 88} )();
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.