Menu
©2015
Documentation generator: JsDoc Toolkit 2.4.0
Template: Codeview 1.2
Generated on: 2015-1-16 18:32

Class puredom.NodeSelection

  • Represents a collection of DOM Elements.
    Puredom methods that work with DOM elements generally return an instance of this.

  • Defined in: puredom.js
Class Summary
Constructor Attributes Constructor Name and Description
 
Creates a new selection containing the elements of nodes.

Method Summary

Method Attributes Method Name and Description
 
 
appendChild (child)
Append an element to the DOM.
 
Get a new Selection containing all direct child elements of the current Selection.
 
classify (className)
Add a CSS class to the selection.
 
clone (deep, newParent)
Clone the selection, optionally into a new parent node.
 
count ()
Get the number of elements in the Selection.
 
css (css, options, callback)
Apply CSS to elements.
 
declassify (className)
Remove a CSS class to the selection.
 
Get an Array of String representations of each element in the selection.
 
destroy ()
Remove all elements in the Selection from the DOM, and destroy them.
 
each (iterator)
Call an iterator function on each element in the selection, wrapping each in a new puredom.NodeSelection.
 
emit ()
 
exists ()
Check if the selection contains at least one element.
 
fadeIn (tween, callback)
This function tries quite hard to guess what particular fade effect is needed.
 
fadeOut (tween, callback, andIgnore)
The opposite of fadeIn().
 
 
first (n)
Get a new Selection containing only the first element in the current Selection.
 
Get a new Selection containing the first direct child element of the current Selection.
 
getResult (reverseIndex)
Get the result of the previous operation.
 
hasClass (className, ifAny)
Check if the selection contains only nodes with the given CSS class.
 
hide (andIgnore)
Hide elements.
 
html (content, asText)
Set the HTML contents of elements.
 
index (i, n)
Get a new Selection containing only the n element(s) in the current Selection starting at index i.
 
insertBefore (child, before)
Insert an element into the DOM before a given reference element.
 
insertInto (what)
Insert all elements in the Selection into a given parent.
 
last (n)
Get a new Selection containing only the last element in the current Selection.
 
Get a new Selection containing the last direct child element of the current Selection.
 
Localize the selection.
 
next ()
Get a new Selection containing the next sibling elements of each element in the current Selection.
 
Get the lower-case nodeName of an element.
 
nthChild (n)
Get a new Selection containing the direct child element of the current Selection at index n.
 
off (type, selector, handler)
Un-register an event handler.
 
on (type, selector, handler)
Register an event handler.
 
parent ()
Get a new Selection containing the de-duped parent elements of the current Selection.
 
prev ()
Get a new Selection containing the previous sibling elements of each element in the current Selection.
 
 
query (selector, options)
Search for elements within the Selection's tree that match the given CSS selector.
 
remove ()
Remove all elements in the Selection from the DOM.
 
 
selection (start, end)
Get or set the selected text of an input element.
 
setOpacity (opacity)
Set the opacity of each node in the selection.
 
show ()
Show elements.
 
Get a new Selection containing both the next and previous sibling elements of each element in the current Selection.
 
submit ()
Submit any forms in the Selection.
 
sumOf (method)
Call a method on each node in the selection and sum the results.
 
template (templateFields)
Template the Selection and all descendants based on data-tpl-id attributes.
 
text (text)
Get or set the textual content of elements.
 
Get a String representation of the selection's current contents.
 
trigger (type, e)
Fire an event on the selection.
 
uuid ()
Get a globally unique identifier for an element.
 
wait (millis, callback)
Call a function on the selection in the future.

Class Detail

puredom.NodeSelection(nodes)
Creates a new selection containing the elements of nodes.
This class is not generally instantiated directly - instead, use the puredom() function to query for elements or wrap an Array of elements with a selection.
Parameters:
{Array} nodes
An array of raw DOM nodes to wrap in a selection.

