angelovcom.net

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

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


      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 twentynineteen_skip_link_focus_fix() PHP function.
      7  *
      8  * Learn more: https://git.io/vWdr2
      9  */
     10 ( function() {
     11 	var isIe = /(trident|msie)/i.test( navigator.userAgent );
     12 
     13 	if ( isIe && document.getElementById && window.addEventListener ) {
     14 		window.addEventListener( 'hashchange', function() {
     15 			var id = location.hash.substring( 1 ),
     16 				element;
     17 
     18 			if ( ! ( /^[A-z0-9_-]+$/.test( id ) ) ) {
     19 				return;
     20 			}
     21 
     22 			element = document.getElementById( id );
     23 
     24 			if ( element ) {
     25 				if ( ! ( /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) ) {
     26 					element.tabIndex = -1;
     27 				}
     28 
     29 				element.focus();
     30 			}
     31 		}, false );
     32 	}
     33 } )();