diff options
author | Matt A. Tobin <email@mattatobin.com> | 2018-02-04 14:35:31 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2018-02-04 14:35:31 -0500 |
commit | 7edd685eee95759d66a457cf428f42e0dda94671 (patch) | |
tree | c4514958ea133084552be32d331c115afc509daa /devtools/server/css-logic.js | |
parent | 0083d404eff36f873cde465d50cd34b112bd124f (diff) | |
parent | fc7d9fade54dfbe275c4808dabe30a19415082e0 (diff) | |
download | UXP-7edd685eee95759d66a457cf428f42e0dda94671.tar UXP-7edd685eee95759d66a457cf428f42e0dda94671.tar.gz UXP-7edd685eee95759d66a457cf428f42e0dda94671.tar.lz UXP-7edd685eee95759d66a457cf428f42e0dda94671.tar.xz UXP-7edd685eee95759d66a457cf428f42e0dda94671.zip |
Merge branch 'master' into configurebuild-work
Diffstat (limited to 'devtools/server/css-logic.js')
-rw-r--r-- | devtools/server/css-logic.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/devtools/server/css-logic.js b/devtools/server/css-logic.js index f632871e1..c4a073635 100644 --- a/devtools/server/css-logic.js +++ b/devtools/server/css-logic.js @@ -793,6 +793,55 @@ CssLogic.findCssSelector = function (ele) { }; /** + * Get the full CSS path for a given element. + * @returns a string that can be used as a CSS selector for the element. It might not + * match the element uniquely. It does however, represent the full path from the root + * node to the element. + */ +CssLogic.getCssPath = function (ele) { + ele = getRootBindingParent(ele); + const document = ele.ownerDocument; + if (!document || !document.contains(ele)) { + throw new Error("getCssPath received element not inside document"); + } + + const getElementSelector = element => { + if (!element.localName) { + return ""; + } + + let label = element.nodeName == element.nodeName.toUpperCase() + ? element.localName.toLowerCase() + : element.localName; + + if (element.id) { + label += "#" + element.id; + } + + if (element.classList) { + for (let cl of element.classList) { + label += "." + cl; + } + } + + return label; + }; + + let paths = []; + + while (ele) { + if (!ele || ele.nodeType !== Node.ELEMENT_NODE) { + break; + } + + paths.splice(0, 0, getElementSelector(ele)); + ele = ele.parentNode; + } + + return paths.length ? paths.join(" ") : ""; +} + +/** * A safe way to access cached bits of information about a stylesheet. * * @constructor |