-
Notifications
You must be signed in to change notification settings - Fork 4
/
debug.js
42 lines (35 loc) · 1.42 KB
/
debug.js
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
// Script written by Drew Noakes -- http://drewnoakes.com
// the div element used for debug output. created in enableDebug.
var debugDiv;
// call this function from a script within the document for which to enable debug output
function enableDebug() {
document.write("<div id='debugContent' style='display:block; position:absolute; top:7px; right:7px; padding:10px; width:200px; background:#ccc; color:black; border:solid 1px black;'></div>");
debugDiv = document.getElementById("debugContent");
writeClearLink();
}
// writes the string passed to it to the page
function writeDebug(message) {
if (debugDiv)
debugDiv.innerHTML += message + "<br\/>";
}
// writes the value of some code expression.
// eg: writeEval("document.location"); // writes "document.location = http://drewnoakes.com"
/*function writeEval(code) {
writeDebug(code + " = " + eval(code));
}
// writes all of the properties of the object passed to it
function writeDebugObject(object) {
for (property in object)
writeDebug(property);
}*/
// clears the debug output. called either manually or by the user clicking the 'clear' link in the debug div.
function clearDebug() {
if (debugDiv) {
debugDiv.innerHTML = "";
writeClearLink();
}
}
// writes a link in the debug div that clears debug output
function writeClearLink() {
writeDebug("<a href='#' onclick='clearDebug(); return false;'>clear</a>");
}