Sha256: bbaa3c73599b5dea0bc84e066e5865e016df9e1bd0193ed1abf9e7bfe2186469

Contents?: true

Size: 1.78 KB

Versions: 104

Compression:

Stored size: 1.78 KB

Contents

/* global text, dom, axe */

/**
 * Returns the visible text of the virtual node
 * NOTE: when calculating the text or accessible text of a node that includes shadow
 * roots attached to it or its children, the flattened tree must be considered
 * rather than the "light DOM"
 * @method visibleVirtual
 * @memberof axe.commons.text
 * @instance
 * @param  {VirtualNode} element
 * @param  {Boolean} screenReader When provided, will evaluate visibility from the perspective of a screen reader
 * @param  {Boolean} noRecursing When False, the result will contain text from the element and it's children.
 * When True, the result will only contain text from the element
 * @return {String}
 */
text.visibleVirtual = function(element, screenReader, noRecursing) {
	const result = element.children
		.map(child => {
			if (child.actualNode.nodeType === 3) {
				// filter on text nodes
				const nodeValue = child.actualNode.nodeValue;
				if (nodeValue && dom.isVisible(element.actualNode, screenReader)) {
					return nodeValue;
				}
			} else if (!noRecursing) {
				return text.visibleVirtual(child, screenReader);
			}
		})
		.join('');
	return text.sanitize(result);
};

/**
 * Finds virtual node and calls visibleVirtual()
 * IMPORTANT: This method requires the composed tree at axe._tree
 * @param  {Element} element
 * @param  {Boolean} screenReader When provided, will evaluate visibility from the perspective of a screen reader
 * @param  {Boolean} noRecursing When False, the result will contain text from the element and it's children.
 * When True, the result will only contain text from the element
 * @return {String}
 */
text.visible = function(element, screenReader, noRecursing) {
	element = axe.utils.getNodeFromTree(axe._tree[0], element);
	return text.visibleVirtual(element, screenReader, noRecursing);
};

Version data entries

104 entries across 104 versions & 1 rubygems

Version Path
govuk_publishing_components-17.12.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.11.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.10.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.9.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.8.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.7.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.6.1 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.6.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.5.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.4.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.3.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.2.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.1.1 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.1.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.0.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-16.29.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-16.28.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-16.27.1 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-16.27.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-16.26.0 node_modules/axe-core/lib/commons/text/visible-virtual.js