Method Detail

  • addEvent()
  • {this} appendChild(child)
    Append an element to the DOM.
    Parameters:
    {puredom.NodeSelection|HTMLElement} child
    An element or a Selection of elements to append
    Returns:
    {this}
  • {puredom.NodeSelection} children()
    Get a new Selection containing all direct child elements of the current Selection.
    Returns:
    {puredom.NodeSelection} children
  • {this} classify(className)
    Add a CSS class to the selection.
    Pass an Array and/or multiple arguments to add multiple classes.
    Parameters:
    {String} className
    A CSS class to add.
    Returns:
    {this}
  • {puredom.NodeSelection} clone(deep, newParent)
    Clone the selection, optionally into a new parent node.
    Parameters:
    {Boolean} deep Optional, Default: true
    Perform a deep clone, which clones all descendent nodes.
    {Object} newParent Optional
    Optionally inject into a new parentNode. Pass true to clone into the same parent.
    Returns:
    {puredom.NodeSelection} clonedSelection
  • {Number} count()
    Get the number of elements in the Selection.
    Returns:
    {Number} count
  • {this} css(css, options, callback)
    Apply CSS to elements.
    Parameters:
    {String|Object} css
    CSS to apply to the elements in the selection. Either a CSS-string, or an Object where the keys are CSS properties and the values are the corresponding values to apply.
    {Object} options Optional
    Options
    {Number|String} options.tween Optional
    Animate the application of the given CSS styles. Numeric values are treated as durations, String values must be a comma-separated value of the format: "duration,easing-method".
    {Function} options.callback Optional
    A function to call once the styles have been applied. If tweening/animating, gets called once the animation has completed.
    {Function} callback
    Same as options.callback, takes precidence when used.
    Returns:
    {this}
  • {this} declassify(className)
    Remove a CSS class to the selection.
    Pass an Array and/or multiple arguments to remove multiple classes.
    Parameters:
    {String} className
    A CSS class to remove.
    Returns:
    {this}
  • describe()
    Get an Array of String representations of each element in the selection.
    For a more logging-friendly option, see puredom.NodeSelection#describe.
  • {this} destroy()
    Remove all elements in the Selection from the DOM, and destroy them.
    Note: This also removes all elements from the Selection.
    Returns:
    {this}
  • {this} each(iterator)
    Call an iterator function on each element in the selection, wrapping each in a new puredom.NodeSelection.
    Note: Return false from within iterator to break out of the loop.
    Parameters:
    {Function} iterator
    Gets passed (element, index) for each element in the selection. The value of this is the selection itself.
    Returns:
    {this}
  • emit()
  • {Boolean} exists()
    Check if the selection contains at least one element.
    Returns:
    {Boolean} exists
  • {this} fadeIn(tween, callback)
    This function tries quite hard to guess what particular fade effect is needed.
    If the element that is already semi-transparent, it fades from the current opacity.
    If the element that is hidden but not explicitly transparent, it fades from opacity=0 (hidden).
    If the element is already 100% opaque (non-transparent), no animation is performed, and the callback is fired after a very small delay (to enforce async).
    Arguments are interchangeable for backward compatibility.
    Parameters:
    {Number|String} tween
    A tween value. Can be a {Number} duration, or {String} "duration,easing-method".
    {Function} callback Optional
    A function to call once the fade has completed. Gets passed the selection.
    Returns:
    {this}
  • fadeOut(tween, callback, andIgnore)
    The opposite of fadeIn(). Makes several guesses about the desired effect.
    Parameters:
    {Any}tween
    {Any}callback
    {Any}andIgnore
  • fireEvent()
  • Get a new Selection containing only the first element in the current Selection.
    Parameters:
    {Any}n
    Returns:
    {puredom.NodeSelection} first
  • {puredom.NodeSelection} firstChild()
    Get a new Selection containing the first direct child element of the current Selection.
    Returns:
    {puredom.NodeSelection} firstChild
  • {Any} getResult(reverseIndex)
    Get the result of the previous operation.
    Many puredom methods return the selection they were called on rather than a standard return value. This method gets the equivalent return value of the most recent selection method call.
    Parameters:
    {Number} reverseIndex Optional, Default: 0
    Optionally get an older return value. This value is a 0-based offset.
    Returns:
    {Any} returnValue, or undefined if no value was returned.
  • {Boolean} hasClass(className, ifAny)
    Check if the selection contains only nodes with the given CSS class.
    Parameters:
    {String} className
    The CSS class to check for
    {Boolean} ifAny Optional, Default: false
    If `true`, returns `true` only if *and* nodes have the given CSS class
    Returns:
    {Boolean}
  • {this} hide(andIgnore)
    Hide elements.
    Parameters:
    {Boolean} andIgnore Optional, Default: true
    If false, triggers "visibility:hidden" CSS, instead of "display:none".
    Returns:
    {this}
  • {String} html(content, asText)
    Set the HTML contents of elements.
    Parameters:
    {String} content Optional
    If set, updates the content of the elements. If not set, returns the HTML content of the first element.
    {Boolean} asText Optional, Default: auto
    If true, content will be treated as textual, if false content will be treated as HTML. Defaults to auto-detection of HTML.
    Returns:
    {String} text The HTML or textual contents of the first element in the selection, or the selection itself if html was not set.
  • {puredom.NodeSelection} index(i, n)
    Get a new Selection containing only the n element(s) in the current Selection starting at index i.
    Parameters:
    {Number} i
    A 0-based index of the elements(s) to return
    {Number} n Optional, Default: 1
    The number of elements to return
    Returns:
    {puredom.NodeSelection} slice
  • {this} insertBefore(child, before)
    Insert an element into the DOM before a given reference element.
    Parameters:
    {puredom.NodeSelection|HTMLElement} child
    An element or a Selection of elements to insert
    {puredom.NodeSelection|HTMLElement} before
    An element or a Selection to insert child before
    Returns:
    {this}
  • {this} insertInto(what)
    Insert all elements in the Selection into a given parent.
    Uses document fragments to improve performance when inserting a Selection containing multiple nodes.
    Parameters:
    {puredom.NodeSelection|HTMLElement} what
    A parent into which the selection should be inserted
    Returns:
    {this}
  • Get a new Selection containing only the last element in the current Selection.
    Parameters:
    {Any}n
    Returns:
    {puredom.NodeSelection} last
  • {puredom.NodeSelection} lastChild()
    Get a new Selection containing the last direct child element of the current Selection.
    Returns:
    {puredom.NodeSelection} firstChild
  • localize()
    Localize the selection.
    Defined in: i18n.js.
  • Get a new Selection containing the next sibling elements of each element in the current Selection.
    Returns:
    {puredom.NodeSelection} nextSiblings
  • {String} nodeName()
    Get the lower-case nodeName of an element.
    Note: Only returns a UUID for the first element in a selection.
    Note: In puredom, the window Object is given a nodeName of "#window".
    Returns:
    {String} nodeName
  • {puredom.NodeSelection} nthChild(n)
    Get a new Selection containing the direct child element of the current Selection at index n.
    Parameters:
    {Number} n
    A 0-based index.
    Returns:
    {puredom.NodeSelection} nthChild
  • {this} off(type, selector, handler)
    Un-register an event handler.
    		foo.removeEvent("click", clickHandler);
    Parameters:
    {String} type
    The event type
    {String} selector Optional
    Optionally fire only if the target matches a CSS selector
    {Function} handler
    The handler to remove
    Returns:
    {this}
  • {this} on(type, selector, handler)
    Register an event handler.
    When an event of the given type is triggered, the handler function is called.
    		function clickHandler(e){ alert(e.button); }
    		foo.addEvent("click", clickHandler);
    Parameters:
    {String} type
    An event type to listen for
    {String} selector Optional
    Optionally fire only if the event target matches a CSS selector
    {Function} handler
    A handler to call in response to the event
    Returns:
    {this}
  • Get a new Selection containing the de-duped parent elements of the current Selection.
    Returns:
    {puredom.NodeSelection} parents
  • Get a new Selection containing the previous sibling elements of each element in the current Selection.
    Returns:
    {puredom.NodeSelection} previousSiblings
  • {puredom.NodeSelection} query(selector, options)
    Search for elements within the Selection's tree that match the given CSS selector.
    Note: This is a scoped version of puredom(selector).
    Parameters:
    {String} selector
    A CSS selector
    {Object} options Optional
    Options, which get passed to puredom()
    Returns:
    {puredom.NodeSelection} results
  • {this} remove()
    Remove all elements in the Selection from the DOM.
    Returns:
    {this}
  • removeEvent()
  • {Object} selection(start, end)
    Get or set the selected text of an input element.
    Note: This only operates on the first element in the selection.
    Parameters:
    {Number} start
    A character index at which to start text selection
    {Number} end Optional, Default: start
    A character index at which to end text selection
    Returns:
    {Object} An object with start, end and text properties correspdonding to the current selection state.
  • {this} setOpacity(opacity)
    Set the opacity of each node in the selection.
    Parameters:
    {Number} opacity
    A value from 0 to 1
    Returns:
    {this}
  • {this} show()
    Show elements.
    Returns:
    {this}
  • {puredom.NodeSelection} siblings()
    Get a new Selection containing both the next and previous sibling elements of each element in the current Selection.
    Returns:
    {puredom.NodeSelection} siblings
  • {this} submit()
    Submit any forms in the Selection.
    Returns:
    {this}
  • {Number} sumOf(method)
    Call a method on each node in the selection and sum the results.
    Parameters:
    {Any}method
    Returns:
    {Number}
  • {this} template(templateFields)
    Template the Selection and all descendants based on data-tpl-id attributes.
    Each element with a data-tpl-id attribute will have it's contents updated with the corresponding value of that attribute when interpreted as a dot-notated key path within templateFields.
    data-tpl-id attribute values can optionally include a pipe-separated list of "filters".
    Example:

    Note: the "htmlEntities" filter is already added for you where needed.
    Parameters:
    {Object} templateFields Optional, Default: {}
    Template data fields. Nested Objects/Arrays are addressable via dot notation.
    Returns:
    {this}
  • {String} text(text)
    Get or set the textual content of elements. Omit text to retrieve the textual value instead of setting it.
    Parameters:
    {String} text Optional
    If set, replaces the textual content of elements.
    Returns:
    {String} text The textual contents of the first element in the selection, or the selection itself if text was not set.
  • toString()
    Get a String representation of the selection's current contents.
    For the raw Array description, see puredom.NodeSelection#describe.
  • {this} trigger(type, e)
    Fire an event on the selection.
    Parameters:
    {String} type
    An event type
    {Object|Event} e
    The event data
    Returns:
    {this}
  • {String} uuid()
    Get a globally unique identifier for an element.
    Note: Only returns a UUID for the first element in a selection.
    Returns:
    {String} uuid
  • {this} wait(millis, callback)
    Call a function on the selection in the future.
    Parameters:
    {Number} millis
    The number of milliseconds to wait before calling callback.
    {Function} callback
    The function to call in millis milliseconds. Gets called on the selection, so the value of this is the selection itself.
    Returns:
    {this}