Skip to content
This repository was archived by the owner on Oct 21, 2021. It is now read-only.

Commit 1580788

Browse files
committed
Merge
2 parents bdf6b4f + 05956b2 commit 1580788

File tree

10 files changed

+745
-46
lines changed

10 files changed

+745
-46
lines changed

.eslintrc

Lines changed: 0 additions & 22 deletions
This file was deleted.

.eslintrc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"amd": true
5+
},
6+
"extends": [
7+
"plugin:github/recommended",
8+
"plugin:github/es6",
9+
"plugin:github/browser"
10+
]
11+
}

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: node_js
2+
node_js:
3+
- "8"
4+
dist: trusty
5+
sudo: false
6+
addons:
7+
chrome: stable
8+
before_script:
9+
- export DISPLAY=:99.0
10+
- sh -e /etc/init.d/xvfb start

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# accessibilityjs
1+
# accessibilityjs ![build status](https://travis-ci.org/github/accessibilityjs.svg?branch=master)
22

33
Client side accessibility error scanner.
44

@@ -56,6 +56,8 @@ Internet Explorer and Edge require a polyfill for [`closest`](https://developer.
5656

5757
## Development
5858

59-
- `npm install`
60-
- `npm test`
61-
- `npm run example`
59+
```bash
60+
> npm install
61+
> npm test
62+
> npm run example
63+
```

example.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
</div>
5151

5252
<script type="text/javascript">
53-
accessibilityjs.scanForProblems(document.body, function (error) {
53+
var errors = accessibilityjs.scanForProblems(document.body, function (error) {
5454
error.element.style.outline = '5px solid red'
5555
error.element.addEventListener('click', function () {
5656
alert([error.name, error.message].join('\n'))
@@ -60,6 +60,8 @@
6060
'.js-menu-target': ['aria-haspopup']
6161
}
6262
})
63+
64+
console.log(errors)
6365
</script>
6466
</body>
6567
</html>

index.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
export function scanForProblems(context, logError, options) {
1+
export function scanForProblems(context, errorCallback, options) {
2+
const errors = {}
3+
4+
function logError(err) {
5+
const {name} = err
6+
7+
errors[name] = errors[name] || []
8+
errors[name].push(err)
9+
10+
errorCallback(err)
11+
}
12+
213
for (const img of context.querySelectorAll('img')) {
314
if (!img.hasAttribute('alt')) {
415
logError(new ImageWithoutAltAttributeError(img))
@@ -31,9 +42,13 @@ export function scanForProblems(context, logError, options) {
3142
}
3243
}
3344

34-
for (const input of context.querySelectorAll('input[type=text], input[type=url], input[type=search], input[type=number], textarea')) {
45+
for (const input of context.querySelectorAll(
46+
'input[type=text], input[type=url], input[type=search], input[type=number], textarea'
47+
)) {
3548
// In case input.labels isn't supported by browser, find the control manually (IE)
36-
const inputLabel = input.labels ? input.labels[0] : input.closest('label') || document.querySelector(`label[for="${input.id}"]`)
49+
const inputLabel = input.labels
50+
? input.labels[0]
51+
: input.closest('label') || document.querySelector(`label[for="${input.id}"]`)
3752
if (!inputLabel && !elementIsHidden(input) && !input.hasAttribute('aria-label')) {
3853
logError(new InputMissingLabelError(input))
3954
}
@@ -47,7 +62,7 @@ export function scanForProblems(context, logError, options) {
4762

4863
if (options && options['ariaPairs']) {
4964
for (const selector in options['ariaPairs']) {
50-
const ARIAAttrsRequired = options['ariaPairs'][selector]
65+
const ARIAAttrsRequired = options['ariaPairs'][selector]
5166
for (const target of context.querySelectorAll(selector)) {
5267
const missingAttrs = []
5368

@@ -61,6 +76,8 @@ export function scanForProblems(context, logError, options) {
6176
}
6277
}
6378
}
79+
80+
return errors
6481
}
6582

6683
function errorSubclass(fn) {
@@ -157,7 +174,12 @@ function isText(value) {
157174
function accessibleText(node) {
158175
switch (node.nodeType) {
159176
case Node.ELEMENT_NODE:
160-
if (isText(node.getAttribute('alt')) || isText(node.getAttribute('aria-label')) || isText(node.getAttribute('title'))) return true
177+
if (
178+
isText(node.getAttribute('alt')) ||
179+
isText(node.getAttribute('aria-label')) ||
180+
isText(node.getAttribute('title'))
181+
)
182+
return true
161183
for (let i = 0; i < node.childNodes.length; i++) {
162184
if (accessibleText(node.childNodes[i])) return true
163185
}

0 commit comments

Comments
 (0)