From 00c9709fd9763542e848f6278db8ba26af5c9886 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 15 Oct 2018 23:46:42 +0200 Subject: Initial commit. --- src/js/skip-link-focus-fix.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/js/skip-link-focus-fix.js (limited to 'src/js/skip-link-focus-fix.js') diff --git a/src/js/skip-link-focus-fix.js b/src/js/skip-link-focus-fix.js new file mode 100644 index 0000000..a39cefb --- /dev/null +++ b/src/js/skip-link-focus-fix.js @@ -0,0 +1,33 @@ +/** + * File skip-link-focus-fix.js. + * + * Helps with accessibility for keyboard only users. + * + * Learn more: https://git.io/vWdr2 + */ +( function() { + var isWebkit = navigator.userAgent.toLowerCase().indexOf( 'webkit' ) > -1, + isOpera = navigator.userAgent.toLowerCase().indexOf( 'opera' ) > -1, + isIe = navigator.userAgent.toLowerCase().indexOf( 'msie' ) > -1; + + if ( ( isWebkit || isOpera || isIe ) && document.getElementById && window.addEventListener ) { + window.addEventListener( 'hashchange', function() { + var id = location.hash.substring( 1 ), + element; + + if ( ! ( /^[A-z0-9_-]+$/.test( id ) ) ) { + return; + } + + element = document.getElementById( id ); + + if ( element ) { + if ( ! ( /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) ) { + element.tabIndex = -1; + } + + element.focus(); + } + }, false ); + } +})(); -- cgit v1.2.3