balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

skip-link-focus-fix.js (832B)


      1 /**
      2  * File skip-link-focus-fix.js.
      3  *
      4  * Helps with accessibility for keyboard only users.
      5  *
      6  * This is the source file for what is minified in the twenty_twenty_one_skip_link_focus_fix() PHP function.
      7  *
      8  * Learn more: https://git.io/vWdr2
      9  *
     10  * @since Twenty Twenty-One 1.0
     11  */
     12 ( function() {
     13 	var isIe = /(trident|msie)/i.test( navigator.userAgent );
     14 
     15 	if ( isIe && document.getElementById && window.addEventListener ) {
     16 		window.addEventListener( 'hashchange', function() {
     17 			var id = location.hash.substring( 1 ),
     18 				element;
     19 
     20 			if ( ! ( /^[A-z0-9_-]+$/.test( id ) ) ) {
     21 				return;
     22 			}
     23 
     24 			element = document.getElementById( id );
     25 
     26 			if ( element ) {
     27 				if ( ! ( /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) ) {
     28 					element.tabIndex = -1;
     29 				}
     30 
     31 				element.focus();
     32 			}
     33 		}, false );
     34 	}
     35 }() );