Class: Dom

GoBrain. Dom

new GoBrain.Dom(root)

GoBrain.Core/src/dom.js, line 1

A scoped DOM wrapper, adding convenience functionality used to manipulate the element and restricts access to anything above the root element.

A scoped DOM wrapper, adding convenience functionality used to manipulate the element and restricts access to anything above the root element.

Name Type Description
root HTMLElement

The root element to work against.

Members

SettingsString

Properties:
Name Type Default Description
IdPrefix String gobrain-id-

This namespace is prepended to all ids set with the .goBrainId() function or searched for with the .getNodeByGoBrainId() function.

TemplatePrefix String gobrain-template-
TemplateVariablePrefix String gobrain-template-variable-

Methods

addClass(clazz, element){GoBrain.Node}

GoBrain.Core/src/dom.js, line 50

Adds a css class if it doesn't already exist.

Adds a css class if it doesn't already exist.

Name Type Description
clazz String

The class to add.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node

addCssRule(selector, rules, sheet, index){GoBrain.Node}

GoBrain.Core/src/dom.js, line 63

Adds a css rule to a style sheet.

Adds a css rule to a style sheet.

Name Type Description
selector String

Selector for the rule.

rules String

The rules to add.

sheet CSSStyleSheet optional

The style sheet to use.

index Number optional

The position in the style sheet to insert the rule at.

Returns:
Type Description
GoBrain.Node

addEventListener(event, handler, options, element){GoBrain.Node}

GoBrain.Core/src/dom.js, line 86

Adds an event listener.

Adds an event listener.

Name Type Description
event String

Event to listen to.

handler function

Handler to invoke when event occurs.

options Boolean | Object

Options to use to add the event handler. If boolean, whether or not to add handler as passive, if supported.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node

addResizeListener(handler, element){GoBrain.Node}

GoBrain.Core/src/dom.js, line 736

Adds a resize listener.

Adds a resize listener.

Name Type Description
handler function

Handler to invoke when resize occurs.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node

appendChild(child, parent){GoBrain.Node}

GoBrain.Core/src/dom.js, line 101

Appends a child node/element.

Appends a child node/element.

Name Type Description
child GoBrain.Node | HTMLElement

The child to append.

parent GoBrain.Node | HTMLElement optional

The parent node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node

attribute(attribute, value, element){GoBrain.Node|String}

GoBrain.Core/src/dom.js, line 114

Gets or sets node attribute.

Gets or sets node attribute.

Name Type Description
attribute String

The name of the data attribute.

value String optional

The value of the data attribute.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node | String

children(element){Array.<GoBrain.Node>}

GoBrain.Core/src/dom.js, line 128

Gets children of node.

Gets children of node.

Name Type Description
element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
Array.<GoBrain.Node>

content(content, element){GoBrain.Node|*}

GoBrain.Core/src/dom.js, line 140

Gets or sets node content.

Gets or sets node content.

Name Type Description
content * optional

The content to set.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node | *

context(){GoBrain.Node}

GoBrain.Core/src/dom.js, line 153

Gets the element that the dom instance was created with.

Gets the element that the dom instance was created with.

Returns:
Type Description
GoBrain.Node

createNode(tag, data){GoBrain.Node}

GoBrain.Core/src/dom.js, line 164

Creates an element wrapped in a node.

Creates an element wrapped in a node.

Name Type Default Description
tag String div optional

The type of element to create.

data String optional

The data for the new node. Only used when creating 'text' nodes.

Returns:
Type Description
GoBrain.Node

createStyleSheet(){CSSStyleSheet}

GoBrain.Core/src/dom.js, line 177

Creates a style sheet and appends it to the DOM.

Creates a style sheet and appends it to the DOM.

Returns:
Type Description
CSSStyleSheet

css(styles, element){GoBrain.Node}

GoBrain.Core/src/dom.js, line 195

Sets node style properties.

Sets node style properties.

Name Type Description
styles Object.<String, *>

The style properties to set.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node

data(property, value, element){GoBrain.Node|String}

GoBrain.Core/src/dom.js, line 208

Gets or sets data attribute.

Gets or sets data attribute.

Name Type Description
property String

The name of the data attribute.

