summaryrefslogtreecommitdiff
path: root/src/js/skip-link-focus-fix.js
diff options
context:
space:
mode:
authorMax2017-05-18 14:03:27 +0200
committerMax2017-05-18 14:03:27 +0200
commitf597e2fe949a1e18eb778b9a5bd102de88570555 (patch)
tree7e42e6f91dd3e764cd2cf0c4f61f48501c2ed98f /src/js/skip-link-focus-fix.js
downloaddocs.maxmail.xyz-f597e2fe949a1e18eb778b9a5bd102de88570555.tar.gz
Initial commit.HEADmaster
Diffstat (limited to 'src/js/skip-link-focus-fix.js')
-rw-r--r--src/js/skip-link-focus-fix.js33
1 files changed, 33 insertions, 0 deletions
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 );
+ }
+})();