Classes
Members
-
<static> observer
-
Description
Default DOMObserver for global usage.
Details
-
<static> screenWidth
-
Description
Document/window width
Details
-
<static> screenHeight
-
Description
Document/window height
Details
Methods
-
<static> addStyle( id, css )
-
Description
Adds a style to the document.
Parameters
Name Type Description idstring identifier to use as the element id
cssstring css to add to the document
Details
-
<static> removeStyle( id )
-
Description
Removes a style from the document.
Parameters
Name Type Description idstring original identifier used
Details
-
<static> addScript( id, url ) → {Promise}
-
Description
Adds/requires a remote script to be loaded
Parameters
Name Type Description idstring identifier to use for this script
urlstring url from which to load the script
Returns
Details
-
<static> removeScript( id )
-
Description
Removes a remote script from the document.
Parameters
Name Type Description idstring original identifier used
Details
-
<static> Q( selector ) → {DocumentFragment|NodeList|HTMLElement}
-
Description
This is my shit version of not having to use
$from jQuery. Meaning that you can pass a selector and it will automatically run module:DOMTools.query. It also means that you can pass a string of html and it will perform and returnparseHTML.Parameters
Name Type Description selectorstring Selector to query or HTML to parse
Returns
Details
-
<static> query( selector [, baseElement ] ) → {Element|null}
-
Description
Essentially a shorthand for
document.querySelector. If thebaseElementis not provideddocumentis used by default.Parameters
Name Type Attributes Description selectorstring Selector to query
baseElementElement <optional> Element to base the query from
Returns
Details
-
<static> queryAll( selector [, baseElement ] ) → {Array.<Element>}
-
Description
Essentially a shorthand for
document.querySelectorAll. If thebaseElementis not provideddocumentis used by default.Parameters
Name Type Attributes Description selectorstring Selector to query
baseElementElement <optional> Element to base the query from
Returns
Details
-
<static> parseHTML( html [, fragment ] ) → {DocumentFragment|NodeList|HTMLElement}
-
Description
Parses a string of HTML and returns the results. If the second parameter is true, the parsed HTML will be returned as a document fragment {@see https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment}. This is extremely useful if you have a list of elements at the top level, they can then be appended all at once to another node.
If the second parameter is false, then the return value will be the list of parsed nodes and there were multiple top level nodes, otherwise the single node is returned.
Parameters
Name Type Attributes Default Description htmlstring HTML to be parsed
fragmentboolean <optional> false Whether or not the return should be the raw
DocumentFragmentReturns
Details
-
<static> createElement()
-
Description
Alternate name for module:DOMTools.parseHTML
Details
-
<static> escapeHTML( html )
-
Description
Takes a string of html and escapes it using the brower's own escaping mechanism.
Parameters
Name Type Description htmlString html to be escaped
Details
-
<static> escapeID( id )
-
Description
Takes a string and escapes it for use as a DOM id.
Parameters
Name Type Description idString string to be escaped
Details
-
<static> addClass( element, ...classes ) → {Element}
-
Description
Adds a list of classes from the target element.
Parameters
Name Type Attributes Description elementElement Element to edit classes of
classesstring <repeatable> Names of classes to add
Returns
Details
-
<static> removeClass( element, ...classes ) → {Element}
-
Description
Removes a list of classes from the target element.
Parameters
Name Type Attributes Description elementElement Element to edit classes of
classesstring <repeatable> Names of classes to remove
Returns
Details
-
<static> toggleClass( element, classname [, indicator ] ) → {Element}
-
Description
When only one argument is present: Toggle class value; i.e., if class exists then remove it and return false, if not, then add it and return true. When a second argument is present: If the second argument evaluates to true, add specified class value, and if it evaluates to false, remove it.
Parameters
Name Type Attributes Description elementElement Element to edit classes of
classnamestring Name of class to toggle
indicatorboolean <optional> Optional indicator for if the class should be toggled
Returns
Details
-
<static> hasClass( element, classname ) → {boolean}
-
Description
Checks if an element has a specific class
Parameters
Name Type Description elementElement Element to edit classes of
classnamestring Name of class to check
Returns
Details
-
<static> replaceClass( element, oldName, newName ) → {Element}
-
Description
Replaces one class with another
Parameters
Name Type Description elementElement Element to edit classes of
oldNamestring Name of class to replace
newNamestring New name for the class
Returns
Details
-
<static> appendTo( thisNode, thatNode ) → {Node}
-
Description
Appends
thisNodetothatNodeParameters
Name Type Description thisNodeNode Node to be appended to another node
thatNodeNode Node for
thisNodeto be appended toReturns
Details
-
<static> prependTo( thisNode, thatNode ) → {Node}
-
Description
Prepends
thisNodetothatNodeParameters
Name Type Description thisNodeNode Node to be prepended to another node
thatNodeNode Node for
thisNodeto be prepended toReturns
Details
-
<static> insertAfter( thisNode, targetNode ) → {Node}
-
Description
Insert after a specific element, similar to jQuery's
thisElement.insertAfter(otherElement).Parameters
Name Type Description thisNodeNode The node to insert
targetNodeNode Node to insert after in the tree
Returns
Details
-
<static> after( thisNode, newNode ) → {Node}
-
Description
Insert after a specific element, similar to jQuery's
thisElement.after(newElement).Parameters
Name Type Description thisNodeNode The node to insert
newNodeNode Node to insert after in the tree
Returns
Details
-
<static> next( element [, selector ] ) → {Element}
-
Description
Gets the next sibling element that matches the selector.
Parameters
Name Type Attributes Default Description elementElement Element to get the next sibling of
selectorstring <optional> "" Optional selector
Returns
Details
-
<static> nextAll( element ) → {NodeList}
-
Description
Gets all subsequent siblings.
Parameters
Name Type Description elementElement Element to get next siblings of
Returns
Details
-
<static> nextUntil( element, selector ) → {Array.<Element>}
-
Description
Gets the subsequent siblings until an element matches the selector.
Parameters
Name Type Description elementElement Element to get the following siblings of
selectorstring Selector to stop at
Returns
Details
-
<static> previous( element [, selector ] ) → {Element}
-
Description
Gets the previous sibling element that matches the selector.
Parameters
Name Type Attributes Default Description elementElement Element to get the previous sibling of
selectorstring <optional> "" Optional selector
Returns
Details
-
<static> previousAll( element ) → {NodeList}
-
Description
Gets all preceeding siblings.
Parameters
Name Type Description elementElement Element to get preceeding siblings of
Returns
Details
-
<static> previousUntil( element, selector ) → {Array.<Element>}
-
Description
Gets the preceeding siblings until an element matches the selector.
Parameters
Name Type Description elementElement Element to get the preceeding siblings of
selectorstring Selector to stop at
Returns
Details
-
<static> indexInParent( node ) → {number}
-
Description
Find which index in children a certain node is. Similar to jQuery's
$.index()Parameters
Name Type Description nodeHTMLElement The node to find its index in parent
Returns
Details
-
<static> index()
-
Description
Shorthand for module:DOMTools.indexInParent
Details
-
<static> parent( element [, selector ] ) → {Element|null}
-
Description
Gets the parent of the element if it matches the selector, otherwise returns null.
Parameters
Name Type Attributes Default Description elementElement Element to get parent of
selectorstring <optional> "" Selector to match parent
Returns
Details
-
<static> findChild( element, selector ) → {Array.<Element>}
-
Description
Gets all children of Element that match the selector if provided.
Parameters
Name Type Description elementElement Element to get all children of
selectorstring Selector to match the children to
Returns
Details
-
<static> findChildren( element, selector ) → {Array.<Element>}
-
Description
Gets all children of Element that match the selector if provided.
Parameters
Name Type Description elementElement Element to get all children of
selectorstring Selector to match the children to
Returns
Details
-
<static> parents( element [, selector ] ) → {Array.<Element>}
-
Description
Gets all ancestors of Element that match the selector if provided.
Parameters
Name Type Attributes Default Description elementElement Element to get all parents of
selectorstring <optional> "" Selector to match the parents to
Returns
Details
-
<static> parentsUntil( element, selector ) → {Array.<Element>}
-
Description
Gets the ancestors until an element matches the selector.
Parameters
Name Type Description elementElement Element to get the ancestors of
selectorstring Selector to stop at
Returns
Details
-
<static> siblings( element [, selector ] ) → {Array.<Element>}
-
Description
Gets all siblings of the element that match the selector.
Parameters
Name Type Attributes Default Description elementElement Element to get all siblings of
selectorstring <optional> "*" Selector to match the siblings to
Returns
Details
-
<static> css( element, attribute [, value ] ) → {Element|string}
-
Description
Sets or gets css styles for a specific element. If
valueis provided then it sets the style and returns the element to allow for chaining, otherwise returns the style.Parameters
Name Type Attributes Description elementElement Element to set the CSS of
attributestring Attribute to get or set
valuestring <optional> Value to set for attribute
Returns
Details
-
<static> width( element [, value ] ) → {Element|string}
-
Description
Sets or gets the width for a specific element. If
valueis provided then it sets the width and returns the element to allow for chaining, otherwise returns the width.Parameters
Name Type Attributes Description elementElement Element to set the CSS of
valuestring <optional> Width to set
Returns
Details
-
<static> height( element [, value ] ) → {Element|string}
-
Description
Sets or gets the height for a specific element. If
valueis provided then it sets the height and returns the element to allow for chaining, otherwise returns the height.Parameters
Name Type Attributes Description elementElement Element to set the CSS of
valuestring <optional> Height to set
Returns
Details
-
<static> text( element [, text ] ) → {string}
-
Description
Sets the inner text of an element if given a value, otherwise returns it.
Parameters
Name Type Attributes Description elementElement Element to set the text of
textstring <optional> Content to set
Returns
Details
-
<static> innerWidth( element ) → {number}
-
Description
Returns the innerWidth of the element.
Parameters
Name Type Description elementElement Element to retrieve inner width of
Returns
Details
-
<static> innerHeight( element ) → {number}
-
Description
Returns the innerHeight of the element.
Parameters
Name Type Description elementElement Element to retrieve inner height of
Returns
Details
-
<static> outerWidth( element ) → {number}
-
Description
Returns the outerWidth of the element.
Parameters
Name Type Description elementElement Element to retrieve outer width of
Returns
Details
-
<static> outerHeight( element ) → {number}
-
Description
Returns the outerHeight of the element.
Parameters
Name Type Description elementElement Element to retrieve outer height of
Returns
Details
-
<static> offset( element ) → {Offset}
-
Description
Gets the offset of the element in the page.
Parameters
Name Type Description elementElement Element to get offset of
Returns
Details
-
<static> on( element, event, delegate [, callback ] ) → {module:DOMTools~CancelListener}
-
Description
This is similar to jQuery's
onfunction and can hopefully be used in the same way.Rather than attempt to explain, I'll show some example usages.
The following will add a click listener (in the
myPluginnamespace) toelement.DOMTools.on(element, "click.myPlugin", () => {console.log("clicked!");});The following will add a click listener (in the
myPluginnamespace) toelementthat only fires when the target is a.blockelement.DOMTools.on(element, "click.myPlugin", ".block", () => {console.log("clicked!");});The following will add a click listener (without namespace) to
element.DOMTools.on(element, "click", () => {console.log("clicked!");});The following will add a click listener (without namespace) to
elementthat only fires once.const cancel = DOMTools.on(element, "click", () => {console.log("fired!"); cancel();});Parameters
Name Type Attributes Description elementElement Element to add listener to
eventstring Event to listen to with option namespace (e.g. "event.namespace")
delegatestring | callable Selector to run on element to listen to
callbackcallable <optional> Function to fire on event
Returns
Details
-
<static> once( element, event, delegate [, callback ] ) → {module:DOMTools~CancelListener}
-
Description
Functionality for this method matches module:DOMTools.on but automatically cancels itself and removes the listener upon the first firing of the desired event.
Parameters
Name Type Attributes Description elementElement Element to add listener to
eventstring Event to listen to with option namespace (e.g. "event.namespace")
delegatestring | callable Selector to run on element to listen to
callbackcallable <optional> Function to fire on event
Returns
Details
-
<static> off( element [, event [, delegate [, callback ] ] ] ) → {Element}
-
Description
This is similar to jQuery's
offfunction and can hopefully be used in the same way.Rather than attempt to explain, I'll show some example usages.
The following will remove a click listener called
onClick(in themyPluginnamespace) fromelement.DOMTools.off(element, "click.myPlugin", onClick);The following will remove a click listener called
onClick(in themyPluginnamespace) fromelementthat only fired when the target is a.blockelement.DOMTools.off(element, "click.myPlugin", ".block", onClick);The following will remove a click listener (without namespace) from
element.DOMTools.off(element, "click", onClick);The following will remove all listeners in namespace
myPluginfromelement.DOMTools.off(element, ".myPlugin");The following will remove all click listeners in namespace
myPluginfrom all elements.DOMTools.off("click.myPlugin");The following will remove all listeners in namespace
myPluginfrom all elements.DOMTools.off(".myPlugin");Parameters
Name Type Attributes Description elementElement | string Element to remove listener from
eventstring <optional> Event to listen to with option namespace (e.g. "event.namespace")
delegatestring | callable <optional> Selector to run on element to listen to
callbackcallable <optional> Function to fire on event
Returns
Details
-
<static> onMountChange( node, callback, onMount )
-
Description
Adds a listener for when the node is added/removed from the document body. The listener is automatically removed upon firing.
Parameters
Name Type Default Description nodeHTMLElement node to wait for
callbackcallable function to be performed on event
onMountboolean true determines if it should fire on Mount or on Unmount
Details
-
<static> onMount()
-
Description
Shorthand for module:DOMTools.onMountChange with third parameter
trueDetails
-
<static> onUnmount()
-
Description
Shorthand for module:DOMTools.onMountChange with third parameter
falseDetails
-
<static> onAdded()
-
Description
Alias for module:DOMTools.onMount
Details
-
<static> onRemoved()
-
Description
Alias for module:DOMTools.onUnmount
Details
-
<static> wrap( elements )
-
Description
Helper function which combines multiple elements into one parent element
Parameters
Name Type Description elementsArray.<HTMLElement> array of elements to put into a single parent
Details
-
<static> resolveElement( node )
-
Description
Resolves the node to an HTMLElement. This is mainly used by library modules.
Parameters
Name Type Description nodejQuery | Element node to resolve
Details
Type Definitions
-
CancelListener()
-
Description
Function that automatically removes added listener.
Details