Skip to content

Commit c011ddf

Browse files
committed
Add initial work on Trello Accessibility Fixes.
So far, it does the following: - Makes lists and cards accessible as lists and list items, respectively. - Focuses the active card when moving between lists and cards with the arrow keys. If you are using a screen reader, you will need to ensure that the arrow keys are passed to the application to make use of this. For NVDA, you can achieve this by switching to focus mode to move through cards. - Labels badges in cards.
1 parent 20b130d commit c011ddf

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

TrelloA11yFixes.user.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// ==UserScript==
2+
// @name Trello Accessibility Fixes
3+
// @namespace http://axSgrease.nvaccess.org/
4+
// @description Improves the accessibility of Trello.
5+
// @author James Teh <jamie@nvaccess.org>
6+
// @copyright 2017 NV Access Limited
7+
// @license GNU General Public License version 2.0
8+
// @version 2017.1
9+
// @grant GM_log
10+
// @include https://trello.com/b/*
11+
// ==/UserScript==
12+
13+
// Used when we need to generate ids for ARIA.
14+
var idCounter = 0;
15+
16+
function onNodeAdded(target) {
17+
if (target.classList.contains("badge")) {
18+
// Label badges.
19+
var label = target.getAttribute("title");
20+
// Include the badge count (if any) in the label.
21+
label += target.textContent;
22+
target.setAttribute("aria-label", label);
23+
return;
24+
}
25+
for (var list of target.querySelectorAll(".list")) {
26+
list.setAttribute("role", "list");
27+
var header = list.querySelector(".list-header-name");
28+
if (header) {
29+
// Label the list with its header.
30+
var id = "axsg-lh" + idCounter++;
31+
header.setAttribute("id", id);
32+
list.setAttribute("aria-labelledby", id);
33+
}
34+
}
35+
for (var card of target.querySelectorAll(".list-card")) {
36+
// Make this a focusable list item.
37+
card.setAttribute("tabindex", "-1");
38+
card.setAttribute("role", "listitem");
39+
}
40+
}
41+
42+
function onClassModified(target) {
43+
var classes = target.classList;
44+
if (!classes)
45+
return;
46+
if (classes.contains("active-card")) {
47+
// When the active card changes, focus it.
48+
target.focus();
49+
}
50+
}
51+
52+
var observer = new MutationObserver(function(mutations) {
53+
for (var mutation of mutations) {
54+
try {
55+
if (mutation.type === "childList") {
56+
for (var node of mutation.addedNodes) {
57+
if (node.nodeType != Node.ELEMENT_NODE)
58+
continue;
59+
onNodeAdded(node);
60+
}
61+
} else if (mutation.type === "attributes") {
62+
if (mutation.attributeName == "class")
63+
onClassModified(mutation.target);
64+
}
65+
} catch (e) {
66+
// Catch exceptions for individual mutations so other mutations are still handled.
67+
GM_log("Exception while handling mutation: " + e);
68+
}
69+
}
70+
});
71+
observer.observe(document, {childList: true, attributes: true,
72+
subtree: true, attributeFilter: ["class"]});

readme.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,15 @@ This script improves the accessibility of the [Telegram instant messaging](https
8484
It so far does the following:
8585

8686
- Marks the chat history as a live region so new messages are announced automatically.
87+
88+
### Trello Accessibility Fixes
89+
[Download Trello Accessibility Fixes](https://github.com/nvaccess/axSGrease/raw/master/TrelloA11yFixes.user.js)
90+
91+
This script improves the accessibility of [Trello](https://trello.com/).
92+
It does the following:
93+
94+
- Makes lists and cards accessible as lists and list items, respectively.
95+
- Focuses the active card when moving between lists and cards with the arrow keys.
96+
If you are using a screen reader, you will need to ensure that the arrow keys are passed to the application to make use of this.
97+
For NVDA, you can achieve this by switching to focus mode to move through cards.
98+
- Labels badges in cards.

0 commit comments

Comments
 (0)