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-30.4.1 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-30.4.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-30.3.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-30.2.1 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-30.2.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-30.1.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-30.0.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-29.15.3 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-29.15.2 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-29.15.1 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-29.15.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-29.14.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-29.13.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-29.12.1 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-29.12.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-29.11.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-29.10.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-29.9.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-29.8.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js
govuk_publishing_components-29.7.0 node_modules/axe-core/lib/commons/aria/is-accessible-ref.js