// This script opens a debug window and defines a function for writing into it.
// To activate the window, you can put this line in a
area
//
//
// Test for debugWin to see if debugging is enabled.
// To conditionally output debug, begin scripts with:
// dbgmsg = new Function("msg",
// (typeof debugWin == "undefined") ? "" : "debugMsg(msg)");
// and then append strings to the debug window with dbgmsg():
// dbgmsg("this is the " + "message");
var debugWin;
if (typeof debugWin == "undefined") {
debugWin = window.open("", "DEBUG",
"menubar=0,scrollbars=1,resizable=1,width=300,"
+ "height=600,left="+(screen.width-301)+",top=1,location=0");
// init the contents of the window
var debugdoc = debugWin.document;
debugdoc.open();
debugdoc.write(''
);
debugdoc.close();
}
function debugMsg(msg) {
if (debugWin.closed)
return;
var debugdoc = debugWin.document;
var row = debugdoc.createElement("tr");
var cell = debugdoc.createElement("td");
var text = debugdoc.createTextNode(msg);
cell.appendChild(text);
row.appendChild(cell);
debugdoc.getElementById('tbody').appendChild(row);
row.scrollIntoView(false);
}
// dump all the properties of an object
// param obj - the object
// param parent - name of obj
// param maxdepth - depth to descend into children.
// recur iff maxdepth > 1
// typically 'parent' is a quoted version of 'obj':
// dumpProps(cbs[cb], "cbs[cb]", 2); // recur at most one level
function debugProps(obj, parent, maxdepth) {
var dad = (parent) ? parent + "." : "";
for (var i in obj) {
if (i == "selectionStart" || i == "selectionEnd"
|| i == "domConfig") {
// once upon a time (firefox 3.6.2) these failed
continue;
}
debugMsg(dad + i + ": " + obj[i]);
if (maxdepth > 1 && typeof obj[i] == "object")
debugProps(obj[i], dad + i, maxdepth - 1);
}
}
var nodeType = ["0", "element", "attribute", "text", "4", "5", "6", "7", "comment"];
function debugTagTree(obj, indent, maxdepth) {
if (obj.nodeType == 3 || obj.nodeType == 8) { // text or comment
debugMsg(indent + ": " + '"' + obj.textContent +'"');
return;
}
debugMsg(indent + ": " + nodeType[obj.nodeType] + " " + obj.tagName);
var kidNodes = obj.childNodes;
if (maxdepth<1) return;
for (var index = 0; index < kidNodes.length; index++)
debugTagTree(kidNodes[index], indent + index, maxdepth - 1);
}