summaryrefslogtreecommitdiff
blob: 44608c2bceaa1eb6a2b8c5113a04b7ec266d2403 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var keyboardNavigation = false,
	keyboardNavigationKeycodes = [ 9, 32, 37, 38, 39, 40 ]; // keyCodes for tab, space, left, up, right, down respectively

document.addEventListener( 'keydown', function( event ) {
	if ( keyboardNavigation ) {
		return;
	}
	if ( keyboardNavigationKeycodes.indexOf( event.keyCode ) !== -1 ) {
		keyboardNavigation = true;
		document.documentElement.classList.add( 'accessible-focus' );
	}
} );
document.addEventListener( 'mouseup', function() {
	if ( ! keyboardNavigation ) {
		return;
	}
	keyboardNavigation = false;
	document.documentElement.classList.remove( 'accessible-focus' );
} );