-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheadingstructure.js
102 lines (95 loc) · 3.29 KB
/
headingstructure.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
create();
function traverseFrames(doc, div) {
check(doc, div);
// go through for each frame's document if there are any frames
var frametypes= ['frame','iframe'];
for (var i=0;i<frametypes.length;i++) {
var myframes=doc.getElementsByTagName(frametypes[i]);
for (var z=0;z<myframes.length;z++) {
try {
traverseFrames(myframes[z].contentWindow.document, div);
} catch(e) {}
}
}
}
function isAncestorDisplayNone(node) {
var safety = 0;
while (node && window.getComputedStyle(node).getPropertyValue('display') != "none" && window.getComputedStyle(node).getPropertyValue('visibility') != "hidden" && safety < 1000) {
if (window.getComputedStyle(node).getPropertyValue('display') == "none" || window.getComputedStyle(node).getPropertyValue('visibility') == "hidden") {
return true;
}
node = node.parentElement;
safety++;
console.log(safety);
}
if (node && (window.getComputedStyle(node).getPropertyValue('display') == "none" || window.getComputedStyle(node).getPropertyValue('visibility') == "hidden")) {
return true;
}
else
return false;
}
function create() {
var div = document.createElement("div");
div.style.backgroundColor = "white";
div.style.color = "darkblue";
div.style.border = "thin solid darkblue";
div.style.position = "fixed";
div.style.width = "20em";
div.style.maxHeight = "20em";
div.style.top = "10em";
div.style.left = "10em";
div.style.overflow = "scroll";
div.id = "a11y_check_headinglist";
var button = document.createElement("button");
var title = document.createElement("span");
title.textContent = "Headings List";
title.style.marginLeft = "3em";
title.style.color = "black";
button.textContent = "Move";
button.addEventListener("mousemove",function(e) {
if (e.buttons > 0) {
var dd = document.getElementById("a11y_check_headinglist");
dd.style.top = e.clientY-10+"px";
dd.style.left = e.clientX-20+"px";
//console.log(e.clientX);
//console.log(e.clientY);
}
});
close = document.createElement("button");
close.textContent = "X";
close.addEventListener("click", function() {
document.getElementById("a11y_check_headinglist").remove();
});
close.style.float = "right";
close.title = "close popup";
div.appendChild(button);
div.appendChild(title);
div.appendChild(close);
traverseFrames(document, div);
document.body.appendChild(div);
}
function check(doc,div) {
var col = doc.querySelectorAll("h1,h2,h3,h4,h5,h6,[role='heading']");
var level = "";
col.forEach(c => {
level = "";
if (!isAncestorDisplayNone(c)) {
var h = doc.createElement("div");
//if (c.tagName.startsWith("H"))
level = c.tagName+" ";
if (c.hasAttribute('aria-level'))
level = level + "aria-level " + c.getAttribute('aria-level')+":";
var len;
len = c.hasAttribute('aria-level') ? parseInt(c.getAttribute('aria-level')) : parseInt(c.tagName.charAt(1));
var spaces = new Array(len + 1).join("-");
var hLabel = doc.createElement("span");
var hValue = doc.createElement("span");
hValue.style.color = "green";
hLabel.textContent = spaces+level;
hValue.textContent = calcNames(c).name;
h.appendChild(hLabel);
h.appendChild(hValue);
div.appendChild(h);
}
} );
}