skip-link-focus-fix.js 882 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Helps with accessibility for keyboard only users.
  3. *
  4. * Learn more: https://git.io/vWdr2
  5. *
  6. * @package Pen
  7. */
  8. ;( function() {
  9. var isWebkit = navigator.userAgent.toLowerCase().indexOf( 'webkit' ) > -1,
  10. isOpera = navigator.userAgent.toLowerCase().indexOf( 'opera' ) > -1,
  11. isIe = navigator.userAgent.toLowerCase().indexOf( 'msie' ) > -1;
  12. if ( ( isWebkit || isOpera || isIe ) && document.getElementById && window.addEventListener ) {
  13. window.addEventListener(
  14. 'hashchange',
  15. function() {
  16. var id = location.hash.substring( 1 ),
  17. element;
  18. if ( ! ( /^[A-z0-9_-]+$/.test( id ) ) ) {
  19. return;
  20. }
  21. element = document.getElementById( id );
  22. if ( element ) {
  23. if ( ! ( /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) ) {
  24. element.tabIndex = -1;
  25. }
  26. element.focus();
  27. }
  28. },
  29. false
  30. );
  31. }
  32. })();