Class JX.DOM
| Defined | src/lib/DOM.js:311 |
| Group | DOM and Markup |
| Extends | JX.Base |
|---|
Query and update the DOM. Everything here is static, this is essentially
a collection of common utility functions.
Tasks
Attaching Event Listeners
Changing DOM Content
Updating Nodes
Serializing Forms
Testing DOM Properties
Convenience Methods
Finding Nodes in the DOM
Changing View State
Unspecified
Methods
private static _getAutoID(node)
| parameters | wild | node | |
| return | wild | | |
This method is not documented.
private static void _insertContent(parent, content, mechanism, reverse)
| parameters | Node | parent | Node to add content to. |
| mixed | content | Content to add. |
| function | mechanism | Callback for actually adding the nodes. |
| bool | reverse | True if array elements should be passed to the mechanism in reverse order, i.e. the mechanism prepends nodes. |
| return | void | | |
Internal, add content to a node using some specified mechanism.
private static _mechanismAppend(node, content)
| parameters | Node | node | Node to append content to. |
| Node | content | Node to append. |
| return | wild | | |
Internal, add content to a node by appending.
private static void _mechanismPrepend(node, content)
| parameters | Node | node | Node to prepend content to. |
| Node | content | Node to prepend. |
| return | void | | |
Internal, add content to a node by prepending.
static alterClass(node, className, add)
| parameters | wild | node | |
| wild | className | |
| wild | add | |
| return | wild | | |
This method is not documented.
static void appendContent(node, content)
| parameters | Node | node | Node to append the content of. |
| mixed | content | Content to append. |
| return | void | | |
Append content to some node. This method uses the same content semantics
as other Javelin methods, see JX.$N() for an explanation. You
can also setContent() or prependContent().
static Dict convertFormToDictionary(form)
| parameters | Node | form | The form element to convert into a dictionary. |
| return | Dict | | A dictionary of form values. |
Converts a form into a dictionary mapping input names to values. This
will overwrite duplicate inputs in an undefined way.
static List convertFormToListOfPairs(form)
| parameters | Node | form | The form element to convert into a list of pairs. |
| return | List | | A list of <name, value> pairs. |
Converts a form into a list of <name, value> pairs.
Note: This function explicity does not match for submit inputs as there
could be multiple in a form. It's the caller's obligation to add the
submit input value if desired.
static Node find(root, tagname, sigil)
| parameters | Node | root | Root node to search beneath. |
| string | tagname | Tag name, like 'a' or 'textarea'. |
| string | sigil | Optionally, sigil which selected node must have. |
| return | Node | | Node uniquely identified by the criteria. |
Select a node uniquely identified by a root, tagname and sigil. This
is similar to JX.DOM.scry() but expects exactly one result.
static void focus(node)
| parameters | Node | node | Node to move cursor focus to, if possible. |
| return | void | | |
Focus a node safely. This is just a convenience wrapper that allows you
to avoid IE's habit of throwing when nearly any focus operation is
invoked.
static void hide()
| parameters | ... | | One or more nodes to set "display: none" on. |
| return | void | | |
Hide one or more elements, by setting display: none; on them. This is
a convenience method. See also show().
static htmlize(str)
| parameters | wild | str | |
| return | wild | | |
This method is not documented.
static JX.Event invoke(node, type, data)
| parameters | Node | node | The node to invoke an event on. |
| string | type | Custom event type. |
| dict | data | Event data. |
| return | JX.Event | | The event object which was dispatched to listeners. The main use of this is to test whether any listeners prevented the event. |
static bool isNode(node)
| parameters | wild | node | Something which might be a Node. |
| return | bool | | True if the parameter is a DOM node. |
Test if an object is a valid Node.
static bool isType(node, of_type)
| parameters | wild | node | Something which might be a Node. |
| string|list | of_type | One or more tags which you want to test for. |
| return | bool | | True if the object is a node, and it's a node of one of the provided types. |
Test if an object is a node of some specific (or one of several) types.
For example, this tests if the node is an <input />, <select />,
or <textarea />.
static object listen(node, type, path, callback)
| parameters | Node | node | The node to listen for events underneath. |
| string|list | type | One or more event types to listen for. |
| list? | path | A path to listen on, or a list of paths. |
| function | callback | Callback to invoke when a matching event occurs. |
| return | object | | A reference to the installed listener. You can later remove the listener by calling this object's remove() method. |
Listen for events occuring beneath a specific node in the DOM. This is
similar to @{JX.Stratcom.listen()}, but allows you to specify some node
which serves as a scope instead of the default scope (the whole document)
which you get if you install using @{JX.Stratcom.listen()} directly. For
example, to listen for clicks on nodes with the sigil 'menu-item' below
the root menu node:
static void prependContent(node, content)
| parameters | Node | node | Node to prepend content to. |
| mixed | content | Content to prepend. |
| return | void | | |
Prepend content to some node. This method uses the same content semantics
as other Javelin methods, see JX.$N() for an explanation. You
can also setContent() or appendContent().
static Node remove(node)
| parameters | Node | node | Node to remove. |
| return | Node | | The node. |
Remove a node from its parent, so it is no longer a child of any other
node.
static Node replace(node, replacement)
| parameters | Node | node | Node to replace. |
| mixed | replacement | Content to replace it with. |
| return | Node | | the original node. |
static void scrollTo(node)
| parameters | Node | node | Node to move document scroll position to, if possible. |
| return | void | | |
Scroll to the position of an element in the document.
static list scry(root, tagname, sigil)
| parameters | Node | root | Root node to search beneath. |
| string | tagname | Tag name, like 'a' or 'textarea'. |
| string | sigil | Optionally, a sigil which nodes are required to have. |
| return | list | | List of matching nodes, which may be empty. |
Search the document for DOM nodes by providing a root node to look
beneath, a tag name, and (optionally) a sigil. Nodes which match all
specified conditions are returned.
static void setContent(node, content)
| parameters | Node | node | Node to set content of. |
| mixed | content | Content to set. |
| return | void | | |
Set the content of some node. This uses the same content semantics as
other Javelin content methods, see JX.$N() for a detailed
explanation. Previous content will be replaced: you can also
prependContent() or appendContent().
static void show()
| parameters | ... | | One or more nodes to remove "display" styles from. |
| return | void | | |
Show one or more elements, by removing their "display" style. This
assumes you have hidden them with hide(), or explicitly set
the style to display: none;.
static textMetrics(node, pseudoclass, x)
| parameters | wild | node | |
| wild | pseudoclass | |
| wild | x | |
| return | wild | | |
This method is not documented.
static uniqID(node)
| parameters | wild | node | |
| return | wild | | |
This method is not documented.