Skip to content

Commit

Permalink
doc: rename aria._lut, add to developer guide
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcy Sutton committed Dec 9, 2017
1 parent 88cd35b commit f1b491c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
15 changes: 15 additions & 0 deletions doc/developer-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ Common functions are an internal library used by the rules and checks. If you h

Core Utilities are an internal library that provides aXe with functionality used throughout its core processes. Most notably among these are the queue function and the DqElement constructor.

#### ARIA Lookup Tables

axe.commons.aria provides a namespace for ARIA-related utilities, including a lookupTable for attributes and roles.

* `axe.commons.aria.lookupTable.attributes`
* `axe.commons.aria.lookupTable.globalAttributes`
* `axe.commons.aria.lookupTable.role`

#### Common Utility Functions

In addition to the ARIA lookupTable, there are also utility functions on the axe.commons.aria and axe.commons.dom namespaces:

* `axe.commons.aria.implicitRole` - Get the implicit role for a given node
* `axe.commons.aria.label` - Gets the accessible ARIA label text of a given element
* `axe.commons.dom.isVisible` - Determine whether an element is visible

#### Queue Function

Expand Down
12 changes: 6 additions & 6 deletions lib/commons/aria/attributes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global aria, axe, lookupTables */
/*global aria, axe, lookupTable */

/**
* Get required attributes for a given role
Expand All @@ -10,7 +10,7 @@
*/
aria.requiredAttr = function (role) {
'use strict';
var roles = lookupTables.role[role],
var roles = lookupTable.role[role],
attr = roles && roles.attributes && roles.attributes.required;
return attr || [];
};
Expand All @@ -25,11 +25,11 @@ aria.requiredAttr = function (role) {
*/
aria.allowedAttr = function (role) {
'use strict';
var roles = lookupTables.role[role],
var roles = lookupTable.role[role],
attr = (roles && roles.attributes && roles.attributes.allowed) || [],
requiredAttr = (roles && roles.attributes && roles.attributes.required) || [];

return attr.concat(lookupTables.globalAttributes).concat(requiredAttr);
return attr.concat(lookupTable.globalAttributes).concat(requiredAttr);
};

/**
Expand All @@ -42,7 +42,7 @@ aria.allowedAttr = function (role) {
*/
aria.validateAttr = function (att) {
'use strict';
return !!lookupTables.attributes[att];
return !!lookupTable.attributes[att];
};

/**
Expand All @@ -60,7 +60,7 @@ aria.validateAttrValue = function (node, attr) {
var matches, list,
doc = document,
value = node.getAttribute(attr),
attrInfo = lookupTables.attributes[attr];
attrInfo = lookupTable.attributes[attr];

if (!attrInfo) {
return true;
Expand Down
8 changes: 4 additions & 4 deletions lib/commons/aria/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/

var aria = commons.aria = {},
lookupTables = aria._lut = {};
lookupTable = aria.lookupTable = {};

lookupTables.attributes = {
lookupTable.attributes = {
'aria-activedescendant': {
type: 'idref'
},
Expand Down Expand Up @@ -171,14 +171,14 @@ lookupTables.attributes = {
}
};

lookupTables.globalAttributes = [
lookupTable.globalAttributes = [
'aria-atomic', 'aria-busy', 'aria-controls', 'aria-current', 'aria-describedby',
'aria-disabled', 'aria-dropeffect', 'aria-flowto', 'aria-grabbed',
'aria-haspopup', 'aria-hidden', 'aria-invalid', 'aria-keyshortcuts', 'aria-label',
'aria-labelledby', 'aria-live', 'aria-owns', 'aria-relevant'
];

lookupTables.role = {
lookupTable.role = {
'alert': {
type: 'widget',
attributes: {
Expand Down
26 changes: 13 additions & 13 deletions lib/commons/aria/roles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global aria, lookupTables, axe */
/* global aria, lookupTable, axe */

/**
* Check if a given role is valid
Expand All @@ -10,7 +10,7 @@
*/
aria.isValidRole = function (role) {
'use strict';
if (lookupTables.role[role]) {
if (lookupTable.role[role]) {
return true;
}

Expand All @@ -25,9 +25,9 @@ aria.isValidRole = function (role) {
* @return {Array} Array of roles that match the type
*/
aria.getRolesWithNameFromContents = function () {
return Object.keys(lookupTables.role).filter(function (r) {
return lookupTables.role[r].nameFrom &&
lookupTables.role[r].nameFrom.indexOf('contents') !== -1;
return Object.keys(lookupTable.role).filter(function (r) {
return lookupTable.role[r].nameFrom &&
lookupTable.role[r].nameFrom.indexOf('contents') !== -1;
});
};

Expand All @@ -40,8 +40,8 @@ aria.getRolesWithNameFromContents = function () {
* @return {Array} Array of roles that match the type
*/
aria.getRolesByType = function (roleType) {
return Object.keys(lookupTables.role).filter(function (r) {
return lookupTables.role[r].type === roleType;
return Object.keys(lookupTable.role).filter(function (r) {
return lookupTable.role[r].type === roleType;
});
};

Expand All @@ -54,7 +54,7 @@ aria.getRolesByType = function (roleType) {
* @return {Mixed} String if a matching role and its type are found, otherwise `null`
*/
aria.getRoleType = function (role) {
var r = lookupTables.role[role];
var r = lookupTable.role[role];

return (r && r.type) || null;
};
Expand All @@ -70,7 +70,7 @@ aria.getRoleType = function (role) {
aria.requiredOwned = function (role) {
'use strict';
var owned = null,
roles = lookupTables.role[role];
roles = lookupTable.role[role];

if (roles) {
owned = axe.utils.clone(roles.owned);
Expand All @@ -89,7 +89,7 @@ aria.requiredOwned = function (role) {
aria.requiredContext = function (role) {
'use strict';
var context = null,
roles = lookupTables.role[role];
roles = lookupTable.role[role];

if (roles) {
context = axe.utils.clone(roles.context);
Expand All @@ -109,7 +109,7 @@ aria.implicitNodes = function (role) {
'use strict';

var implicit = null,
roles = lookupTables.role[role];
roles = lookupTable.role[role];

if (roles && roles.implicit) {
implicit = axe.utils.clone(roles.implicit);
Expand Down Expand Up @@ -172,8 +172,8 @@ aria.implicitRole = function (node) {
/*
* Create a list of { name / implicit } role mappings to filter on
*/
var roles = Object.keys(lookupTables.role).map( function (role) {
var lookup = lookupTables.role[role];
var roles = Object.keys(lookupTable.role).map( function (role) {
var lookup = lookupTable.role[role];
return { name: role, implicit: lookup && lookup.implicit };
});

Expand Down

0 comments on commit f1b491c

Please sign in to comment.