value String optional

The value of the data attribute.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node | String

getNodeByClass(clazz, element){GoBrain.Node|null}

GoBrain.Core/src/dom.js, line 222

Gets first node beneath node that has a matching css class.

Gets first node beneath node that has a matching css class.

Name Type Description
clazz String

The class to look for.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node | null

getNodeByGoBrainId(id, element){GoBrain.Node|null}

GoBrain.Core/src/dom.js, line 235

Gets first node beneath node that has a matching GoBrain id.

Gets first node beneath node that has a matching GoBrain id.

Name Type Description
id String

The id to look for.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node | null

getNodeById(id, element){GoBrain.Node|null}

GoBrain.Core/src/dom.js, line 250

Gets first node beneath node that has a matching id.

Gets first node beneath node that has a matching id.

Name Type Description
id String

The id to look for.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node | null

getNodesByAttributeAndValue(attribute, value, element){Array.<GoBrain.Node>}

GoBrain.Core/src/dom.js, line 263

Gets all elements beneath node that have a matching attribute value pair.

Gets all elements beneath node that have a matching attribute value pair.

Name Type Description
attribute String

The attribute to look for.

value String

The attribute value to look for.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
Array.<GoBrain.Node>

getNodesByClass(clazz, element){Array.<GoBrain.Node>}

GoBrain.Core/src/dom.js, line 277

Gets all nodes beneath node that have a matching css class.

Gets all nodes beneath node that have a matching css class.

Name Type Description
clazz String

The class to look for.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
Array.<GoBrain.Node>

getNodesById(id, element){Array.<GoBrain.Node>}

GoBrain.Core/src/dom.js, line 290

Gets all nodes beneath node that have a matching id.

Gets all nodes beneath node that have a matching id.

Name Type Description
id String

The id to look for.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
Array.<GoBrain.Node>

getTemplate(templateName, element){function}

GoBrain.Core/src/dom.js, line 303

Finds and processes a markup template and creates a function that will create new instances of the template when called.

Finds and processes a markup template and creates a function that will create new instances of the template when called.

Name Type Description
templateName String

The name of the template.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
function

goBrainId(id, element){HTMLElement|null}

GoBrain.Core/src/dom.js, line 351

Sets a node GoBrain id.

Sets a node GoBrain id. This id must be unique.

Name Type Description
id String

The unique id to set.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
HTMLElement | null

hasAncestor(ancestor, element){Boolean}

GoBrain.Core/src/dom.js, line 375

Checks if the node has a specific element as ancestor.

Checks if the node has a specific element as ancestor.

Name Type Description
ancestor GoBrain.Node | HTMLElement

The potential ancestor to check against.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
Boolean

hasAttribute(attribute, element){Boolean}

GoBrain.Core/src/dom.js, line 388

Checks if the node has a specific element as first level child.

Checks if the node has a specific element as first level child.

Name Type Description
attribute String

The attribute to look for.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
Boolean

hasChild(child, element){Boolean}

GoBrain.Core/src/dom.js, line 401

Checks if the node has a specific element as first level child.

Checks if the node has a specific element as first level child.

Name Type Description
child GoBrain.Node | HTMLElement

The potential child to check against.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
Boolean

hasClass(clazz, element){Boolean}

GoBrain.Core/src/dom.js, line 414

Checks if the node has a specific css class.

Checks if the node has a specific css class.

Name Type Description
clazz String

The css class to look for.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
Boolean

hasDescendant(descendant, element){Boolean}

GoBrain.Core/src/dom.js, line 427

Checks if the node has a specific element as descendant.

Checks if the node has a specific element as descendant.

Name Type Description
descendant GoBrain.Node | HTMLElement

The potential descendant to check against.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
Boolean

height(value, element){GoBrain.Node|Number}

GoBrain.Core/src/dom.js, line 440

Gets or sets the node height.

Gets or sets the node height.

Name Type Description
value Number | String optional

The new height.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node | Number

hide(element){GoBrain.Node}

GoBrain.Core/src/dom.js, line 453

Hides the node.

Hides the node.

Name Type Description
element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node

innerContent(content, element){GoBrain.Node|*}

GoBrain.Core/src/dom.js, line 465

