diff --git a/src/wp-content/themes/twentysixteen/functions.php b/src/wp-content/themes/twentysixteen/functions.php index d098a1ebde927..6053fe6c03d22 100644 --- a/src/wp-content/themes/twentysixteen/functions.php +++ b/src/wp-content/themes/twentysixteen/functions.php @@ -412,10 +412,10 @@ function twentysixteen_scripts() { } if ( is_singular() && wp_attachment_is_image() ) { - wp_enqueue_script( 'twentysixteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20170530' ); + wp_enqueue_script( 'twentysixteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array(), '20220209', true ); } - wp_enqueue_script( 'twentysixteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20211130', true ); + wp_enqueue_script( 'twentysixteen-script', get_template_directory_uri() . '/js/functions.js', array(), '20220209', true ); wp_localize_script( 'twentysixteen-script', diff --git a/src/wp-content/themes/twentysixteen/js/functions.js b/src/wp-content/themes/twentysixteen/js/functions.js index 4c3b97d0329f7..bc6e1e8129e06 100644 --- a/src/wp-content/themes/twentysixteen/js/functions.js +++ b/src/wp-content/themes/twentysixteen/js/functions.js @@ -4,210 +4,294 @@ * * Contains handlers for navigation and widget area. */ + ( function () { + 'use strict'; -( function( $ ) { - var body, masthead, menuToggle, siteNavigation, socialNavigation, siteHeaderMenu, resizeTimer; + var mainNav, masthead, menuToggle, siteNavigation, socialNavigation, siteHeaderMenu, resizeTimer; + + function matches( el, sel ) { + if ( Element.prototype.matches ) { + return el.matches( sel ); + } + + if ( Element.prototype.msMatchesSelector ) { + return el.msMatchesSelector( sel ); + } + } + + // Based on https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill + function closest( el, sel ) { + if ( el.closest ) { + return el.closest( sel ); + } + + var current = el; + + do { + if ( matches( el, sel ) ) { + return current; + } + current = current.parentElement || current.parentNode; + } while ( current !== null && current.nodeType === 1 ); + + return null; + } + + function forEachNode( parent, selector, fn ) { + var nodes = parent.querySelectorAll( selector ); + for ( var i = 0; i < nodes.length; i++ ) { + fn( nodes[ i ] ); + } + } function initMainNavigation( container ) { + forEachNode( container, '.menu-item-has-children > a', function ( el ) { + // Add dropdown toggle that displays child menu items. + var dropdownToggle = document.createElement( 'button' ); + dropdownToggle.className = 'dropdown-toggle'; + dropdownToggle.setAttribute( 'aria-expanded', 'false' ); + + var span = document.createElement( 'span' ); + span.className = 'screen-reader-text'; + span.textContent = screenReaderText.expand; - // Add dropdown toggle that displays child menu items. - var dropdownToggle = $( '