Top

class Node

smx. Node

The Node class wraps an XMLNode and provides an easy to use api to interact with it.

This class can be further extended by mixins from custom modules.

Details:
Mixes In:

Constructor

new Node(xmlNode)

Parameters
  • xmlNode {XMLNode}

Members

[0]:XMLNode

  • protected

Original XMLNode for reference

id:String

  • readonly

Direct access to XMLNode's id attribute.

name:String

  • readonly

Direct access to XMLNode name

type:String

  • readonly

Gets node name based on inner XMLNode.nodeName, default is smx, posible values are txt, md, html, ...

className:String

  • readonly

Gets node className based on inner XMLNode class attribute

document:SMXDocument

  • readonly

Gets the owner SMXDoxument

hash:String

  • readonly

Gets browser url hash

uri:String

  • readonly

Gets Uniform Resource Identifier. Concatenation of id values from parent nodes up to document root

url:String

  • readonly

Gets Uniform Resource Locator Concatenation of path values from parent nodes up to document root

src:String

  • readonly

Gets source file url for this node

parent:SMXNode

  • readonly

Gets parent node

ancestors:Array.<SMXNode>

  • readonly

Gets ancestors nodes, ordered from outer to inner.

root:SMXNode

  • readonly

Gets root node

children:Array.<SMXNode>

  • readonly

Gets children nodes

first:SMXNode

  • readonly

Gets first child node

last:SMXNode

  • readonly

Gets last child node

previous:SMXNode

  • readonly

Gets previous sibling node

next:SMXNode

  • readonly

Gets next sibling node

Methods

getIndex([selector]) → {Integer}

Gets the index position in parent's children. If node has no parent, will return 0. When using the optional parameter selector, the resultant index is calculated based only in the sibling nodes matching the given selector, if node does not match the selector itself will return -1.

Parameters
  • [selector] {String} :

    filter selector

Returns
  • {Integer}
Details:
Mixes In:

getText() → {String}

Gets the text content.

Returns
  • {String}
Details:
Mixes In:

getHTML() → {String}

Gets the html content.

Returns
  • {String}
Details:
Mixes In:

getData() → {String}

Gets the inner data content formatted according to node type.

Returns
  • {String}
Details:
Mixes In:

toString() → {String}

Gets the string representation.

Returns
  • {String}
Details:
Mixes In:

toJSON() → {Object}

Gets the Node as JSON Object representation.

Returns
  • {Object}
Details:
Mixes In:
To Do:
  • Not Implemented!

attr(name) → {String}

Gets the value for the given attribute name.

Parameters
  • name {String} :

    attribute name

Returns
  • {String} :

    value

Details:
Mixes In:
Example
//<movie tags="sci-fi, horror, adventures" />
$movie.attr('tags')
// => "sci-fi, horror, adventures"

get(name, [opt]) → {String}

This method is like attr but will use an attribute parser if there is one predefined for the given attribute name.

Parameters
  • name {String} :

    attribute name

  • [opt] {Object} :

    options to pass into attribute parser

Returns
  • {String} :

    value

Details:
Mixes In:

has(name) → {Boolean}

Checks if node has or not an attribute with the given name

Parameters
  • name {String} :

    attribute name

Returns
  • {Boolean}
Details:
Mixes In:

dsv(name, [delimiter]) → {Array.<String>}

Gets Delimiter Separated Value An utility method converts given attribute value into dsv array

Parameters
  • name {String} :

    the name of the attribute

  • [delimiter] {String} :

    delimiter string

Returns
  • {Array.<String>}
Details:
Mixes In:
Example
//<movie tags="sci-fi, horror, adventures">
$movie.dsv('tags',',')
// => ["sci-fi", "horror", "adventures"]

getAncestors(selector) → {Array.<smx.Node>}

Gets a list of all ancestor nodes matching the given selector, ordered from outer to inner.

Parameters
  • selector {String}
Returns
Details:
Mixes In:

isAncestorOf(node) → {Boolean}

Checks if node is an ancestor of another.

Parameters
Returns
  • {Boolean}
Details:
Mixes In:

isMatch(selector) → {Boolean}

Checks if node matches the given selector.

Parameters
  • selector {String} :

    css selector to match

Returns
  • {Boolean}
Details:
Mixes In:

find(selector) → {Array.<Node>}

Finds all descendant nodes matching the given selector.

Parameters
  • selector {String} :

    search selector

Returns
  • {Array.<Node>}
Details:
Mixes In:

findOne(selector) → {smx.Node}

This method is like find but returns only the first result.

Parameters
  • selector {String} :

    search selector

Returns
Details:
Mixes In:

getChildren([selector]) → {Array.<Node>}

Gets the children nodes matching the given selector.

Parameters
  • [selector] {String}
Returns
  • {Array.<Node>}
Details:
Mixes In:

getFirst([selector]) → {smx.Node}

Gets the first child node matching the given selector.

Parameters
  • [selector] {String}
Returns
Details:
Mixes In:

getLast([selector]) → {smx.Node}

Gets the last child node matching the given selector.

Parameters
  • [selector] {String}
Returns
Details:
Mixes In:

getChildAt(index) → {smx.Node}

Gets child node at given index

Parameters
  • index {Integer} :

    index position

Returns
Details:
Mixes In:

isDescendantOf(node) → {Boolean}

Checks if a node is child of another

Parameters
Returns
  • {Boolean}
Details:
Mixes In:

getNext([selector]) → {smx.Node}

Gets the next sibling node matching the given selector.

Parameters
  • [selector] {String} :

    filter selector

Returns
Details:
Mixes In:

getAllNext([selector]) → {Array.<smx.Node>}

Gets all next sibling nodes matching the given selector.

Parameters
  • [selector] {String} :

    filter selector

Returns
Details:
Mixes In:

getPrevious([selector]) → {smx.Node}

Gets the previous sibling node matching the given selector.

Parameters
  • [selector] {String} :

    filter selector

Returns
Details:
Mixes In:

getAllPrevious([selector]) → {Array.<smx.Node>}

Gets all previous sibling nodes matching the given selector.

Parameters
  • [selector] {String} :

    filter selector

Returns
Details:
Mixes In: