Skip to content

Commit

Permalink
fix incompatibility with webpack and change all references to utils a…
Browse files Browse the repository at this point in the history
…nd commons to use the axe object so that configure will be able to use our standard rule and check definitions
  • Loading branch information
dylanb committed Mar 20, 2016
1 parent ff893ed commit 60a5ae6
Show file tree
Hide file tree
Showing 167 changed files with 1,087 additions and 1,095 deletions.
4 changes: 3 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"globals": {},
"globals": {
"axe": true
},

"browser" : false,
"node" : true,
Expand Down
7 changes: 5 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ module.exports = function (grunt) {
'lib/core/*/index.js',
'lib/core/**/index.js',
'lib/core/**/*.js',
'<%= configure.rules.dest.auto %>',
'lib/core/export.js',
'<%= configure.rules.dest.auto %>',
'lib/outro.stub'
],
dest: 'axe.js',
Expand Down Expand Up @@ -114,7 +114,10 @@ module.exports = function (grunt) {
dest: 'axe.min.js'
}],
options: {
preserveComments: 'some'
preserveComments: 'some',
mangle: {
except: ['commons', 'utils', 'axe']
}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion doc/developer-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ The DqElement is a "serialized" `HTMLElement`. It will calculate the CSS selecto

```javascript
var firstH1 = document.getElementByTagName('h1')[0];
var dqH1 = new utils.DqElement(firstH1);
var dqH1 = new axe.utils.DqElement(firstH1);
```

Elements returned by the DqElement class have the following methods and properties:
Expand Down
3 changes: 1 addition & 2 deletions lib/.jshintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"globals": {
"axe": true,
"utils": true
"axe": true
},

"browser" : true,
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"results": true,
"node": true,
"options": true,
"commons": true,
"axe": true,
"document": true,
"window": true
},
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/aria/abstractrole.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return commons.aria.getRoleType(node.getAttribute('role')) === 'abstract';
return axe.commons.aria.getRoleType(node.getAttribute('role')) === 'abstract';
4 changes: 2 additions & 2 deletions lib/checks/aria/allowed-attr-matches.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

var role = node.getAttribute('role');
if (!role) {
role = commons.aria.implicitRole(node);
role = axe.commons.aria.implicitRole(node);
}
var allowed = commons.aria.allowedAttr(role);
var allowed = axe.commons.aria.allowedAttr(role);
if (role && allowed) {
var aria = /^aria-/;
if (node.hasAttributes()) {
Expand Down
6 changes: 3 additions & 3 deletions lib/checks/aria/allowed-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ var attr, attrName, allowed,
attrs = node.attributes;

if (!role) {
role = commons.aria.implicitRole(node);
role = axe.commons.aria.implicitRole(node);
}
allowed = commons.aria.allowedAttr(role);
allowed = axe.commons.aria.allowedAttr(role);
if (role && allowed) {
for (var i = 0, l = attrs.length; i < l; i++) {
attr = attrs[i];
attrName = attr.name;
if (commons.aria.validateAttr(attrName) && allowed.indexOf(attrName) === -1) {
if (axe.commons.aria.validateAttr(attrName) && allowed.indexOf(attrName) === -1) {
invalid.push(attrName + '="' + attr.nodeValue + '"');
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/aria/invalidrole.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
return !commons.aria.isValidRole(node.getAttribute('role'));
return !axe.commons.aria.isValidRole(node.getAttribute('role'));


2 changes: 1 addition & 1 deletion lib/checks/aria/required-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var missing = [];
if (node.hasAttributes()) {
var attr,
role = node.getAttribute('role'),
required = commons.aria.requiredAttr(role);
required = axe.commons.aria.requiredAttr(role);

if (role && required) {
for (var i = 0, l = required.length; i < l; i++) {
Expand Down
8 changes: 4 additions & 4 deletions lib/checks/aria/required-children.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var requiredOwned = commons.aria.requiredOwned,
implicitNodes = commons.aria.implicitNodes,
matchesSelector = commons.utils.matchesSelector,
idrefs = commons.dom.idrefs;
var requiredOwned = axe.commons.aria.requiredOwned,
implicitNodes = axe.commons.aria.implicitNodes,
matchesSelector = axe.commons.utils.matchesSelector,
idrefs = axe.commons.dom.idrefs;

function owns(node, role, ariaOwned) {
if (node === null) { return false; }
Expand Down
10 changes: 5 additions & 5 deletions lib/checks/aria/required-parent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function getSelector(role) {
var impliedNative = commons.aria.implicitNodes(role) || [];
var impliedNative = axe.commons.aria.implicitNodes(role) || [];
return impliedNative.concat('[role="' + role + '"]').join(',');
}

Expand All @@ -9,16 +9,16 @@ function getMissingContext(element, requiredContext, includeElement) {
missing = [];

if (!requiredContext) {
requiredContext = commons.aria.requiredContext(role);
requiredContext = axe.commons.aria.requiredContext(role);
}

if (!requiredContext) { return null; }

for (index = 0, length = requiredContext.length; index < length; index++) {
if (includeElement && commons.utils.matchesSelector(element, getSelector(requiredContext[index]))) {
if (includeElement && axe.utils.matchesSelector(element, getSelector(requiredContext[index]))) {
return null;
}
if (commons.dom.findUp(element, getSelector(requiredContext[index]))) {
if (axe.commons.dom.findUp(element, getSelector(requiredContext[index]))) {
//if one matches, it passes
return null;
} else {
Expand All @@ -35,7 +35,7 @@ function getAriaOwners(element) {

while (element) {
if (element.id) {
o = document.querySelector('[aria-owns~=' + commons.utils.escapeSelector(element.id) + ']');
o = document.querySelector('[aria-owns~=' + axe.commons.utils.escapeSelector(element.id) + ']');
if (o) { owners.push(o); }
}
element = element.parentNode;
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/aria/valid-attr-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ for (var i = 0, l = attrs.length; i < l; i++) {
attr = attrs[i];
attrName = attr.name;
if (options.indexOf(attrName) === -1 && aria.test(attrName) &&
!commons.aria.validateAttrValue(node, attrName)) {
!axe.commons.aria.validateAttrValue(node, attrName)) {

invalid.push(attrName + '="' + attr.nodeValue + '"');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/aria/valid-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var attr,

for (var i = 0, l = attrs.length; i < l; i++) {
attr = attrs[i].name;
if (options.indexOf(attr) === -1 && aria.test(attr) && !commons.aria.validateAttr(attr)) {
if (options.indexOf(attr) === -1 && aria.test(attr) && !axe.commons.aria.validateAttr(attr)) {
invalid.push(attr);
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/checks/color/color-contrast-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ if (nodeName === 'LABEL') {

// label of disabled control associated w/ aria-labelledby
if (node.id) {
var candidate = doc.querySelector('[aria-labelledby~=' + commons.utils.escapeSelector(node.id) + ']');
var candidate = doc.querySelector('[aria-labelledby~=' + axe.commons.utils.escapeSelector(node.id) + ']');
if (candidate && candidate.disabled) {
return false;
}
}

if (commons.text.visible(node, false, true) === '') {
if (axe.commons.text.visible(node, false, true) === '') {
return false;
}

Expand All @@ -62,7 +62,7 @@ var range = document.createRange(),
for (index = 0; index < length; index++) {
child = childNodes[index];

if (child.nodeType === 3 && commons.text.sanitize(child.nodeValue) !== '') {
if (child.nodeType === 3 && axe.commons.text.sanitize(child.nodeValue) !== '') {
range.selectNodeContents(child);
}
}
Expand All @@ -72,7 +72,7 @@ length = rects.length;

for (index = 0; index < length; index++) {
//check to see if the rectangle impinges
if (commons.dom.visuallyOverlaps(rects[index], node)) {
if (axe.commons.dom.visuallyOverlaps(rects[index], node)) {
return true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/checks/color/color-contrast.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var noScroll = !!(options || {}).noScroll;
var bgNodes = [],
bgColor = commons.color.getBackgroundColor(node, bgNodes, noScroll),
fgColor = commons.color.getForegroundColor(node, noScroll);
bgColor = axe.commons.color.getBackgroundColor(node, bgNodes, noScroll),
fgColor = axe.commons.color.getForegroundColor(node, noScroll);

//We don't know, so we'll pass it provisionally
if (fgColor === null || bgColor === null) {
Expand All @@ -13,7 +13,7 @@ var fontSize = parseFloat(nodeStyle.getPropertyValue('font-size'));
var fontWeight = nodeStyle.getPropertyValue('font-weight');
var bold = (['bold', 'bolder', '600', '700', '800', '900'].indexOf(fontWeight) !== -1);

var cr = commons.color.hasValidContrastRatio(bgColor, fgColor, fontSize, bold);
var cr = axe.commons.color.hasValidContrastRatio(bgColor, fgColor, fontSize, bold);

this.data({
fgColor: fgColor.toHexString(),
Expand Down
4 changes: 2 additions & 2 deletions lib/checks/color/link-in-text-block.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global commons*/
var color = commons.color;
/* global axe*/
var color = axe.commons.color;

function getContrast(color1, color2) {
var c1lum = color1.getRelativeLuminance();
Expand Down
20 changes: 10 additions & 10 deletions lib/checks/forms/fieldset.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var failureCode,


function getUnrelatedElements(parent, name) {
return commons.utils.toArray(parent.querySelectorAll('select,textarea,button,input:not([name="' + name +
return axe.commons.utils.toArray(parent.querySelectorAll('select,textarea,button,input:not([name="' + name +
'"]):not([type="hidden"])'));
}

Expand All @@ -15,7 +15,7 @@ function checkFieldset(group, name) {
failureCode = 'no-legend';
return false;
}
if (!commons.text.accessibleText(firstNode)) {
if (!axe.commons.text.accessibleText(firstNode)) {
self.relatedNodes([firstNode]);
failureCode = 'empty-legend';
return false;
Expand All @@ -31,11 +31,11 @@ function checkFieldset(group, name) {

function checkARIAGroup(group, name) {

var hasLabelledByText = commons.dom.idrefs(group, 'aria-labelledby').some(function (element) {
return element && commons.text.accessibleText(element);
var hasLabelledByText = axe.commons.dom.idrefs(group, 'aria-labelledby').some(function (element) {
return element && axe.commons.text.accessibleText(element);
});
var ariaLabel = group.getAttribute('aria-label');
if (!hasLabelledByText && !(ariaLabel && commons.text.sanitize(ariaLabel))) {
if (!hasLabelledByText && !(ariaLabel && axe.commons.text.sanitize(ariaLabel))) {
self.relatedNodes(group);
failureCode = 'no-group-label';
return false;
Expand All @@ -51,20 +51,20 @@ function checkARIAGroup(group, name) {
}

function spliceCurrentNode(nodes, current) {
return commons.utils.toArray(nodes).filter(function (candidate) {
return axe.commons.utils.toArray(nodes).filter(function (candidate) {
return candidate !== current;
});
}

function runCheck(element) {
var name = commons.utils.escapeSelector(node.name);
var name = axe.commons.utils.escapeSelector(node.name);
var matchingNodes = document.querySelectorAll('input[type="' +
commons.utils.escapeSelector(node.type) + '"][name="' + name + '"]');
axe.commons.utils.escapeSelector(node.type) + '"][name="' + name + '"]');
if (matchingNodes.length < 2) {
return true;
}
var fieldset = commons.dom.findUp(element, 'fieldset');
var group = commons.dom.findUp(element, '[role="group"]' + (node.type === 'radio' ? ',[role="radiogroup"]' : ''));
var fieldset = axe.commons.dom.findUp(element, 'fieldset');
var group = axe.commons.dom.findUp(element, '[role="group"]' + (node.type === 'radio' ? ',[role="radiogroup"]' : ''));
if (!group && !fieldset) {
failureCode = 'no-group';
self.relatedNodes(spliceCurrentNode(matchingNodes, element));
Expand Down
4 changes: 2 additions & 2 deletions lib/checks/forms/labelledby.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ this.data({
});

var matchingNodes = document.querySelectorAll('input[type="' +
commons.utils.escapeSelector(node.type) + '"][name="' + commons.utils.escapeSelector(node.name) + '"]');
axe.commons.utils.escapeSelector(node.type) + '"][name="' + axe.commons.utils.escapeSelector(node.name) + '"]');
if (matchingNodes.length <= 1) {
return true;
}
Expand All @@ -19,5 +19,5 @@ return [].map.call(matchingNodes, function (m) {
});
}).filter(function (n) {
var labelNode = document.getElementById(n);
return labelNode && commons.text.accessibleText(labelNode);
return labelNode && axe.commons.text.accessibleText(labelNode);
}).length !== 0;
4 changes: 2 additions & 2 deletions lib/checks/keyboard/focusable-no-name.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var tabIndex = node.getAttribute('tabindex'),
isFocusable = commons.dom.isFocusable(node) && tabIndex > -1;
isFocusable = axe.commons.dom.isFocusable(node) && tabIndex > -1;
if (!isFocusable) {
return false;
}
return !commons.text.accessibleText(node);
return !axe.commons.text.accessibleText(node);
6 changes: 3 additions & 3 deletions lib/checks/label/duplicate-img-label.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
var imgs = node.querySelectorAll('img');
var text = commons.text.visible(node, true).toLowerCase();
var text = axe.commons.text.visible(node, true).toLowerCase();

if (text === '') {
return false;
}

for (var i = 0, len = imgs.length; i < len; i++) {
var img = imgs[i];
var imgAlt = commons.text.accessibleText(img).toLowerCase();
var imgAlt = axe.commons.text.accessibleText(img).toLowerCase();
if (imgAlt === text &&
img.getAttribute('role') !== 'presentation' &&
commons.dom.isVisible(img)) {
axe.commons.dom.isVisible(img)) {
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/checks/label/explicit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

var label = document.querySelector('label[for="' + commons.utils.escapeSelector(node.id) + '"]');
var label = document.querySelector('label[for="' + axe.commons.utils.escapeSelector(node.id) + '"]');
if (label) {
return !!commons.text.accessibleText(label);
return !!axe.commons.text.accessibleText(label);
}
return false;
8 changes: 4 additions & 4 deletions lib/checks/label/help-same-as-label.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var labelText = commons.text.label(node),
var labelText = axe.commons.text.label(node),
check = node.getAttribute('title');

if (!labelText) {
Expand All @@ -10,11 +10,11 @@ if (!check) {
check = '';

if (node.getAttribute('aria-describedby')) {
var ref = commons.dom.idrefs(node, 'aria-describedby');
var ref = axe.commons.dom.idrefs(node, 'aria-describedby');
check = ref.map(function (thing) {
return thing ? commons.text.accessibleText(thing) : '';
return thing ? axe.commons.text.accessibleText(thing) : '';
}).join('');
}
}

return commons.text.sanitize(check) === commons.text.sanitize(labelText);
return axe.commons.text.sanitize(check) === axe.commons.text.sanitize(labelText);
4 changes: 2 additions & 2 deletions lib/checks/label/implicit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

var label = commons.dom.findUp(node, 'label');
var label = axe.commons.dom.findUp(node, 'label');
if (label) {
return !!commons.text.accessibleText(label);
return !!axe.commons.text.accessibleText(label);
}
return false;
2 changes: 1 addition & 1 deletion lib/checks/label/multiple-label.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var labels = [].slice.call(document.querySelectorAll('label[for="' +
commons.utils.escapeSelector(node.id) + '"]')),
axe.commons.utils.escapeSelector(node.id) + '"]')),
parent = node.parentNode;

while (parent) {
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/label/title-only.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
var labelText = commons.text.label(node);
var labelText = axe.commons.text.label(node);
return !labelText && !!(node.getAttribute('title') || node.getAttribute('aria-describedby'));
Loading

0 comments on commit 60a5ae6

Please sign in to comment.