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
Highlight all nodes with 'data-brackets-id' value that matches id, or if id is an array, matches any of the given ids.
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);
}
Hide in-browser highlighting
function hide() {
switch (_highlight.type) {
case "node":
Inspector.DOM.hideHighlight();
break;
case "css":
RemoteAgent.call("hideHighlight");
break;
}
_highlight = {};
}
Initialize the agent
function load() {
if (LiveDevelopment.config.experimental) {
RemoteAgent.on("highlight.HighlightAgent", _onRemoteHighlight);
}
}
Highlight a single node using DOM.highlightNode
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);
}
Redraw active highlights
function redraw() {
RemoteAgent.call("redrawHighlights");
}
Highlight all nodes affected by a CSS rule
function rule(name) {
if (_highlight.ref === name) {
return;
}
hide();
_highlight = {type: "css", ref: name};
RemoteAgent.call("highlightRule", name);
}
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;
});