dump.js
Summary
No overview generated for 'dump.js'
dump = function (domElement, bWindow) {
var strDump=dump.getHTML(domElement, false, 0)
if (!bWindow) return strDump
var outputWindow;
outputWindow=window.open("","dumpdom");
outputWindow.focus();
outputWindow.document.open("text/html", "replace");
outputWindow.document.write("<HTML><HEAD><TITLE>DOM</TITLE></HEAD><BODY>\n");
outputWindow.document.write("<textarea rows=20 cols=60>")
outputWindow.document.write(strDump)
outputWindow.document.write("</textarea>")
outputWindow.document.write("</BODY></HTML>\n");
outputWindow.document.close();
}
dump.agt = navigator.userAgent.toLowerCase();
dump.is_ie = ((dump.agt.indexOf("msie") != -1) && (dump.agt.indexOf("opera") == -1));
dump.RE_tagName = /(<\/|<)\s*([^ \t\n>]+)/ig;
dump.getHTML = function(root, outputRoot, intDeep) {
var i2;
var html = "";
for (i2=0; i2 <= intDeep; i2++) html+=" "
switch (root.nodeType) {
case 1:
case 11:
var closed;
var i;
var root_tag = (root.nodeType == 1) ? root.tagName.toLowerCase() : '';
if (dump.is_ie && root_tag == "head") {
if (outputRoot)
html += "\n<head>\n";
var save_multiline = RegExp.multiline;
RegExp.multiline = true;
var txt = root.innerHTML.replace(dump.RE_tagName, function(str, p1, p2) {
return p1 + p2.toLowerCase();
});
RegExp.multiline = save_multiline;
html += '\n' + txt;
if (outputRoot)
html += "\n</head>\n";
break;
} else if (outputRoot) {
closed = (!(root.hasChildNodes() || dump.needsClosingTag(root)));
html += "<" + root.tagName.toLowerCase();
var attrs = root.attributes;
for (i = 0; i < attrs.length; ++i) {
var a = attrs.item(i);
if (!a.specified) {
continue;
}
var name = a.nodeName.toLowerCase();
if (/_moz|contenteditable|_msh/.test(name)) {
continue;
}
var value;
if (name != "style") {
if (typeof root[a.nodeName] != "undefined" && name != "href" && name != "src") {
value = root[a.nodeName];
} else {
value = a.nodeValue;
if (value && (dump.is_ie && (name == "href" || name == "src"))) {
value = this.stripBaseURL(value);
}
}
} else {
value = root.style.cssText;
}
if (/(_moz|^$)/.test(value)) {
continue;
}
html += " " + name + '="' + value + '"';
}
html += closed ? " />\n" : ">\n";
}
for (i = root.firstChild; i; i = i.nextSibling) {
html += this.getHTML(i, true, intDeep+1)
}
if (outputRoot && !closed) {
for (i2=0; i2 <= intDeep; i2++) html+=" "
html += "</" + root.tagName.toLowerCase() + ">\n";
}
break;
case 3:
if ( !root.previousSibling && !root.nextSibling && root.data.match(/^\s*$/i) ) html += ' ';
else
{
html += this.htmlEncode(root.data) + '\n';
}
break;
case 8:
html += "<!--" + root.data + "-->";
break;
}
return html;
};
dump.stripBaseURL = function(string) {
var baseurl = string;
baseurl = baseurl.replace(/[^\/]+$/, '');
var basere = new RegExp(baseurl);
string = string.replace(basere, "");
baseurl = baseurl.replace(/^(https?:\/\/[^\/]+)(.*)$/, '$1');
basere = new RegExp(baseurl);
return string.replace(basere, "");
};
dump.htmlEncode = function(str) {
str = str.replace(/&/ig, "&");
str = str.replace(/</ig, "<");
str = str.replace(/>/ig, ">");
str = str.replace(/\x22/ig, """);
return str;
};
dump.needsClosingTag = function(el) {
var closingTags = " head script style div span tr td tbody table em strong font a title ";
return (closingTags.indexOf(" " + el.tagName.toLowerCase() + " ") != -1);
};
Documentation generated by
JSDoc on Thu Aug 16 12:18:39 2007