1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
<!DOCTYPE HTML>
<html>
<head>
<title>Live DOM Viewer</title>
<script type="text/javascript" language="javascript" src="nu.validator.htmlparser.HtmlParser.nocache.js"></script>
<style>
h1 { margin: 0; }
h2 { font-size: small; margin: 1em 0 0; }
p, ul, pre { margin: 0; }
p { border: inset thin; }
textarea { width: 100%; -width: 99%; height: 8em; border: 0; }
iframe { width: 100%; height: 12em; border: 0; }
/* iframe.large { height: 24em; } */
pre { border: inset thin; padding: 0.5em; color: gray; }
pre samp { color: black; }
#dom { border: inset thin; padding: 0.5em 0.5em 0.5em 1em; color: black; min-height: 5em; font-family: monospace; background: white; }
#dom ul { padding: 0 0 0 1em; margin: 0; }
#dom li { padding: 0; margin: 0; list-style: none; position: relative; }
#dom li li { list-style: disc; }
#dom .t1 code { color: purple; font-weight: bold; }
#dom .t2 { font-style: normal; font-family: monospace; }
#dom .t2 .name { color: black; font-weight: bold; }
#dom .t2 .value { color: blue; font-weight: normal; }
#dom .t3 code, #dom .t4 code, #dom .t5 code { color: gray; }
#dom .t7 code, #dom .t8 code { color: green; }
#dom span { font-style: italic; font-family: serif; }
#dom .t10 code { color: teal; }
#dom .misparented, #dom .misparented code { color: red; font-weight: bold; }
#dom.hidden, .hidden { visibility: hidden; margin: 0.5em 0; padding: 0; height: 0; min-height: 0; }
pre#log { color: black; font: small monospace; }
script + p { border: none; font-size: smaller; margin: 0.8em 0.3em; }
</style>
<style title="Tree View">
#dom li li { list-style: none; }
#dom li:first-child::before { position: absolute; top: 0; height: 0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
#dom li:not(:last-child)::after { position: absolute; top: 0; bottom: -0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
</style>
<script>
if (navigator.userAgent.match('Gecko/(\\d+)') && RegExp.$1 == '20060217' && RegExp.$1 != '00000000') {
var style = document.getElementsByTagName('style')[1];
style.parentNode.removeChild(style);
}
</script>
</head>
<body onload="init()">
<h1>Live DOM Viewer</h1>
<h2>Markup to test (<a href="data:," id="permalink" rel="bookmark">permalink</a>, <a href="javascript:up()">upload</a>, <a href="javascript:down()">download</a>, <a href="#" onclick="toggleVisibility(this); return false">hide</a>): <span id="updown-status"></span></h2>
<p><textarea oninput="updateInput(event)" onkeydown="updateInput(event)"><!DOCTYPE html>
...</textarea></p>
<h2><a href="data:," id="domview">DOM view</a> (<a href="#" onclick="toggleVisibility(this); return false;">hide</a>, <a href="#" onclick="updateDOM()">refresh</a>):</h2>
<ul id="dom"></ul>
<h2><a href="data:," id="link">Rendered view</a>: (<a href="#" onclick="toggleVisibility(this); return false;">hide</a><!--, <a href="#" onclick="grow(this)">grow</a>-->):</h2>
<p><iframe src="blank.html"></iframe></p> <!-- data:, -->
<h2>innerHTML view: (<a href="#" onclick="toggleVisibility(this); return false;">show</a>, <a href="#" onclick="updateDOM()">refresh</a>):</h2>
<pre class="hidden"><!DOCTYPE HTML><html><samp></samp></html></pre>
<h2>Log: (<a href="#" onclick="toggleVisibility(this); return false;">hide</a>):</h2>
<pre id="log">Script not loaded.</pre>
<script>
var iframe = document.getElementsByTagName('iframe')[0];
var textarea = document.getElementsByTagName('textarea')[0];
var pre = document.getElementsByTagName('samp')[0];
var dom = document.getElementsByTagName('ul')[0];
var log = document.getElementById('log');
var updownStatus = document.getElementById('updown-status');
var delayedUpdater = 0;
var lastString = '';
var logBuffer = '';
var logBuffering = false;
function updateInput(event) {
if (delayedUpdater) {
clearTimeout(delayedUpdater);
delayedUpdater = 0;
}
delayedUpdater = setTimeout(update, 100);
}
function afterParse() {
lastString = textarea.value;
setTimeout(updateDOM, 100);
updown('');
}
function update() {
if (lastString != textarea.value) {
logBuffering = true;
document.getElementById('link').href = 'data:text/html;charset=utf-8,' + encodeURIComponent(textarea.value);
iframe.contentWindow.onerror = function (a, b, c) {
record('error: ' + a + ' on line ' + c);
}
iframe.contentWindow.w = function (s) {
record('log: ' + s);
}
window.parseHtmlDocument(textarea.value, iframe.contentWindow.document, afterParse, null);
}
}
function updateDOM() {
while (pre.firstChild) pre.removeChild(pre.firstChild);
pre.appendChild(document.createTextNode(iframe.contentWindow.document.documentElement.innerHTML));
printDOM(dom, iframe.contentWindow.document);
document.getElementById('domview').href = 'data:text/plain;charset=utf-8,<ul class="domTree">' + encodeURIComponent(dom.innerHTML + '</ul>');
document.getElementById('permalink').href = '?' + encodeURIComponent(textarea.value);
record('rendering mode: ' + iframe.contentWindow.document.compatMode);
if (iframe.contentWindow.document.title)
record('document.title: ' + iframe.contentWindow.document.title);
else
record('document has no title');
while (log.firstChild != log.lastChild)
log.removeChild(log.lastChild);
log.firstChild.data = logBuffer;
logBuffering = false;
logBuffer = '';
}
function printDOM(ul, node) {
while (ul.firstChild) ul.removeChild(ul.firstChild);
for (var i = 0; i < node.childNodes.length; i += 1) {
var li = document.createElement('li');
li.className = 't' + node.childNodes[i].nodeType;
if (node.childNodes[i].nodeType == 10) {
li.appendChild(document.createTextNode('DOCTYPE: '));
}
var code = document.createElement('code');
code.appendChild(document.createTextNode(node.childNodes[i].nodeName));
li.appendChild(code);
if (node.childNodes[i].nodeValue) {
var span = document.createElement('span');
span.appendChild(document.createTextNode(node.childNodes[i].nodeValue));
li.appendChild(document.createTextNode(': '));
li.appendChild(span);
}
if (node.childNodes[i].attributes)
for (var j = 0; j < node.childNodes[i].attributes.length; j += 1) {
if (node.childNodes[i].attributes[j].specified) {
var attName = document.createElement('code');
attName.appendChild(document.createTextNode(node.childNodes[i].attributes[j].nodeName));
attName.className = 'attribute name';
var attValue = document.createElement('code');
attValue.appendChild(document.createTextNode(node.childNodes[i].attributes[j].nodeValue));
attValue.className = 'attribute value';
var att = document.createElement('span');
att.className = 't2';
att.appendChild(attName);
att.appendChild(document.createTextNode('="'));
att.appendChild(attValue);
att.appendChild(document.createTextNode('"'));
li.appendChild(document.createTextNode(' '));
li.appendChild(att);
}
}
if (node.childNodes[i].parentNode == node) {
if (node.childNodes[i].childNodes.length) {
var ul2 = document.createElement('ul');
li.appendChild(ul2);
printDOM(ul2, node.childNodes[i]);
}
} else {
li.className += ' misparented';
}
ul.appendChild(li);
}
}
function toggleVisibility(link) {
var n = link.parentNode.nextSibling;
if (n.nodeType == 3 /* text node */) n = n.nextSibling; // we should always do this but in IE, text nodes vanish
n.className = (n.className == "hidden") ? '' : 'hidden';
link.firstChild.data = n.className == "hidden" ? "show" : "hide";
}
/*
function grow(link) {
var n = link.parentNode.nextSibling;
if (n.nodeType == 3 /-* text node *-/) n = n.nextSibling; // we should always do this but in IE, text nodes vanish
n.className = (n.className == "large") ? '' : 'large';
link.firstChild.data = n.className == "grow" ? "shrink" : "grow";
}
*/
function down() {
updown('downloading...');
var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
request.onreadystatechange = function () {
updown('downloading... ' + request.readyState + '/4');
if (request.readyState == 4) {
textarea.value = request.responseText;
update();
updown('downloaded');
}
};
request.open('GET', 'clipboard.cgi', true);
request.send(null);
}
function up() {
updown('uploading...');
var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
request.onreadystatechange = function () {
updown('uploading... ' + request.readyState + '/4');
if (request.readyState == 4) {
updown('uploaded');
}
};
request.open('POST', 'clipboard.cgi', true);
request.setRequestHeader('Content-Type', 'text/plain');
request.send(textarea.value);
}
function init() {
var uri = location.search;
if (uri)
textarea.value = decodeURIComponent(uri.substring(1, uri.length));
update();
}
function record(s) {
if (logBuffering)
logBuffer += s + '\r\n';
else
log.appendChild(document.createTextNode(s + '\r\n'));
}
function updown(s) {
while (updownStatus.firstChild) updownStatus.removeChild(updownStatus.firstChild);
updownStatus.appendChild(document.createTextNode(s));
}
</script>
<p>This script puts a function <code>w(<var>s</var>)</code> into the
global scope of the test page, where <var>s</vaR> is a string to
output to the log. Also, five files are accessible in the current
directory for test purposes: <code>image</code> (a GIF image),
<code>flash</code> (a Flash file), <code>script</code> (a JS file),
<code>style</code> (a CSS file), and <code>document</code> (an HTML
file).</p>
</body>
</html>
|