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
Members
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
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
ancestors:Array.<SMXNode>
- readonly
Gets ancestors nodes, ordered from outer to inner.
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
-
{Array.<smx.Node>}
Details:
- Mixes In:
isAncestorOf(node) → {Boolean}
Checks if node is an ancestor of another.
Parameters
-
node
{smx.Node}
:reference node
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
-
{smx.Node}
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
-
{smx.Node}
Details:
- Mixes In:
getLast([selector]) → {smx.Node}
Gets the last child node matching the given selector.
Parameters
-
[selector]
{String}
Returns
-
{smx.Node}
Details:
- Mixes In:
getChildAt(index) → {smx.Node}
Gets child node at given index
Parameters
-
index
{Integer}
:index position
Returns
-
{smx.Node}
Details:
- Mixes In:
isDescendantOf(node) → {Boolean}
Checks if a node is child of another
Parameters
-
node
{smx.Node}
:reference node
Returns
-
{Boolean}
Details:
- Mixes In:
getNext([selector]) → {smx.Node}
Gets the next sibling node matching the given selector.
Parameters
-
[selector]
{String}
:filter selector
Returns
-
{smx.Node}
Details:
- Mixes In:
getAllNext([selector]) → {Array.<smx.Node>}
Gets all next sibling nodes matching the given selector.
Parameters
-
[selector]
{String}
:filter selector
Returns
-
{Array.<smx.Node>}
Details:
- Mixes In:
getPrevious([selector]) → {smx.Node}
Gets the previous sibling node matching the given selector.
Parameters
-
[selector]
{String}
:filter selector
Returns
-
{smx.Node}
Details:
- Mixes In:
getAllPrevious([selector]) → {Array.<smx.Node>}
Gets all previous sibling nodes matching the given selector.
Parameters
-
[selector]
{String}
:filter selector
Returns
-
{Array.<smx.Node>}
Details:
- Mixes In: