Make WordPress Core

Ticket #45424: 45424.13.patch

File 45424.13.patch, 3.1 KB (added by allancole, 6 years ago)

Print skip-link-focus-fix inline instead of enqueueing as blocking script. More info here: https://github.com/WordPress/twentynineteen/pull/47

  • src/wp-content/themes/twentynineteen/functions.php

     
    221221
    222222        wp_style_add_data( 'twentynineteen-style', 'rtl', 'replace' );
    223223
    224         wp_enqueue_script( 'twentynineteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
    225 
    226224        if ( has_nav_menu( 'menu-1' ) ) {
    227225                wp_enqueue_script( 'twentynineteen-priority-menu', get_theme_file_uri( '/js/priority-menu.js' ), array(), '1.0', true );
    228226                wp_enqueue_script( 'twentynineteen-touch-navigation', get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), array(), '1.0', true );
     
    237235add_action( 'wp_enqueue_scripts', 'twentynineteen_scripts' );
    238236
    239237/**
     238 * Fix skip link focus in IE11.
     239 *
     240 * This does not enqueue the script because it is tiny and because it is only for IE11,
     241 * thus it does not warrant having an entire dedicated blocking script being loaded.
     242 *
     243 * @link https://git.io/vWdr2
     244 */
     245function twentynineteen_skip_link_focus_fix() {
     246        // The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`.
     247        ?>
     248        <script>
     249        /(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1);
     250        </script>
     251        <?php
     252}
     253add_action( 'wp_print_footer_scripts', 'twentynineteen_skip_link_focus_fix' );
     254
     255/**
    240256 * Enqueue supplemental block editor styles.
    241257 */
    242258function twentynineteen_editor_customizer_styles() {
     
    263279
    264280        require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
    265281
    266         if ( 'default' === get_theme_mod( 'primary_color', 'default' ) ) {
    267                 $primary_color = 199;
    268         } else {
    269                 $primary_color = absint( get_theme_mod( 'primary_color_hue', 199 ) );
     282        $primary_color = 199;
     283        if ( 'default' !== get_theme_mod( 'primary_color', 'default' ) ) {
     284                $primary_color = get_theme_mod( 'primary_color_hue', 199 );
    270285        }
    271286        ?>
    272287
    273         <style type="text/css" id="custom-theme-colors" <?php echo is_customize_preview() ? 'data-hue="' . $primary_color . '"' : ''; ?>>
     288        <style type="text/css" id="custom-theme-colors" <?php echo is_customize_preview() ? 'data-hue="' . absint( $primary_color ) . '"' : ''; ?>>
    274289                <?php echo twentynineteen_custom_colors_css(); ?>
    275290        </style>
    276291        <?php
  • src/wp-content/themes/twentynineteen/js/skip-link-focus-fix.js

     
    33 *
    44 * Helps with accessibility for keyboard only users.
    55 *
     6 * This is the source file for what is minified in the twentynineteen_skip_link_focus_fix() PHP function.
     7 *
    68 * Learn more: https://git.io/vWdr2
    79 */
    810( function() {