Namespace: dom

requiem~dom

Collection of DOM manipulation methods.
Source:

Methods

(static) addChild(elementopt, child, nameopt, prependopt) → {Node|Array.<Node>}

Adds a child element(s) to an element. By default the added element(s) are appended to the end of the element.
Parameters:
Name Type Attributes Default Description
element Node <optional>
Specifies the element to add the child to.
child Node | Array.<Node> Single element or an array of elements.
name string <optional>
The name of the child/children to be added. Typically a name is required. If it is not specified, this method will attempt to infer the name from the provided child/children. This method fails if a name cannot be inferred. If there exists another child with the same name, the added child will be grouped together with the existing child.
prepend boolean <optional>
false Specifies whether the child is prepended to this element instead of appended.
Source:
Returns:
The added element(s).
Type
Node | Array.<Node>

(static) addClass(element, className)

Adds class(es) to DOM element(s).
Parameters:
Name Type Description
element Node | Array.<Node> Target element(s).
className string | Array.<string> Class(es) to add.
Source:

(static) addToChildRegistry(childRegistry, child, nameopt) → {boolean}

Adds a child or an array of children with the same name to the specified child registry.
Parameters:
Name Type Attributes Description
childRegistry Object The child registry.
child Node | Array Either one child element or an array of multiple child elements with the same name.
name string <optional>
Name of the child(ren).
Source:
Returns:
True if the child is successfully added to the child registry, false otherwise.
Type
boolean

(static) createElement(value) → {Node}

Creates a DOM element from the provided string.
Parameters:
Name Type Description
value string String describing the DOM element.
Source:
Returns:
DOM element.
Type
Node

(static) getAttribute(element, name) → {string}

Gets an attribute of an element by its name.
Parameters:
Name Type Description
element Node Target element.
name string Attribute name.
Source:
Returns:
Attribute value.
Type
string

(static) getChild(elementopt, nameopt, recursiveopt) → {Node|Array|Object}

Gets the a child from the global display tree consisting of all sightread Element instances.
Parameters:
Name Type Attributes Default Description
element Node <optional>
Specifies the parent element instance to fetch the child from.
name string <optional>
Name of the child, depth separated by '.' (i.e. 'foo.bar'). If unspecified, the entire child list of this Element will be returned.
recursive boolean <optional>
true Speciifies whether to search for the child recursively down the tree.
Source:
Returns:
Type
Node | Array | Object

(static) getChildRegistry(elementopt, findClosestopt) → {Object}

Gets the global child registry.
Parameters:
Name Type Attributes Description
element Node <optional>
Target element.
findClosest Node <optional>
Specifies whether to keep seeking for a child registry upwards in the DOM tree if the target element doesn't have one.
Source:
Returns:
The child registry.
Type
Object

(static) getClassIndex(element, className) → {number}

Gets the index of a specified class in a DOM element,
Parameters:
Name Type Description
element Node Target element.
className string Target class name.
Source:
Returns:
Index of given class name. -1 if not found.
Type
number

(static) getDataRegistry(identifieropt) → {Object}

Gets the data registry or a specific entry inside the data registry.
Parameters:
Name Type Attributes Description
identifier string <optional>
The dot notated identifier.
Source:
Returns:
The data registry.
Type
Object

(static) getElementRegistry(identifieropt) → {Object}

Gets the element registry.
Parameters:
Name Type Attributes Description
identifier string | function <optional>
Either a tag or the element class to look for. If unspecified the entire registry will be returned.
Source:
Returns:
The element registry.
Type
Object

(static) getState(element) → {string}

Gets the current state of a DOM element as defined by Directive.STATE.
Parameters:
Name Type Description
element Node Target element.
Source:
Returns:
State of the target element.
Type
string

(static) getStyle(element, key, isComputedopt, isolateUnitsopt) → {*}

Gets the value of an inline CSS rule of a Node by its name.
Parameters:
Name Type Attributes Default Description
element Node Target element.
key string Name of the CSS rule in camelCase.
isComputed boolean <optional>
false Specifies whether the styles are computed.
isolateUnits boolean <optional>
false Specifies whether value and units are separated. This affects the return value type.
Source:
Returns:
Value of the style. If isolateUnits is set to true, this will return an object containing both 'value' and 'unit' keys.
Type
*

(static) hasAttribute(element, name) → {boolean}

