An updated theme (based on Atticus Finch) for ClassicPress
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
912 B

3 years ago
  1. /**
  2. * skip-link-focus-fix.js
  3. *
  4. * Helps with accessibility for keyboard only users.
  5. *
  6. * Learn more: https://github.com/Automattic/Atticus Finch/pull/136
  7. */
  8. ( function() {
  9. var is_webkit = navigator.userAgent.toLowerCase().indexOf( 'webkit' ) > -1,
  10. is_opera = navigator.userAgent.toLowerCase().indexOf( 'opera' ) > -1,
  11. is_ie = navigator.userAgent.toLowerCase().indexOf( 'msie' ) > -1;
  12. if ( ( is_webkit || is_opera || is_ie ) && document.getElementById && window.addEventListener ) {
  13. window.addEventListener( 'hashchange', function() {
  14. var id = location.hash.substring( 1 ),
  15. element;
  16. if ( ! ( /^[A-z0-9_-]+$/.test( id ) ) ) {
  17. return;
  18. }
  19. element = document.getElementById( id );
  20. if ( element ) {
  21. if ( ! ( /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) ) {
  22. element.tabIndex = -1;
  23. }
  24. element.focus();
  25. }
  26. }, false );
  27. }
  28. })();