Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,35 +1 @@
/**
* File skip-link-focus-fix.js.
*
* Helps with accessibility for keyboard only users.
*
* This is the source file for what is minified in the twenty_twenty_one_skip_link_focus_fix() PHP function.
*
* Learn more: https://git.io/vWdr2
*
* @since Twenty Twenty-One 1.0
*/
( function() {
var isIe = /(trident|msie)/i.test( navigator.userAgent );

if ( 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 );
}
}() );
// Internet Explorer support was removed.
23 changes: 6 additions & 17 deletions src/wp-content/themes/twentytwentyone/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,31 +486,20 @@ function twentytwentyone_block_editor_script() {
add_action( 'enqueue_block_editor_assets', 'twentytwentyone_block_editor_script' );

/**
* Fixes skip link focus in IE11.
* Adds an HTML comment about the lack of Internet Explorer support.
*
* This does not enqueue the script because it is tiny and because it is only for IE11,
* thus it does not warrant having an entire dedicated blocking script being loaded.
* This originally printed a script to fix the skip link focus behavior in IE11.
*
* @since Twenty Twenty-One 1.0
* @deprecated Twenty Twenty-One 1.9 Removed from wp_print_footer_scripts action.
* @deprecated Twenty Twenty-One 2.8 Removed Internet Explorer support.
*
* @link https://git.io/vWdr2
*/
function twenty_twenty_one_skip_link_focus_fix() {

// If SCRIPT_DEBUG is defined and true, print the unminified file.
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
echo '<script>';
include get_template_directory() . '/assets/js/skip-link-focus-fix.js';
echo '</script>';
} else {
// The following is minified via `npx terser --compress --mangle -- assets/js/skip-link-focus-fix.js`.
?>
<script>
/(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);
</script>
<?php
}
?>
<!-- Internet Explorer support was removed. -->
<?php
}

/**
Expand Down
Loading