Checks to see if an element has the attribute of the specified name.
Parameters:
Name Type Description
element Node Target element.
name string Attribute name.
Source:
Returns:
True if attribute with said name exists, false otherwise.
Type
boolean

(static) hasChild(child, elementopt) → {boolean}

Determines if an element contains the specified child.
Parameters:
Name Type Attributes Description
child Node | string A child is a Node. It can also be a string of child name(s) separated by '.'.
element Node <optional>
Specifies the parent Node to fetch the child from.
Source:
Returns:
True if this element has the specified child, false otherwise.
Type
boolean

(static) hasClass(element, className) → {boolean}

Verifies that the specified element(s) has the specified class.
Parameters:
Name Type Description
element Node | Array.<Node> Target element(s).
className string Class to check.
Source:
Returns:
True if element(s) has given class, false otherwise.
Type
boolean

(static) hasStyle(element, key) → {boolean}

Checks to see if a Node has the specified inline CSS rule.
Parameters:
Name Type Description
element Node Target element.
key string Name of the style.
Source:
Returns:
Type
boolean

(static) namespace(pathopt, scopeopt) → {Object}

Generates a nested namespace in the specified scope, as described by the dot- notated namespace path.
Parameters:
Name Type Attributes Default Description
path string <optional>
Namespace path with keywords separated by dots.
scope Object | window <optional>
window|{} Scope/object to create the nested namespace in. If browser environment is detected, this param will default to window. Otherwise it will be an empty object literal.
Source:
Returns:
The generated namespace.
Type
Object

(static) ready(callback)

Invokes a callback when the DOM is ready.
Parameters:
Name Type Description
callback function Function invoked when the DOM is ready.
Source:

(static) register(tagOrClass, options) → {Class}

Wraps the native Document.registerElement() and registers a custom element with the DOM while storing it in the registry.
Parameters:
Name Type Description
tagOrClass string of the registered element class or the class itself (in this case the second param is not needed).
options function | Object Either a class to base the element on or an object literal containing additional options of the registration.
Properties
Name Type Attributes Description
prototype Class <optional>
Element class prototype to base the custom element on.
class Class <optional>
Element class to base the custom element on, takes priority over prototype.
extends string <optional>
Existing tag to extend.
Source:
See:
  • Document.registerElement()
Returns:
The registered class.
Type
Class

(static) removeChild(elementopt, child)

Removes a child element(s) from an element.
Parameters:
Name Type Attributes Description
element Node <optional>
Specifies the parent Node to remove the child from.
child Node | Array | string Child/children to be removed. This can be a Node or array. It can also be a string namespace of the target child/children.
Source:

(static) removeClass(element, className)

Removes a class(es) from DOM element(s).
Parameters:
Name Type Description
element Node | Array.<Node> Target element(s).
className string | Array.<string> Class(es) to remove.
Source:

(static) removeFromChildRegistry(childRegistry, child)

Removes a child or an array of children with the same name from the specified child registry.
Parameters:
Name Type Description
childRegistry Object The child registry.
child Node | Array | string Either one child element or an array of multiple child elements with the same name or the name in dot notation.
Source:

(static) setAttribute(element, name, value)

Sets an attribute of an element by the attribute name.
Parameters:
Name Type Description
element Node Target element.
name string Attribute name.
value * Attribute value.
Source:

(static) setDataRegistry(data)

Sets the data registry.
Parameters:
Name Type Description
data Object Sets the data registry.
Source:

(static) setState(element, state)

Sets the state of a DOM element(s) as defined by Directive.STATE.
Parameters:
Name Type Description
element Node | Array.<Node> Target element(s).
state string New state.
Source:

(static) setStyle(element, key, value)

Sets an inline CSS rule of a Node.
Parameters:
Name Type Description
element Node Target element.
key string Name of the CSS rule in camelCase.
value * Value of the style. If a number is provided, it will be automatically suffixed with 'px'.
Source:
See:

(static) sightread(elementopt, childRegistryopt)

Crawls a DOM element, creates a child registry for the element and registers all of its children into the child registry, recursively.
Parameters:
Name Type Attributes Default Description
element Node <optional>
document Target element for sightreading. By default this will be the document.
childRegistry Object <optional>
Target child registry to register child elements with. If unspecified it will be inferred from the target element.
Source: