Nenhuma Descrição

skip-link-focus-fix.js 832B

123456789101112131415161718192021222324252627282930313233343536
  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. if ( isIe && document.getElementById && window.addEventListener ) {
  15. window.addEventListener( 'hashchange', 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. }, false );
  29. }
  30. }() );