| @@ -1,0 +1,19 @@ | ||
| 1 | +var keyboardNavigation = false, | |
| 2 | + keyboardNavigationKeycodes = [ 9, 32, 37, 38, 39, 40 ]; // keyCodes for tab, space, left, up, right, down respectively | |
| 3 | + | |
| 4 | +document.addEventListener( 'keydown', function ( event ) { | |
| 5 | + if ( keyboardNavigation ) { | |
| 6 | + return; | |
| 7 | + } | |
| 8 | + if ( keyboardNavigationKeycodes.indexOf( event.keyCode ) !== -1 ) { | |
| 9 | + keyboardNavigation = true; | |
| 10 | + document.documentElement.classList.add( 'accessible-focus' ); | |
| 11 | + } | |
| 12 | +} ); | |
| 13 | +document.addEventListener( 'mouseup', function () { | |
| 14 | + if ( ! keyboardNavigation ) { | |
| 15 | + return; | |
| 16 | + } | |
| 17 | + keyboardNavigation = false; | |
| 18 | + document.documentElement.classList.remove( 'accessible-focus' ); | |
| 19 | +} ); | |