Modules (180)

HighlightAgent

Description

HighlightAgent dispatches events for highlight requests from in-browser highlight requests, and allows highlighting nodes and rules in the browser.

Trigger "highlight" when a node should be highlighted

Dependencies

Functions

Public API

domElement

Highlight all nodes with 'data-brackets-id' value that matches id, or if id is an array, matches any of the given ids.

value string,Array<string>
of the 'data-brackets-id' to match, or an array of such.
    function domElement(ids) {
        var selector = "";
        if (!Array.isArray(ids)) {
            ids = [ids];
        }
        _.each(ids, function (id) {
            if (selector !== "") {
                selector += ",";
            }
            selector += "[data-brackets-id='" + id + "']";
        });
        rule(selector);
    }
Public API

hide

Hide in-browser highlighting

    function hide() {
        switch (_highlight.type) {
        case "node":
            Inspector.DOM.hideHighlight();
            break;
        case "css":
            RemoteAgent.call("hideHighlight");
            break;
        }
        _highlight = {};
    }
Public API

load

Initialize the agent

    function load() {
        if (LiveDevelopment.config.experimental) {
            RemoteAgent.on("highlight.HighlightAgent", _onRemoteHighlight);
        }
    }
Public API

node

Highlight a single node using DOM.highlightNode

node DOMNode
    function node(n) {
        if (!LiveDevelopment.config.experimental) {
            return;
        }

        if (!Inspector.config.highlight) {
            return;
        }

        // go to the parent of a text node
        if (n && n.type === 3) {
            n = n.parent;
        }

        // node cannot be highlighted
        if (!n || !n.nodeId || n.type !== 1) {
            return hide();
        }

        // node is already highlighted
        if (_highlight.type === "node" && _highlight.ref === n.nodeId) {
            return;
        }

        // highlight the node
        _highlight = {type: "node", ref: n.nodeId};
        Inspector.DOM.highlightNode(n.nodeId, Inspector.config.highlightConfig);
    }
Public API

redraw

Redraw active highlights

    function redraw() {
        RemoteAgent.call("redrawHighlights");
    }
Public API

rule

Highlight all nodes affected by a CSS rule

rule string
selector
    function rule(name) {
        if (_highlight.ref === name) {
            return;
        }
        hide();
        _highlight = {type: "css", ref: name};
        RemoteAgent.call("highlightRule", name);
    }
Public API

unload

Clean up

    function unload() {
        if (LiveDevelopment.config.experimental) {
            RemoteAgent.off(".HighlightAgent");
        }
    }


    EventDispatcher.makeEventDispatcher(exports);

    // Export public functions
    exports.hide = hide;
    exports.node = node;
    exports.rule = rule;
    exports.domElement = domElement;
    exports.redraw = redraw;
    exports.load = load;
    exports.unload = unload;
});