Skip to content

Commit d5c7235

Browse files
committed
Merge pull request #213 from ricksbrown/a11y
Add some a11y checking in debug mode
2 parents 69151fc + 535eff6 commit d5c7235

4 files changed

Lines changed: 58 additions & 15 deletions

File tree

wcomponents-theme/src/main/js/wc/debug/a11y.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
define(["axs", "wc/dom/initialise"], function(axs, initialise) {
1+
define(["axs", "wc/ui/loading"], function(axs, loading) {
22
"use strict";
33

4-
initialise.addCallback(a11yTest);
4+
loading.done.then(a11yTest);
55

6+
/**
7+
* Run the accessbility test on the current page.
8+
*/
69
function a11yTest() {
710
var auditConfig, issues;
811
try {
912
auditConfig = new axs.AuditConfiguration();
1013
auditConfig.showUnsupportedRulesWarning = false;
14+
auditConfig.scope = document.body;
15+
/*
16+
* Skip "focusableElementNotVisibleAndNotAriaHidden" because it sets focus and that could be annoying.
17+
*/
18+
auditConfig.auditRulesToIgnore = ["focusableElementNotVisibleAndNotAriaHidden"];
1119
issues = axs.Audit.run(auditConfig);
1220
issues.forEach(formatIssue);
1321
}
@@ -16,6 +24,11 @@ define(["axs", "wc/dom/initialise"], function(axs, initialise) {
1624
}
1725
}
1826

27+
/*
28+
* TODO hook this into a generic "debug messages" mechanism.
29+
* This could be a good place for an experiment such as mustache templates or webcomponents since it only runs when
30+
* debug is enabled.
31+
*/
1932
function formatIssue(issue) {
2033
var container = document.createElement("div"),
2134
list = document.createElement("ul"),

wcomponents-theme/src/main/js/wc/ui/loading.js

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,47 @@ define(["wc/dom/initialise", "wc/ui/modalShim"],
1111
/** @param initialise wc/dom/initialise @param modalShim wc/ui/modalShim @ignore */
1212
function(initialise, modalShim) {
1313
"use strict";
14-
initialise.addCallback(
15-
function() {
14+
var loading = {
15+
/**
16+
* A Promise that is resolved when thepage is first initialized.
17+
* If other scripts wish to be notified when the UI is no longer in the loading state they can use this promise.
18+
* @var
19+
* @type {Promise}
20+
* @public
21+
*/
22+
done: new Promise(function(loaded, error) {
1623
try {
17-
var container = document.getElementById("wc_ui_loading");
18-
if (container && container.parentNode) {
19-
container.parentNode.removeChild(container);
20-
}
24+
postInit();
25+
loaded();
2126
}
22-
finally {
23-
modalShim.clearModal();
27+
catch (ex) {
28+
error(ex);
2429
}
25-
});
26-
return true;
30+
}),
31+
/**
32+
* Call to dismiss the loading overlay (under normal circumstances this happens automatically).
33+
* @function module:wc/ui/loading.postInit
34+
* @public
35+
*/
36+
postInit: postInit
37+
};
38+
39+
/**
40+
* Call when the DOM is loaded and UI controls are initialized to dismiss the loading overlay.
41+
* This is exposed as a public method since there are rare cases when it may need to be called manually.
42+
*/
43+
function postInit() {
44+
try {
45+
var container = document.getElementById("wc_ui_loading");
46+
if (container && container.parentNode) {
47+
container.parentNode.removeChild(container);
48+
}
49+
}
50+
finally {
51+
modalShim.clearModal();
52+
}
53+
}
54+
55+
initialise.register(loading);
56+
return loading;
2757
});

wcomponents-theme/src/main/xslt/wc.ui.root.xsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@
5656
<!-- We want to load up the CSS as soon as we can, so do it immediately after loading require. -->
5757
<xsl:variable name="styleLoaderId" select="concat($scriptId,'-styleloader')"/>
5858
<script type="text/javascript" id="{$styleLoaderId}">
59-
<xsl:text>require(["wc/compat/compat!"], function(){</xsl:text>
59+
<xsl:text>require(["wc/compat/compat!"], function() {</xsl:text>
6060
<xsl:text>require(["wc/loader/style", "wc/dom/removeElement"</xsl:text>
6161
<xsl:if test="$isDebug=1">
62-
<xsl:text>,"wc/debug/consoleColor"</xsl:text>
62+
<xsl:text>,"wc/debug/consoleColor", "wc/debug/a11y"</xsl:text>
6363
</xsl:if>
6464
<xsl:text>], function(s, r){try{s.load();}finally{r("</xsl:text>
6565
<xsl:value-of select="$styleLoaderId"/>

wcomponents-theme/unbuilt.package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"jsdoc-oblivion": "~0.0.4"
88
},
99
"devDependencies": {
10-
"accessibility-developer-tools": "2.9.0-rc.0",
10+
"accessibility-developer-tools": "2.10.0",
1111
"clean-css": "~3.4.3",
1212
"css-b64-images": "~0.2.5",
1313
"dojo": "~1.10.4",

0 commit comments

Comments
 (0)