Modules (188)

DOMNode

Description

DOMNode represents a node in the DOM tree. It is constructed from a payload similar to {DOM.Node} and supports all basic tree operations. If a node has a nodeId it is registered with the DOMAgent via addNode(). The node's sourceOffset and sourceLength is stored as its location and length. Nodes can iterated using each() or find(). dump shows the entire tree on the console.

Dependencies

Functions

DOMNode

Constructor

the DOMAgent
agent is passed to avoid circular relationships
node DOM.Node
payload
    var DOMNode = function DOMNode(agent, payload) {
        this.agent = agent;
        this.children = [];
        this.attributes = {};

        // set the payload
        if (typeof payload === "string") {
            payload = DOMHelpers.extractPayload(payload);
        }
        if (payload) {
            this.setPayload(payload);
        }
        this.agent.addNode(this);
    };

    var TYPE_ELEMENT = DOMNode.TYPE_ELEMENT = 1; // element node
    var TYPE_ATTRIBUTE = DOMNode.TYPE_ATTRIBUTE = 2; // attribute node (unused)
    var TYPE_TEXT = DOMNode.TYPE_TEXT = 3; // text node
    var TYPE_COMMENT = DOMNode.TYPE_COMMENT = 8; // comment node <!-- -->
    var TYPE_DOCUMENT = DOMNode.TYPE_DOCUMENT = 9; // document node <!DOCUMENT>
Private

_fill

Fill a string to the given length (used for debug output)

source string
string
length integer
fill char
character
    function _fill(string, length, c) {
        if (c === undefined) {
            c = " ";
        }
        while (string.length < length) {
            string += c;
        }
        return string;
    }
Private

_makeFindCondition

Construct a find condition (used in find and findParent) The match can be a callback returning true or false, the node name or the node type.

or function
{string} or {number} match criteria
    function _makeFindCondition(match) {
        switch (typeof match) {
        case "function":
            return match;
        case "string":
            return function findCondition(name, node) {
                return node.name === name;
            }.bind(undefined, match.toUpperCase());
        case "number":
            return function findCondition(type, node) {
                return node.type === type;
            }.bind(undefined, match);
        default:
            console.error("Invalid find condition: " + match);
        }
    }