aria-api

access ARIA information from JavaScript
git clone https://git.ce9e.org/aria-api.git

commit
d07b2afed95eccf343fc6bf2ae19fd01004cdf3b
parent
032ad4fd0079a8797b2d0ea88c1712c970a503f5
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2024-01-30 08:18
small code style tweaks

Diffstat

M lib/attrs.js 16 ++++++++++++----
M lib/query.js 4 ++--

2 files changed, 14 insertions, 6 deletions


diff --git a/lib/attrs.js b/lib/attrs.js

@@ -1,5 +1,13 @@
    1     1 const constants = require('./constants.js');
    2     2 
   -1     3 var unique = function(arr) {
   -1     4 	return arr.filter((a, i) => arr.indexOf(a) === i);
   -1     5 };
   -1     6 
   -1     7 var flatten = function(arr) {
   -1     8 	return [].concat.apply([], arr);
   -1     9 };
   -1    10 
    3    11 // candidates can be passed for performance optimization
    4    12 const getRole = function(el, candidates) {
    5    13 	if (el.hasAttribute('role')) {
@@ -13,7 +21,7 @@ const getRole = function(el, candidates) {
   13    21 			}
   14    22 		}
   15    23 	} else {
   16    -1 		const roles = candidates ? candidates : Object.keys(constants.roles);
   -1    24 		const roles = candidates || Object.keys(constants.roles);
   17    25 		for (const role of roles) {
   18    26 			const r = constants.roles[role];
   19    27 			if (r) {
@@ -27,10 +35,10 @@ const getRole = function(el, candidates) {
   27    35 };
   28    36 
   29    37 const hasRole = function(el, roles) {
   30    -1 	const candidates = [].concat.apply([], roles.map(role => {
   -1    38 	const subRoles = roles.map(role => {
   31    39 		return (constants.roles[role] || {}).subRoles || [role];
   32    -1 	}));
   33    -1 	return !!getRole(el, candidates);
   -1    40 	});
   -1    41 	return !!getRole(el, unique(flatten(subRoles)));
   34    42 };
   35    43 
   36    44 const getAttribute = function(el, key) {

diff --git a/lib/query.js b/lib/query.js

@@ -17,13 +17,13 @@ const matches = function(el, selector) {
   17    17 };
   18    18 
   19    19 const _querySelector = function(all) {
   20    -1 	return function(root, role) {
   -1    20 	return function(root, selector) {
   21    21 		const results = [];
   22    22 		try {
   23    23 			atree.walk(root, node => {
   24    24 				if (node.nodeType === node.ELEMENT_NODE) {
   25    25 					// FIXME: skip hidden elements
   26    -1 					if (matches(node, role)) {
   -1    26 					if (matches(node, selector)) {
   27    27 						results.push(node);
   28    28 						if (!all) {
   29    29 							throw 'StopIteration';