Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Accessibility Panel #87

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/accessibility-element-view.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use strict'

const SelectableView = require('./selectable-view')
const Eval = require('./eval')

class AccessibilityElementView extends SelectableView {
constructor (element, parent) {
super('element-row')

this.path = element
this.path = element.selector
this.pathId = element.id
parent.appendChild(this.element)
this.render()
this.handleEvents(parent)
Expand All @@ -19,6 +21,13 @@ class AccessibilityElementView extends SelectableView {

render () {
this.selectorPath.textContent = this.path

// Add a click-handler that will select the element.
// Uses the `accessibilityAuditMap` defined in accessibility.js
this.selectorPath.onclick = (evt) => {
evt.stopPropagation()
Eval.execute(`inspect(window.__devtron.accessibilityAuditMap.get(${this.pathId}))`)
}
}

filter (searchText) {
Expand Down
27 changes: 24 additions & 3 deletions lib/accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@ const Eval = require('./eval')

exports.audit = () => {
return Eval.execute(function () {
const {axs} = window.__devtron
const {axs} = window.__devtron // defined in browserGlobals.js
const config = new axs.AuditConfiguration({showUnsupportedRulesWarning: false})
return axs.Audit.run(config).map(function (result) {
const results = axs.Audit.run(config)

// Create a lookup map so users can click on an element to inspect it
let idCounter = 0
window.__devtron.accessibilityAuditMap = new Map()
results.forEach(function (result) {
const elements = result.elements || []
elements.forEach(function (element) {
const id = idCounter++
element.__accessibilityAuditId = id
window.__devtron.accessibilityAuditMap.set(id, element)
})
})

return results.map(function (result) {
const elements = result.elements || []
let status = 'N/A'
if (result.result === 'PASS') {
Expand All @@ -19,7 +33,14 @@ exports.audit = () => {
title: result.rule.heading,
url: result.rule.url,
elements: elements.map(function (element) {
return window.__devtron.axs.utils.getQuerySelectorText(element)
let selector = element.tagName.toLowerCase()
if (element.className) {
selector += '.' + element.className.split(' ').join('.')
}
return {
selector: selector,
id: element.__accessibilityAuditId
}
})
}
}).sort(function (resultA, resultB) {
Expand Down
8 changes: 8 additions & 0 deletions lib/browserGlobals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This defines globals that will be used in the browser context
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the filename here should be browser-globals.js to match the naming convention of the other files in this project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, 😊 . Fixed!

// (via the content_scripts definition in manifest.json)
//
// It is generated via `npm run-script prepublish`
const axs = require('accessibility-developer-tools')

window.__devtron = window.__devtron || {}
window.__devtron.axs = axs
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"content_scripts": [
{
"matches": ["*"],
"js": ["vendor/axs.js"]
"js": ["out/browserGlobals.js"]
}
]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Electron DevTools Extension",
"main": "./api.js",
"scripts": {
"prepublish": "browserify lib/*.js -o out/index.js --ignore-missing --entry lib/index.js",
"prepublish": "browserify lib/*.js -o out/index.js --ignore-missing --entry lib/index.js && browserify lib/browserGlobals.js -o out/browserGlobals.js",
"start": "watchify lib/*.js -o out/index.js --ignore-missing --entry lib/index.js --verbose",
"test": "mocha test/unit/*-test.js test/integration/*-test.js && standard"
},
Expand Down Expand Up @@ -39,6 +39,7 @@
"watchify": "^3.7.0"
},
"dependencies": {
"accessibility-developer-tools": "^2.11.0",
"highlight.js": "^9.3.0",
"humanize-plus": "^1.8.1"
},
Expand Down
7 changes: 7 additions & 0 deletions static/devtron.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ tbody:focus,
padding-left: 45px;
}

.row-element-path a {
cursor: pointer;
}
tr.active .row-element-path a {
color: white;
}

.active .sidebar-icon {
background-color: white;
}
Expand Down
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<td></td>
<td></td>
<td class="row-element-path">
<span data-field="selectorPath"></span>
<a data-field="selectorPath" href="#"></a>
</td>
</tr>
</template>
Expand Down
Loading