Bug 8856: Web Inspector should show the Xpath for the selected node
http://bugzilla.opendarwin.org/show_bug.cgi?id=8856
Adds an Xpath area to the Node panel.
* WebInspector/webInspector/inspector.css:
* WebInspector/webInspector/inspector.html:
* WebInspector/webInspector/inspector.js:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@14319
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2006-05-11 Timothy Hatcher <timothy@apple.com>
+
+ Reviewed by Darin.
+
+ Bug 8856: Web Inspector should show the Xpath for the selected node
+ http://bugzilla.opendarwin.org/show_bug.cgi?id=8856
+
+ Adds an Xpath area to the Node panel.
+
+ * WebInspector/webInspector/inspector.css:
+ * WebInspector/webInspector/inspector.html:
+ * WebInspector/webInspector/inspector.js:
+
2006-05-11 Timothy Hatcher <timothy@apple.com>
Reviewed by Anders.
color: rgba(255,255,255,0.6);
}
+#nodeXpath {
+ margin-top: 4px;
+ height: 60px;
+}
+
+#nodeXpathValue {
+ -webkit-user-select: text;
+ -webkit-dashboard-region: dashboard-region(control rectangle);
+ word-wrap: break-word;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ height: 32px;
+}
+
#nodeContents {
display: -webkit-box;
-webkit-box-flex: 12;
<span class="label">Namespace URI:</span>
<span class="value"><div id="nodeNamespace"></div></span>
</div>
+ <div id="nodeXpath">
+ <div class="infoRow header">
+ <span class="label" style="width: initial">Xpath</span>
+ </div>
+ <div id="nodeXpathValue"></div>
+ </div>
<div id="elementAttributes">
<div class="infoRow header">
<span class="label" style="width: initial">Element Attributes</span>
return "(unknown)";
}
+function xpathForNode(node)
+{
+ var path = "";
+ while (node) {
+ if (node.nodeType == Node.DOCUMENT_NODE) {
+ path = "/" + path;
+ } else {
+ if (node.nodeName == "HTML" || node.nodeName == "BODY") {
+ path = node.nodeName.toLowerCase() + (path.length ? "/" + path : "");
+ } else {
+ var index = 1;
+ var child = (node.parentNode ? node.parentNode.firstChild : null);
+ while (child) {
+ if (node == child)
+ break;
+ if (child.nodeName == node.nodeName)
+ index++;
+ child = child.nextSibling;
+ }
+
+ var name = node.nodeName.toLowerCase();
+ if (node.nodeType == Node.TEXT_NODE)
+ name = "text()";
+
+ path = name + "[" + index + "]" + (path.length ? "/" + path : "");
+ }
+ }
+
+ node = node.parentNode;
+ }
+
+ return path;
+}
+
function updatePanes()
{
for (var i = 0; i < tabNames.length; i++)
document.getElementById("nodeContents").style.display = "none";
}
+ document.getElementById("nodeXpathValue").textContent = xpathForNode(focusedNode);
+
document.getElementById("nodeType").textContent = nodeTypeName(focusedNode);
document.getElementById("nodeName").textContent = focusedNode.nodeName;