Sha256: 62e92d8d080be2747e42a4bb108a536816f608802f2f3defb4fe8088a3694060

Contents?: true

Size: 1.5 KB

Versions: 271

Compression:

Stored size: 1.5 KB

Contents

/* global aria, axe, dom */
const idRefsRegex = /^idrefs?$/;

function cacheIdRefs(node, refAttrs) {
	if (node.hasAttribute) {
		const idRefs = axe._cache.get('idRefs');

		if (node.nodeName.toUpperCase() === 'LABEL' && node.hasAttribute('for')) {
			idRefs[node.getAttribute('for')] = true;
		}

		for (let i = 0; i < refAttrs.length; ++i) {
			const attr = refAttrs[i];

			if (!node.hasAttribute(attr)) {
				continue;
			}

			const attrValue = node.getAttribute(attr);

			const tokens = axe.utils.tokenList(attrValue);

			for (let k = 0; k < tokens.length; ++k) {
				idRefs[tokens[k]] = true;
			}
		}
	}

	for (let i = 0; i < node.children.length; i++) {
		cacheIdRefs(node.children[i], refAttrs);
	}
}

/**
 * Check that a DOM node is a reference in the accessibility tree
 * @param {Element} node
 * @returns {Boolean}
 */
aria.isAccessibleRef = function isAccessibleRef(node) {
	node = node.actualNode || node;
	let root = dom.getRootNode(node);
	root = root.documentElement || root; // account for shadow roots
	const id = node.id;

	// because axe.commons is not available in axe.utils, we can't do
	// this caching when we build up the virtual tree
	if (!axe._cache.get('idRefs')) {
		axe._cache.set('idRefs', {});
		// Get all idref(s) attributes on the lookup table
		const refAttrs = Object.keys(aria.lookupTable.attributes).filter(attr => {
			const { type } = aria.lookupTable.attributes[attr];
			return idRefsRegex.test(type);
		});

		cacheIdRefs(root, refAttrs);
	}

	return axe._cache.get('idRefs')[id] === true;
};

Version data entries

271 entries across 271 versions & 1 rubygems

Version Path
govuk_publishing_components-21.66.2 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.66.1 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.66.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.65.1 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.65.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.64.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.63.3 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.63.2 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.63.1 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.63.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.62.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.61.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.60.3 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.60.2 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.60.1 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.60.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.59.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.58.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.57.1 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-21.57.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js