content

Helpers for working with element content

API

getDefaultText(element) static method

Use a heuristic to extract text from the given item.

This looks, in order, at: the aria-label attribute, the alt attribute, innerText, or textContent.

This function is used as the default implementation of the getItemText function in several mixins.

Parameters:

  • element: Element

Returns: string

isSubstantiveElement(node) static method

Return true if the given node is likely to be useful as component content.

This will be true for nodes that are: a) instances of Element (HTMLElement or SVGElement), and b) not on a blacklist of normally invisible elements (such as style or script). Among other things, this returns false for Text nodes.

This is used by ContentItemsMixin to filter out nodes which are unlikely to be interesting as list items. This is intended to satisfy the Gold Standard checklist criteria Auxiliary Content, so that a component does not inadvertently treat <style> and other invisible items as element content.

Parameters:

  • node: Node

Returns: boolean

substantiveElements(nodes) static method

Return a set of Elements which are likely to be useful as component content.

Given a NodeList or array of objects, this will return only those array members that are: a) instances of Element (HTMLElement or SVGElement), and b) not on a blacklist of normally invisible elements (such as style or script). Among other things, this filters out Text nodes.

Parameters:

  • nodes: NodeList|Array.the list of nodes to filter

Returns: Array. the filtered elements