Gets or sets node inner content.

Gets or sets node inner content.

Name Type Description
content * optional

The content to set.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node | *

insertAfter(newElement, element){GoBrain.Node}

GoBrain.Core/src/dom.js, line 478

Inserts a node/element after the node.

Inserts a node/element after the node.

Name Type Description
newElement GoBrain.Node | HTMLElement

The node element to insert.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node

insertBefore(newElement, element){GoBrain.Node}

GoBrain.Core/src/dom.js, line 491

Inserts a node/element before the node.

Inserts a node/element before the node.

Name Type Description
newElement GoBrain.Node | HTMLElement

The node element to insert.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node

isFullscreen(){Boolean}

GoBrain.Core/src/dom.js, line 504

Checks whether the application is currently in fullscreen or not.

Checks whether the application is currently in fullscreen or not.

Returns:
Type Description
Boolean

matches(selector, element){Boolean}

GoBrain.Core/src/dom.js, line 528

Checks if the node matches a selector.

Checks if the node matches a selector.

Name Type Description
selector String

The selector to check against.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
Boolean

nextSibling(element){GoBrain.Node|null}

GoBrain.Core/src/dom.js, line 541

Gets the node's next sibling.

Gets the node's next sibling.

Name Type Description
element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node | null

parent(element){GoBrain.Node}

GoBrain.Core/src/dom.js, line 553

Gets the node's parent node.

Gets the node's parent node.

Name Type Description
element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node

previousSibling(element){GoBrain.Node|null}

GoBrain.Core/src/dom.js, line 565

Gets the node's previous sibling.

Gets the node's previous sibling.

Name Type Description
element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node | null

query(query, element){Array.<GoBrain.Node>}

GoBrain.Core/src/dom.js, line 577

Gets all nodes beneath node that have a matching query.

Gets all nodes beneath node that have a matching query.

Name Type Description
query String

The query to look for.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
Array.<GoBrain.Node>

remove(element){null}

GoBrain.Core/src/dom.js, line 590

Removes the node.

Removes the node.

Name Type Description
element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
null

removeChild(child, parent){GoBrain.Node}

GoBrain.Core/src/dom.js, line 602

Removes a child from the node.

Removes a child from the node.

Name Type Description
child GoBrain.Node | HTMLElement

The child to remove.

parent GoBrain.Node | HTMLElement optional

The parent node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node

removeClass(clazz, element){GoBrain.Node}

GoBrain.Core/src/dom.js, line 615

Removes a css class from the node.

Removes a css class from the node.

Name Type Description
clazz String

The css class to remove.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node

removeEventListener(event, handler, options, element){GoBrain.Node}

GoBrain.Core/src/dom.js, line 628

Removes an event listener.

Removes an event listener.

Name Type Description
event String

Event to remove listener from.

handler function

Handler to remove.

options Boolean | Object

Options to use to remove the event handler. If boolean, whether or not to remove passive handler, if supported.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node

removeResizeListener(handler, element)

GoBrain.Core/src/dom.js, line 776

Removes a resize listener.

Removes a resize listener.

Name Type Description
handler function

Handler to remove.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

show(element){GoBrain.Node}

GoBrain.Core/src/dom.js, line 643

Shows the node.

Shows the node.

Name Type Description
element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node

style(property, value, element){GoBrain.Node|*}

GoBrain.Core/src/dom.js, line 655

Gets or sets a node style property.

Gets or sets a node style property.

Name Type Description
property String

The style property name.

value * optional

The style property value.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node | *

toggleClass(clazz, element){GoBrain.Node}

GoBrain.Core/src/dom.js, line 669

Toggles a css class, if the node has the class it will be removed otherwise it will be added.

Toggles a css class, if the node has the class it will be removed otherwise it will be added.

Name Type Description
clazz String

The css class to toggle.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node

width(value, element){GoBrain.Node|Number}

GoBrain.Core/src/dom.js, line 682

Gets or sets the node width.

Gets or sets the node width.

Name Type Description
value Number | String optional

The new width.

element GoBrain.Node | HTMLElement optional

The node/element to use instead of the root.

Returns:
Type Description
GoBrain.Node | Number