skip-link-focus-fix.js 751 B

1234567891011121314151617181920212223242526
  1. ( function() {
  2. var is_webkit = navigator.userAgent.toLowerCase().indexOf( 'webkit' ) > -1,
  3. is_opera = navigator.userAgent.toLowerCase().indexOf( 'opera' ) > -1,
  4. is_ie = navigator.userAgent.toLowerCase().indexOf( 'msie' ) > -1;
  5. if ( ( is_webkit || is_opera || is_ie ) && document.getElementById && window.addEventListener ) {
  6. window.addEventListener( 'hashchange', function() {
  7. var id = location.hash.substring( 1 ),
  8. element;
  9. if ( ! ( /^[A-z0-9_-]+$/.test( id ) ) ) {
  10. return;
  11. }
  12. element = document.getElementById( id );
  13. if ( element ) {
  14. if ( ! ( /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) ) {
  15. element.tabIndex = -1;
  16. }
  17. element.focus();
  18. }
  19. }, false );
  20. }
  21. })();