skip-link-focus-fix.js 852 B

1234567891011121314151617181920212223242526
  1. /**
  2. * Makes "skip to content" link work correctly in IE9, Chrome, and Opera
  3. * for better accessibility.
  4. *
  5. * @link http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/
  6. */
  7. ( function() {
  8. var is_webkit = navigator.userAgent.toLowerCase().indexOf( 'webkit' ) > -1,
  9. is_opera = navigator.userAgent.toLowerCase().indexOf( 'opera' ) > -1,
  10. is_ie = navigator.userAgent.toLowerCase().indexOf( 'msie' ) > -1;
  11. if ( ( is_webkit || is_opera || is_ie ) && document.getElementById && window.addEventListener ) {
  12. window.addEventListener( 'hashchange', function() {
  13. var element = document.getElementById( location.hash.substring( 1 ) );
  14. if ( element ) {
  15. if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) {
  16. element.tabIndex = -1;
  17. }
  18. element.focus();
  19. }
  20. }, false );
  21. }
  22. } )();