skip-link-focus-fix.js 727 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 ua = navigator.userAgent.toLowerCase();
  9. if ( ( ua.indexOf( 'webkit' ) > -1 || ua.indexOf( 'opera' ) > -1 || ua.indexOf( 'msie' ) > -1 ) &&
  10. document.getElementById && window.addEventListener ) {
  11. window.addEventListener( 'hashchange', function() {
  12. var element = document.getElementById( location.hash.substring( 1 ) );
  13. if ( element ) {
  14. if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.nodeName ) ) {
  15. element.tabIndex = -1;
  16. }
  17. element.focus();
  18. }
  19. }, false );
  20. }
  21. } )();