Skip to content

Commit 3873357

Browse files
authored
Merge pull request #87 from philschatz/accessibility-update
Improve Accessibility Panel
2 parents def19c5 + 3fd7b93 commit 3873357

8 files changed

+54
-2292
lines changed

lib/accessibility-element-view.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
'use strict'
22

33
const SelectableView = require('./selectable-view')
4+
const Eval = require('./eval')
45

56
class AccessibilityElementView extends SelectableView {
67
constructor (element, parent) {
78
super('element-row')
89

9-
this.path = element
10+
this.path = element.selector
11+
this.pathId = element.id
1012
parent.appendChild(this.element)
1113
this.render()
1214
this.handleEvents(parent)
@@ -19,6 +21,13 @@ class AccessibilityElementView extends SelectableView {
1921

2022
render () {
2123
this.selectorPath.textContent = this.path
24+
25+
// Add a click-handler that will select the element.
26+
// Uses the `accessibilityAuditMap` defined in accessibility.js
27+
this.selectorPath.onclick = (evt) => {
28+
evt.stopPropagation()
29+
Eval.execute(`inspect(window.__devtron.accessibilityAuditMap.get(${this.pathId}))`)
30+
}
2231
}
2332

2433
filter (searchText) {

lib/accessibility.js

+24-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,23 @@ const Eval = require('./eval')
22

33
exports.audit = () => {
44
return Eval.execute(function () {
5-
const {axs} = window.__devtron
5+
const {axs} = window.__devtron // defined in browser-globals.js
66
const config = new axs.AuditConfiguration({showUnsupportedRulesWarning: false})
7-
return axs.Audit.run(config).map(function (result) {
7+
const results = axs.Audit.run(config)
8+
9+
// Create a lookup map so users can click on an element to inspect it
10+
let idCounter = 0
11+
window.__devtron.accessibilityAuditMap = new Map()
12+
results.forEach(function (result) {
13+
const elements = result.elements || []
14+
elements.forEach(function (element) {
15+
const id = idCounter++
16+
element.__accessibilityAuditId = id
17+
window.__devtron.accessibilityAuditMap.set(id, element)
18+
})
19+
})
20+
21+
return results.map(function (result) {
822
const elements = result.elements || []
923
let status = 'N/A'
1024
if (result.result === 'PASS') {
@@ -19,7 +33,14 @@ exports.audit = () => {
1933
title: result.rule.heading,
2034
url: result.rule.url,
2135
elements: elements.map(function (element) {
22-
return window.__devtron.axs.utils.getQuerySelectorText(element)
36+
let selector = element.tagName.toLowerCase()
37+
if (element.className) {
38+
selector += '.' + element.className.split(' ').join('.')
39+
}
40+
return {
41+
selector: selector,
42+
id: element.__accessibilityAuditId
43+
}
2344
})
2445
}
2546
}).sort(function (resultA, resultB) {

lib/browser-globals.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This defines globals that will be used in the browser context
2+
// (via the content_scripts definition in manifest.json)
3+
//
4+
// It is generated via `npm run-script prepublish`
5+
const axs = require('accessibility-developer-tools')
6+
7+
window.__devtron = window.__devtron || {}
8+
window.__devtron.axs = axs

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"content_scripts": [
66
{
77
"matches": ["*"],
8-
"js": ["vendor/axs.js"]
8+
"js": ["out/browser-globals.js"]
99
}
1010
]
1111
}

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"description": "Electron DevTools Extension",
55
"main": "./api.js",
66
"scripts": {
7-
"prepublish": "browserify lib/*.js -o out/index.js --ignore-missing --entry lib/index.js",
8-
"start": "watchify lib/*.js -o out/index.js --ignore-missing --entry lib/index.js --verbose",
7+
"prepublish": "browserify lib/*.js -o out/index.js --ignore-missing --entry lib/index.js && browserify lib/browser-globals.js -o out/browser-globals.js",
8+
"start": "browserify lib/browser-globals.js -o out/browser-globals.js && watchify lib/*.js -o out/index.js --ignore-missing --entry lib/index.js --verbose",
99
"test": "mocha test/unit/*-test.js test/integration/*-test.js && standard"
1010
},
1111
"repository": {
@@ -39,6 +39,7 @@
3939
"watchify": "^3.7.0"
4040
},
4141
"dependencies": {
42+
"accessibility-developer-tools": "^2.11.0",
4243
"highlight.js": "^9.3.0",
4344
"humanize-plus": "^1.8.1"
4445
},

static/devtron.css

+7
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ tbody:focus,
130130
padding-left: 45px;
131131
}
132132

133+
.row-element-path a {
134+
cursor: pointer;
135+
}
136+
tr.active .row-element-path a {
137+
color: white;
138+
}
139+
133140
.active .sidebar-icon {
134141
background-color: white;
135142
}

static/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
<td></td>
9191
<td></td>
9292
<td class="row-element-path">
93-
<span data-field="selectorPath"></span>
93+
<a data-field="selectorPath" href="#"></a>
9494
</td>
9595
</tr>
9696
</template>

0 commit comments

Comments
 (0)