dom
- auto-gen TOC: {:toc}# Module: dom
dom
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 15
Members
<_static_> blockLevelList :string
List of block level elements separated by bars ( | ) |
Type:
*string*
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 769
<_static_> COMMENT_NODE :number
Node type constant for comment nodes
Type:
*number*
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 38
<_static_> DOCUMENT_FRAGMENT_NODE :number
Node type constant for document fragments
Type:
*number*
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 52
<_static_> DOCUMENT_NODE :number
Node type document nodes
Type:
*number*
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 45
<_static_> ELEMENT_NODE :number
Node type constant for element nodes
Type:
*number*
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 24
<_static_> EVENT_BUBBLE :boolean
For on() and off() if to add/remove the event to the bubble phase
Type:
*boolean*
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 192
<_static_> EVENT_CAPTURE :boolean
For on() and off() if to add/remove the event to the capture phase
Type:
*boolean*
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 184
<_static_> TEXT_NODE :number
Node type constant for text nodes
Type:
*number*
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 31
Methods
<_static_> addClass(node, className)
Parameters:
Name | Type | Description |
---|---|---|
node |
HTMLElement | |
className |
string |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 495
<_static_> appendChild(node, child)
Appends child to parent node
Parameters:
Name | Type | Description |
---|---|---|
node |
HTMLElement | |
child |
HTMLElement |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 161
<_static_> attr(node, attr, value)
If only attr param is specified it will get the value of the attr param.
If value is specified but null the attribute will be removed otherwise the attr value will be set to the passed value.
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
node |
HTMLElement | ||
attr |
string | ||
value |
string | optional nullable |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 286
<_static_> canHaveChildren(node) → {boolean}
List of elements that do not allow children separated by bars ( | ) |
Parameters:
Name | Type | Description |
---|---|---|
node |
Node |
Since: - 1.4.5|
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 779
Returns:
Type boolean
<_static_> closest(node, selector) → {HTMLElement|undefined}
Checks the passed node and all parents and returns the first matching node if any.
Parameters:
Name | Type | Description |
---|---|---|
node |
HTMLElement | |
selector |
string |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 138
Returns:
Type HTMLElement|undefined
<_static_> contains(node, child) → {boolean}
Returns true if node contains child otherwise false.
This differs from the DOM contains() method in that if node and child are equal this will return false.
Parameters:
Name | Type | Description |
---|---|---|
node |
Node | |
child |
HTMLElement |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 442
Returns:
Type boolean
<_static_> convertElement(element, toTagName) → {HTMLElement}
Converts an element from one type to another.
For example it can convert the element to
Parameters:
Name | Type | Description |
---|---|---|
element |
HTMLElement | |
toTagName |
string |
Since: - 1.4.4|
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 739
Returns:
Type HTMLElement
<_static_> copyCSS(from, to)
Copy the CSS from 1 node to another.
Only copies CSS defined on the element e.g. style attr.
Parameters:
Name | Type | Description |
---|---|---|
from |
HTMLElement | |
to |
HTMLElement |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 826
<_static_> createElement(tag, attributes, context) → {HTMLElement}
Creates an element with the specified attributes
Will create it in the current document unless context is specified.
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
tag |
string | ||
attributes |
object.<string, string> | optional | |
context |
Document | optional |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 75
Returns:
Type HTMLElement
<_static_> css(node, rule, value) → {string|number|undefined}
Gets a computed CSS values or sets an inline CSS value
Rules should be in camelCase format and not hyphenated like CSS properties.
Parameters:
Name | Type | Argument | Description | |
---|---|---|---|---|
node |
HTMLElement | |||
rule |
object | string | ||
value |
string | number | optional |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 355
Returns:
Type string|number|undefined
<_static_> data(node, key, value) → {object|undefined}
Gets or sets the data attributes on a node
Unlike the jQuery version this only stores data in the DOM attributes which means only strings can be stored.
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
node |
Node | ||
key |
string | optional | |
value |
string | optional |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 388
Returns:
Type object|undefined
<_static_> extractContents(startNode, endNode) → {DocumentFragment}
Extracts all the nodes between the start and end nodes
Parameters:
Name | Type | Description |
---|---|---|
startNode |
HTMLElement | The node to start extracting at |
endNode |
HTMLElement | The node to stop extracting at |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 1012
Returns:
Type DocumentFragment
<_static_> find(node, selector) → {NodeList}
Finds any child nodes that match the selector
Parameters:
Name | Type | Description |
---|---|---|
node |
HTMLElement | |
selector |
string |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 173
Returns:
Type NodeList
<_static_> findCommonAncestor(node1, node2) → {HTMLElement}
Finds the common parent of two nodes
Parameters:
Name | Type | Description |
---|---|---|
node1 |
HTMLElement | |
node2 |
HTMLElement |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 892
Returns:
Type HTMLElement
<_static_> fixNesting(node)
Fixes block level elements inside in inline elements.
Also fixes invalid list nesting by placing nested lists inside the previous li tag or wrapping them in an li tag.
Parameters:
Name | Type | Description |
---|---|---|
node |
HTMLElement |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 839
<_static_> getOffset(node) → {object}
Gets the offset position of an element
Parameters:
Name | Type | Description |
---|---|---|
node |
HTMLElement |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 1028
Returns:
An object with left and top properties
Type object
<_static_> getSibling(node, node, previous) → {Node}
Parameters:
Name | Type | Argument | Default | Description |
---|---|---|---|---|
node |
Node | nullable | ||
node |
||||
previous |
boolean | optional | false |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 906
Returns:
Type Node
<_static_> getStyle(elm, property) → {string}
Gets the value of a CSS property from the elements style attribute
Parameters:
Name | Type | Description |
---|---|---|
elm |
HTMLElement | |
property |
string |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 1053
Returns:
Type string
<_static_> hasClass(node, className) → {boolean}
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
node |
HTMLElement | nullable | |
className |
string |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 486
Returns:
Type boolean
<_static_> hasStyle(elm, property, values) → {boolean}
Tests if an element has a style.
If values are specified it will check that the styles value matches one of the values
Parameters:
Name | Type | Argument | Description | |
---|---|---|---|---|
elm |
HTMLElement | |||
property |
string | |||
values |
string | Array | optional |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 1096
Returns:
Type boolean
<_static_> hasStyling(elm, node) → {boolean}
Checks if an element has any styling.
It has styling if it is not a plain <div> or <p> or if it has a class, style attribute or data.
Parameters:
Name | Type | Description |
---|---|---|
elm |
HTMLElement | |
node |
Since: - 1.4.4|
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 723
Returns:
Type boolean
<_static_> height(node, value) → {number|undefined}
Gets or sets the height of the passed node.
Parameters:
Name | Type | Argument | Description | |
---|---|---|---|---|
node |
HTMLElement | |||
value |
number | string | optional |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 570
Returns:
Type number|undefined
<_static_> hide(node)
Sets the passed elements display to none
Parameters:
Name | Type | Description |
---|---|---|
node |
HTMLElement |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 315
<_static_> insertBefore(node, refNode) → {Node}
Parameters:
Name | Type | Description |
---|---|---|
node |
Node | |
refNode |
Node |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 467
Returns:
Type Node
<_static_> is(node, selector) → {boolean}
Checks if node matches the given selector.
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
node |
HTMLElement | nullable | |
selector |
string |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 421
Returns:
Type boolean
<_static_> isInline(elm, includeCodeAsBlock) → {boolean}
Checks if an element is inline
Parameters:
Name | Type | Argument | Default | Description |
---|---|---|---|---|
elm |
HTMLElement | |||
includeCodeAsBlock |
boolean | optional | false |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 802
Returns:
Type boolean
<_static_> isVisible(node, node) → {boolean}
Returns if a node is visible.
Parameters:
Name | Type | Description |
---|---|---|
node |
HTMLElement | |
node |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 618
Returns:
Type boolean
<_static_> off(node, events, selector, fn, capture)
Removes an event listener for the specified events.
Parameters:
Name | Type | Argument | Default | Description |
---|---|---|---|---|
node |
Node | |||
events |
string | |||
selector |
string | optional | ||
fn |
function | |||
capture |
boolean | optional | false |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 256
See:
- on() |
<_static_> on(node, events, selector, fn, capture)
Adds an event listener for the specified events.
Events should be a space separated list of events.
If selector is specified the handler will only be called when the event target matches the selector.
Parameters:
Name | Type | Argument | Default | Description |
---|---|---|---|---|
node |
Node | |||
events |
string | |||
selector |
string | optional | ||
fn |
function | |||
capture |
boolean | optional | false |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 210
See:
- off() |
<_static_> parent(node, selector) → {HTMLElement|undefined}
Gets the first parent node that matches the selector
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
node |
HTMLElement | ||
selector |
string | optional |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 120
Returns:
Type HTMLElement|undefined
<_static_> parents(node, selector) → {Array.<HTMLElement>}
Returns an array of parents that matches the selector
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
node |
HTMLElement | ||
selector |
string | optional |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 100
Returns:
Type Array.<HTMLElement>
<_static_> parseHTML(html, context) → {DocumentFragment}
Parses HTML into a document fragment
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
html |
string | ||
context |
Document | optional |
Since: - 1.4.4|
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 697
Returns:
Type DocumentFragment
<_static_> previousElementSibling(node, selector) → {HTMLElement}
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
node |
Node | ||
selector |
string | optional |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 452
Returns:
Type HTMLElement
<_static_> remove(node)
Removes the node from the DOM
Parameters:
Name | Type | Description |
---|---|---|
node |
HTMLElement |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 148
<_static_> removeAttr(node, attr)
Removes the specified attribute
Parameters:
Name | Type | Description |
---|---|---|
node |
HTMLElement | |
attr |
string |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 305
<_static_> removeClass(node, className)
Parameters:
Name | Type | Description |
---|---|---|
node |
HTMLElement | |
className |
string |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 509
<_static_> removeWhiteSpace(root)
Removes unused whitespace from the root and all it’s children.
Parameters:
Name | Type | Description |
---|---|---|
root |
HTMLElement |
Since: - 1.4.3|
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 921
<_static_> rTraverse(node, func, innermostFirst, siblingsOnly)
Like traverse but loops in reverse
Parameters:
Name | Type | Description |
---|---|---|
node |
||
func |
||
innermostFirst |
||
siblingsOnly |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 684
See:
- traverse |
<_static_> show(node)
Sets the passed elements display to default
Parameters:
Name | Type | Description |
---|---|---|
node |
HTMLElement |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 325
<_static_> toggle(node)
Toggles an elements visibility
Parameters:
Name | Type | Description |
---|---|---|
node |
HTMLElement |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 335
<_static_> toggleClass(node, className, state)
Toggles a class on node.
If state is specified and is truthy it will add the class.
If state is specified and is falsey it will remove the class.
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
node |
HTMLElement | ||
className |
string | ||
state |
boolean | optional |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 531
<_static_> traverse(node, func, innermostFirst, siblingsOnly, reverse)
Loop all child nodes of the passed node
The function should accept 1 parameter being the node. If the function returns false the loop will be exited.
Parameters:
Name | Type | Argument | Default | Description |
---|---|---|---|---|
node |
HTMLElement | |||
func |
function | Callback which is called with every | ||
child node as the first argument. | ||||
innermostFirst |
boolean | If the innermost node should be passed | ||
to the function before it’s parents. | ||||
siblingsOnly |
boolean | If to only traverse the nodes siblings | ||
reverse |
boolean | optional | false | If to traverse the nodes in reverse |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 654
<_static_> trigger(node, eventName, data)
Triggers a custom event with the specified name and sets the detail property to the data object passed.
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
node |
HTMLElement | ||
eventName |
string | ||
data |
object | optional |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 592
<_static_> width(node, value) → {number|undefined}
Gets or sets the width of the passed node.
Parameters:
Name | Type | Argument | Description | |
---|---|---|---|---|
node |
HTMLElement | |||
value |
number | string | optional |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 549
Returns:
Type number|undefined
<_inner_> camelCase(string) → {string}
Convert CSS property names into camel case
Parameters:
Name | Type | Description |
---|---|---|
string |
string |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 629
Returns:
Type string
<_inner_> classes(node) → {Array.<string>}
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
node |
HTMLElement | nullable |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 476
Returns:
Type Array.<string>
<_inner_> toFloat(value)
Parameters:
Name | Type | Description |
---|---|---|
value |
Source: out/C:/Users/John/repos/SCEditor/src/lib/dom.js, line 57