js/skip-link-focus-fix.js   A
last analyzed

Complexity

Total Complexity 6
Complexity/F 3

Size

Lines of Code 24
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 24
rs 10
wmc 6
mnd 4
bc 4
fnc 2
bpm 2
cpm 3
noi 1
1
/**
2
 * File skip-link-focus-fix.js.
3
 *
4
 * Helps with accessibility for keyboard only users.
5
 *
6
 * Learn more: https://git.io/vWdr2
7
 */
8
( function() {
9
	var isIe = /(trident|msie)/i.test( navigator.userAgent );
0 ignored issues
show
Bug introduced by
The variable navigator seems to be never declared. If this is a global, consider adding a /** global: navigator */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
10
11
	if ( isIe && document.getElementById && window.addEventListener ) {
12
		window.addEventListener( 'hashchange', function() {
13
			var id = location.hash.substring( 1 ),
14
				element;
15
16
			if ( ! ( /^[A-z0-9_-]+$/.test( id ) ) ) {
17
				return;
18
			}
19
20
			element = document.getElementById( id );
21
22
			if ( element ) {
23
				if ( ! ( /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) ) {
24
					element.tabIndex = -1;
25
				}
26
27
				element.focus();
28
			}
29
		}, false );
30
	}
31
} )();
32