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 (49 loc) · 2.13 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
define(
["core/utils"], // load this to be sure that the jQuery extensions are loaded
function (utils) {
return {
run: function (conf, doc, cb, msg) {
msg.pub("start", "w3c/aria");
// ensure head section is labelled
$('body', doc).attr('role', 'document') ;
$('body', doc).attr('id', 'respecDocument') ;
$('div.head', doc).attr('role', 'contentinfo') ;
$('div.head', doc).attr('id', 'respecHeader') ;
if (!conf.noTOC) {
// ensure toc is labelled
var toc = $('section#toc', doc)
.find("ul:first");
toc.attr('role', 'navigation') ;
if (!toc.attr("id")) {
toc.attr('id', 'respecContents') ;
}
}
// mark issues and notes with heading
var noteCount = 0 ; var issueCount = 0 ; var ednoteCount = 0;
$(".note-title, .ednote-title, .issue-title", doc).each(function (i, item) {
var $item = $(item)
, isIssue = $item.hasClass("issue-title")
, isEdNote = $item.hasClass("ednote-title")
, level = $item.parents("section").length+2 ;
$item.attr('aria-level', level) ;
$item.attr('role', 'heading') ;
if (isIssue) {
issueCount++;
$item.makeID('h', "issue" + issueCount) ;
} else if (isEdNote) {
ednoteCount++;
$item.makeID('h', "ednote" + ednoteCount) ;
} else {
noteCount++;
$item.makeID('h', "note" + noteCount) ;
}
});
msg.pub("end", "w3c/aria");
cb();
}
};
}
);