2015-07-01 15:21:44 +00:00
|
|
|
/**
|
|
|
|
* skip-link-focus-fix.js
|
|
|
|
*
|
2015-08-03 19:14:14 +00:00
|
|
|
* Helps with accessibility for keyboard only users.
|
2015-07-01 15:21:44 +00:00
|
|
|
*
|
2015-10-29 17:25:18 +00:00
|
|
|
* Learn more: https://git.io/vWdr2
|
2015-07-01 15:21:44 +00:00
|
|
|
*/
|
2013-01-22 00:01:53 +00:00
|
|
|
( function() {
|
2013-03-05 00:41:38 +00:00
|
|
|
var is_webkit = navigator.userAgent.toLowerCase().indexOf( 'webkit' ) > -1,
|
|
|
|
is_opera = navigator.userAgent.toLowerCase().indexOf( 'opera' ) > -1,
|
|
|
|
is_ie = navigator.userAgent.toLowerCase().indexOf( 'msie' ) > -1;
|
2013-03-07 14:10:13 +00:00
|
|
|
|
2014-04-15 09:40:29 +00:00
|
|
|
if ( ( is_webkit || is_opera || is_ie ) && document.getElementById && window.addEventListener ) {
|
|
|
|
window.addEventListener( 'hashchange', function() {
|
2015-02-17 17:52:36 +00:00
|
|
|
var id = location.hash.substring( 1 ),
|
|
|
|
element;
|
|
|
|
|
2015-02-23 10:48:50 +00:00
|
|
|
if ( ! ( /^[A-z0-9_-]+$/.test( id ) ) ) {
|
2015-02-17 17:52:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
element = document.getElementById( id );
|
2013-03-07 14:10:13 +00:00
|
|
|
|
2013-03-05 00:41:38 +00:00
|
|
|
if ( element ) {
|
2015-02-23 10:48:50 +00:00
|
|
|
if ( ! ( /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) ) {
|
2013-03-05 00:41:38 +00:00
|
|
|
element.tabIndex = -1;
|
2014-12-24 05:19:34 +00:00
|
|
|
}
|
2013-03-07 14:10:13 +00:00
|
|
|
|
2013-03-05 00:41:38 +00:00
|
|
|
element.focus();
|
|
|
|
}
|
2013-03-07 14:10:13 +00:00
|
|
|
}, false );
|
2013-03-05 00:41:38 +00:00
|
|
|
}
|
2013-01-22 00:01:53 +00:00
|
|
|
})();
|