NodeFire Library

core  1.0.6

NodeFire Library > core > NF.util.dom
Search:
 
Filters

static Class NF.util.dom

The DOM class provides extended access to document object level querying and manipulation.

Methods

addChild

Node addChild ( addWhere , newNode , refNode )
Adds a child node to the DOM. Optionally specify the addWhere parameter to target the insertion location, options are...
  • "first-child" = Add as the first child of the refNode
  • "last-child" = Default: Add as the last child of the refNode
Parameters:
addWhere <null | string> Optional, Where to add the Node... "first-child", "last-child" [Default: "last-child"]
newNode <Node> The Node to be added.
refNode <Node> Adds the new Node relative to the refNode.
Returns: Node
The added Node.

addClass

boolean addClass ( Node , className )
Adds a className to a Node.
Parameters:
Node <Node> The Node to add the className to.
className <string> The className to add.
Returns: boolean
True if the class name was not already present and added.

addNode

Node addNode ( addWhere , newNode , refNode )
Adds a Node to the DOM. The addWhere parameter specifies where to add the Node, options include...
  • "first-child" = Add as the first child of the refNode
  • "last-child" = Add as the last child of the refNode
  • "replace-child" = Remove all refNode children and add as an only child.
  • "before" = Add as a sibling before the refNode.
  • "after" = Add as a sibling after the refNode.
  • "replace" = Replace the refNode with the newNode
Parameters:
addWhere <string> Where to add the Node... "first-child", "last-child", "replace-child", "before", "after", "replace"
newNode <Node> The Node to be added.
refNode <Node> Adds the new Node relative to the refNode.
Returns: Node
The added Node.

createNodeFromHTML

Node createNodeFromHTML ( HTML )
Creates a new node from an HTML string.
Parameters:
HTML <string> A string with the HTML node to be created.
Returns: Node
The created Node.

getChild

Node getChild ( parentNode , type , filterClass , matchAllClasses )
Get a parents child Node. The filterClass parameter can be used to target children with specific names applied to the Nodes class attribute. When using a classFilter and a N'th occurance type, the N'th occurance of children matching the classFilter is returned.
Parameters:
parentNode <Node>
type <int || string> The type of child to get... "first-child", "last-child", or N'th occurance.
filterClass <string | string Array> Only return a child with the matching class name.
matchAllClasses <boolean> If supplying an array of multiple filterClass names, match all class names or one class name. Default behavior is one class name.
Returns: Node
A child Node.

getFirstAncestorByClassName

Node getFirstAncestorByClassName ( rootNode , className , classNameFilter )
Get the first parent Node with a matching className.
Parameters:
rootNode <Node> The root node to search from.
className <string> The className to match.
classNameFilter <string> Optional, if a node with a matching classNameFilter is of closer relation then the function returns false;
Returns: Node
The matching ancestor Node.

getFirstDecendantByClassName

Node getFirstDecendantByClassName ( rootNode , className , checkRoot )
Get the first descendant Node with a matching className.
Parameters:
rootNode <Node> The root node to search from.
className <string> The className to match.
checkRoot <boolean> Optional, include the root node in the search;
Returns: Node
The matching descendant Node.

getLocationMatchedLinks

Array getLocationMatchedLinks ( rootNode , match )
Gets an Array of links where the href attribute matches the curent document location in the browsers address bar. The optional match parameter can futher target the portioin of the URL to match. The match parameter is an Array of strings which may include any combination of ["resource", "hash", "search"].
  • "resource" = The file name, location, and protocol.
  • "hash" = The bookmark portion of the URL, e.g. (#myBookmark).
  • "search" = The query string portion of the url, e.g. (?myQueryString).
Parameters:
rootNode <Node> The root Node to start the search from.
match <string Array> An array of match options, e.g ["resource", "hash", "search"]
Returns: Array
An array of matching Nodes.

getNodesByClassName

Array getNodesByClassName ( rootNode , className )
Searches all descendant Nodes from the rootNode and returns an Array of matching nodes.
Parameters:
rootNode <Node> The root Node to search from.
className <string> The className to match.
Returns: Array
An Array of matching nodes.

getSibling

Node getSibling ( refNode , type , classFilter , tagFilter , childNodeTest )
Get the previous or next sibling. Optional classFilter, tagFilter, and childNodeTest parameters help target specific siblings.
Parameters:
refNode <Node> The reference Node to search from.
type <string> The type of search to perform ('next' or 'previous').
classFilter <string> Optional className to match.
tagFilter <string> Optional tagName to match.
childNodeTest <function> Optional function call test where the first paramter is the refNode.
Returns: Node
The matching sibling Node.

hasClass

Array hasClass ( Node , className , matchAll )
Determines if the className is attached to the class attribute for each node.
Parameters:
Node <Node | Node Array> The node or an Array of Nodes to query.
className <string | string Array> The class name or an array of classNames.
matchAll <boolean> Match all classNames or a single className.
Returns: Array
An Array of nodes with matching class names.

isDescendant

boolean isDescendant ( refNode , descendant )
Determines if a node is a descendant of another node.
Parameters:
refNode <Node> The reference node or ancestor.
descendant <Node> The potential descendant node.
Returns: boolean
True if the refNode is an ancestor of the potential descendant node.

isRelation

boolean isRelation ( Node1 , Node2 )
Determines if two nodes are related by ancestry or descendancy.
Parameters:
Node1 <Node>
Node2 <Node>
Returns: boolean
True if the nodes are connected by a ancestor or descendant relationship.

removeChildren

Node Array removeChildren ( parentNode , classFilter )
Remove a parents child Nodes. The optional classFilter can be a single string or Array of strings. Nodes with class attributes matching the classFilter will not be removed.
Parameters:
parentNode <Node> The childrens parent Node.
classFilter <string | string Array> Nodes with className attributes matching the classFilter will not be removed.
Returns: Node Array
The Child Nodes removed.

removeClass

boolean removeClass ( Node , className )
Removes a className from a Node.
Parameters:
Node <Node> The Node to remove the className from.
className <string> The className to remove.
Returns: boolean
True if the class name was present and removed.

removeNode

Node Array removeNode ( Node )
Removes a single Node or an Array of Nodes.
Parameters:
Node <Node | Node Array> The Node or Array of Nodes to remove.
Returns: Node Array
The nodes removed.

unwrapNode

Node unwrapNode ( wrapperNode , targetNode )
Unwrap a Node.
Parameters:
wrapperNode <Node> The wrapper node to remove.
targetNode <Node> The node within the wrapper to preserve.
Returns: Node
The unwrapped preserved node.

wrapNode

Node wrapNode ( wrapNode , wrapperNode , targetNode )
Wrap a Node within a Node.
Parameters:
wrapNode <Node> The Node to wrap.
wrapperNode <Node | HTML string> The node or HTML string to use as the wrapper.
targetNode <Node> Optional target node within the wrapper to use as an inner wrapper container.
Returns: Node
The Node wrapper.


Copyright © 2011 OpenCube: Inc. All rights reserved.