forked from yatil/accessifyhtml5.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
accessifyhtml5.js
55 lines (48 loc) · 1.13 KB
/
accessifyhtml5.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Accessifyhtml5.js
*
* Source: https://github.com/yatil/accessifyhtml5.js
*/
var AccessifyHTML5 = function (defaults) {
if (document.querySelectorAll) {
var fixes = {
'article' : {'role': 'article' },
'aside' : {'role': 'complementary' },
'nav' : {'role': 'navigation' },
'output' : {'aria-live': 'polite' },
'section' : {'role': 'region' },
'[required]': {'aria-required': 'true' }
};
if (defaults) {
if (defaults.header) {
fixes[defaults.header] = {
'role': 'banner'
};
}
if (defaults.footer) {
fixes[defaults.footer] = {
'role': 'contentinfo'
}
}
if (defaults.main) {
fixes[defaults.main] = {
'role': 'main'
}
}
}
for (var fix in fixes) {
var elems = document.querySelectorAll(fix),
obj = fixes[fix],
attr, value, key, i = 0;
for (key in obj) {
attr = key;
value = obj[key];
}
for (i; i < elems.length; i++) {
if (!elems[i].hasAttribute(attr)) {
elems[i].setAttribute(attr, value);
};
}
}
}
};