From 77faa74b059e2966e80bdd167b7aa0cc370fcb1c Mon Sep 17 00:00:00 2001 From: Ian Dunn Date: Thu, 24 Mar 2022 17:19:23 -0700 Subject: [PATCH] Theme: Remove redundant JS files. These are already being loaded from the parent theme, and have identical copies there. --- README.md | 2 + themes/wporg-5ftf/functions.php | 16 ++++- themes/wporg-5ftf/js/navigation.js | 78 --------------------- themes/wporg-5ftf/js/skip-link-focus-fix.js | 33 --------- 4 files changed, 15 insertions(+), 114 deletions(-) delete mode 100644 themes/wporg-5ftf/js/navigation.js delete mode 100644 themes/wporg-5ftf/js/skip-link-focus-fix.js diff --git a/README.md b/README.md index 4f03a34..6dead0b 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,5 @@ See [the theme README](./themes/wporg-5ftf/README.md) for scripts specific to th The canonical source for this project is [github.com/WordPress/five-for-the-future](https://github.com/WordPress/five-for-the-future). The contents are synced to the dotorg SVN repo to run on production, because we don't deploy directly from GitHub, for reliability reasons. The plugin and theme lives in the private SVN repo instead of `meta.svn.wordpress.org`, because the code is already open-sourced, and we don't want to clutter the Meta logs and Slack channels with noise from "Syncing w/ Git repository..." commits. + +To sync to SVN, run `bin/sync/5ftf.sh` from a w.org sandbox. diff --git a/themes/wporg-5ftf/functions.php b/themes/wporg-5ftf/functions.php index 9010367..3a7d4eb 100644 --- a/themes/wporg-5ftf/functions.php +++ b/themes/wporg-5ftf/functions.php @@ -128,10 +128,20 @@ add_action( 'after_setup_theme', __NAMESPACE__ . '\content_width', 0 ); * Enqueue scripts and styles. */ function scripts() { - wp_enqueue_style( 'wporg-style', get_theme_file_uri( '/css/style.css' ), [ 'dashicons', 'open-sans' ], '2021-05-11' ); + wp_enqueue_style( + 'wporg-style', + get_theme_file_uri( '/css/style.css' ), + [ 'dashicons', 'open-sans' ], + filemtime( __DIR__ . '/css/style.css' ) + ); - wp_enqueue_script( 'wporg-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20181209', true ); - wp_enqueue_script( 'wporg-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true ); + wp_enqueue_script( + 'wporg-navigation', + get_template_directory_uri() . '/js/navigation.js', + array(), + filemtime( get_template_directory() . '/js/navigation.js' ), + true + ); } add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\scripts' ); diff --git a/themes/wporg-5ftf/js/navigation.js b/themes/wporg-5ftf/js/navigation.js deleted file mode 100644 index 1c963cb..0000000 --- a/themes/wporg-5ftf/js/navigation.js +++ /dev/null @@ -1,78 +0,0 @@ -/** - * File navigation.js. - * - * Handles toggling the navigation menu for small screens and enables TAB key - * navigation support for dropdown menus. - */ -( function() { - var container, button, menu, links, subMenus, i, len; - - container = document.getElementById( 'site-navigation' ); - if ( ! container ) { - return; - } - - button = container.getElementsByTagName( 'button' )[0]; - if ( 'undefined' === typeof button ) { - return; - } - - menu = container.getElementsByTagName( 'ul' )[0]; - - // Hide menu toggle button if menu is empty and return early. - if ( 'undefined' === typeof menu ) { - button.style.display = 'none'; - return; - } - - if ( -1 === menu.className.indexOf( 'nav-menu' ) ) { - menu.className += ' nav-menu'; - } - - button.onclick = function() { - if ( -1 !== container.className.indexOf( 'toggled' ) ) { - container.className = container.className.replace( ' toggled', '' ); - button.setAttribute( 'aria-expanded', 'false' ); - } else { - container.className += ' toggled'; - button.setAttribute( 'aria-expanded', 'true' ); - } - }; - - // Get all the link elements within the menu. - links = menu.getElementsByTagName( 'a' ); - subMenus = menu.getElementsByTagName( 'ul' ); - - // Set menu items with submenus to aria-haspopup="true". - for ( i = 0, len = subMenus.length; i < len; i++ ) { - subMenus[i].parentNode.setAttribute( 'aria-haspopup', 'true' ); - } - - // Each time a menu link is focused or blurred, toggle focus. - for ( i = 0, len = links.length; i < len; i++ ) { - links[i].addEventListener( 'focus', toggleFocus, true ); - links[i].addEventListener( 'blur', toggleFocus, true ); - } - - /** - * Sets or removes .focus class on an element. - */ - function toggleFocus() { - var self = this; - - // Move up through the ancestors of the current link until we hit .nav-menu. - while ( -1 === self.className.indexOf( 'nav-menu' ) ) { - - // On li elements toggle the class .focus. - if ( 'li' === self.tagName.toLowerCase() ) { - if ( -1 !== self.className.indexOf( 'focus' ) ) { - self.className = self.className.replace( ' focus', '' ); - } else { - self.className += ' focus'; - } - } - - self = self.parentElement; - } - } -} )(); diff --git a/themes/wporg-5ftf/js/skip-link-focus-fix.js b/themes/wporg-5ftf/js/skip-link-focus-fix.js deleted file mode 100644 index a39cefb..0000000 --- a/themes/wporg-5ftf/js/skip-link-focus-fix.js +++ /dev/null @@ -1,33 +0,0 @@ -/** - * File skip-link-focus-fix.js. - * - * Helps with accessibility for keyboard only users. - * - * Learn more: https://git.io/vWdr2 - */ -( function() { - var isWebkit = navigator.userAgent.toLowerCase().indexOf( 'webkit' ) > -1, - isOpera = navigator.userAgent.toLowerCase().indexOf( 'opera' ) > -1, - isIe = navigator.userAgent.toLowerCase().indexOf( 'msie' ) > -1; - - if ( ( isWebkit || isOpera || isIe ) && document.getElementById && window.addEventListener ) { - window.addEventListener( 'hashchange', function() { - var id = location.hash.substring( 1 ), - element; - - if ( ! ( /^[A-z0-9_-]+$/.test( id ) ) ) { - return; - } - - element = document.getElementById( id ); - - if ( element ) { - if ( ! ( /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) ) { - element.tabIndex = -1; - } - - element.focus(); - } - }, false ); - } -})();