This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
forked from speced/respec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aria.js
51 lines (51 loc) · 1.76 KB
/
aria.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
// Module w3c/aria
// Adds wai-aria landmarks and roles to entire document.
// Introduced by Shane McCarron (shane@aptest.com) from the W3C PFWG
"use strict";
define([],
function() {
return {
run: function(conf, doc, cb) {
// ensure head section is labeled
if (!doc.body.hasAttribute("role")) {
doc.body.setAttribute("role", "document");
}
if (!doc.body.hasAttribute("id")) {
doc.body.setAttribute("id", "respecDocument");
}
var head = document.querySelector("div.head");
if (head) {
head.setAttribute("role", "contentinfo");
head.setAttribute("id", "respecHeader");
}
var toc = doc.querySelector("#toc ol:first-of-type");
if (toc) {
// ensure toc is labeled
toc.setAttribute("role", "directory");
}
// mark issues and notes with heading
var noteCount = 1;
var issueCount = 1;
var ednoteCount = 1;
Array
.from(doc.querySelectorAll(".note-title, .ednote-title, .issue-title"))
.forEach(function(element) {
var $element = $(element);
var isIssue = element.classList.contains("issue-title");
var isEdNote = element.classList.contains("ednote-title");
var level = $element.parents("section").length + 2;
element.setAttribute("aria-level", level);
element.setAttribute("role", "heading");
if (isIssue) {
$element.makeID("h", "issue" + issueCount++);
} else if (isEdNote) {
$element.makeID("h", "ednote" + ednoteCount++);
} else {
$element.makeID("h", "note" + noteCount++);
}
});
cb();
}
};
}
);