mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-31 14:15:30 +00:00
First Checked In.
This commit is contained in:
parent
4502f7816e
commit
6864952c47
76
xpfe/browser/src/DumpDOM.js
Normal file
76
xpfe/browser/src/DumpDOM.js
Normal file
@ -0,0 +1,76 @@
|
||||
// ----------------------
|
||||
// DumpDOM(node)
|
||||
//
|
||||
// Call this function to dump the contents of the DOM starting at the specified node.
|
||||
// Use node = document.documentElement to dump every element of the current document.
|
||||
// Use node = top.window.document.documentElement to dump every element.
|
||||
// ----------------------
|
||||
function DumpDOM(node)
|
||||
{
|
||||
dump("--------------------- DumpDOM ---------------------\n");
|
||||
|
||||
DumpNodeAndChildren(node, "");
|
||||
|
||||
dump("------------------- End DumpDOM -------------------\n");
|
||||
}
|
||||
|
||||
|
||||
// This function does the work of DumpDOM by recursively calling itself to explore the tree
|
||||
function DumpNodeAndChildren(node, prefix)
|
||||
{
|
||||
dump(prefix + "<" + node.nodeName);
|
||||
if ( node.nodeType == 1 )
|
||||
{
|
||||
DumpAttribute(node, "name");
|
||||
DumpAttribute(node, "style");
|
||||
DumpAttribute(node, "flex");
|
||||
|
||||
// id
|
||||
var text = node.getAttribute('id');
|
||||
if ( text && text[0] != '$' )
|
||||
dump(" id=\"" + text + "\"");
|
||||
|
||||
DumpAttribute(node, "value");
|
||||
DumpAttribute(node, "src");
|
||||
DumpAttribute(node, "onclick");
|
||||
DumpAttribute(node, "onchange");
|
||||
}
|
||||
|
||||
if ( node.nodeName == "#text" )
|
||||
dump(" = \"" + node.data + "\"");
|
||||
|
||||
dump(">\n");
|
||||
|
||||
// dump IFRAME && FRAME DOM
|
||||
if ( node.nodeName == "IFRAME" || node.nodeName == "FRAME" )
|
||||
{
|
||||
if ( node.name )
|
||||
{
|
||||
var wind = top.frames[node.name];
|
||||
if ( wind && wind.document && wind.document.documentElement )
|
||||
{
|
||||
dump(prefix + "----------- " + node.nodeName + " -----------\n");
|
||||
DumpNodeAndChildren(wind.document.documentElement, prefix + " ");
|
||||
dump(prefix + "--------- End " + node.nodeName + " ---------\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
// children of nodes (other than frames)
|
||||
else
|
||||
{
|
||||
var child = 0;
|
||||
while ( node.childNodes && child < node.childNodes.length )
|
||||
{
|
||||
DumpNodeAndChildren(node.childNodes[child], prefix + " ");
|
||||
child++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function DumpAttribute(node, attribute)
|
||||
{
|
||||
var text = node.getAttribute(attribute);
|
||||
if ( text )
|
||||
dump(" " + attribute + "=\"" + text + "\"");
|
||||
}
|
Loading…
Reference in New Issue
Block a user