This repository has been archived on 2020-05-08. You can view files and clone it, but cannot push or open issues or pull requests.
understrap/js/skip-link-focus-fix.js

34 lines
880 B
JavaScript
Raw Normal View History

2015-08-12 07:06:27 +00:00
/**
2016-03-10 12:52:48 +00:00
* File skip-link-focus-fix.js.
2015-08-12 07:06:27 +00:00
*
* Helps with accessibility for keyboard only users.
*
* Learn more: https://git.io/vWdr2
2015-08-12 07:06:27 +00:00
*/
2014-12-10 11:36:38 +00:00
( function() {
2016-03-10 12:52:48 +00:00
var isWebkit = navigator.userAgent.toLowerCase().indexOf( 'webkit' ) > -1,
isOpera = navigator.userAgent.toLowerCase().indexOf( 'opera' ) > -1,
isIe = navigator.userAgent.toLowerCase().indexOf( 'msie' ) > -1;
2014-12-10 11:36:38 +00:00
2016-03-10 12:52:48 +00:00
if ( ( isWebkit || isOpera || isIe ) && document.getElementById && window.addEventListener ) {
2014-12-10 11:36:38 +00:00
window.addEventListener( 'hashchange', function() {
2015-08-12 07:06:27 +00:00
var id = location.hash.substring( 1 ),
element;
if ( ! ( /^[A-z0-9_-]+$/.test( id ) ) ) {
return;
}
element = document.getElementById( id );
2014-12-10 11:36:38 +00:00
if ( element ) {
2015-08-12 07:06:27 +00:00
if ( ! ( /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) ) {
2014-12-10 11:36:38 +00:00
element.tabIndex = -1;
2015-08-12 07:06:27 +00:00
}
2014-12-10 11:36:38 +00:00
element.focus();
}
}, false );
}
})();