Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* chore(package): update deps * feat: use ol in ToC (closes #835) * refactor(aria): query for the toc instead * style(aria): jscs fixup * refactor(aria): use less jquery * style(aria): use double quotes * fix(aria): convert NodeList to array
- Loading branch information
Marcos Cáceres
committed
Aug 5, 2016
1 parent
a84caa5
commit 17ecce8
Showing
4 changed files
with
95 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,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) { | ||
// 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 = $('nav#toc', doc).find("ul:first") ; | ||
toc.attr('role', 'directory') ; | ||
} | ||
// 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) ; | ||
} | ||
}); | ||
cb(); | ||
"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(); | ||
} | ||
}; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters