# HG changeset patch # User hertzhaft # Date 1134477072 -3600 # Node ID 84c20b64e1de2b451e9300451a42b54b52c57bda # Parent bd95a59ba0f9def1f10f5ecd5f735e9fbb62845e added my rudimentary debug library diff -r bd95a59ba0f9 -r 84c20b64e1de client/digitallibrary/greyskin/debug.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/digitallibrary/greyskin/debug.js Tue Dec 13 13:31:12 2005 +0100 @@ -0,0 +1,88 @@ +var Debug; +var _now = {}; + +function newElement(tagname, content) { + // creates a new element, adding node or text content if given + var elem = document.createElement(tagname); + if (content) elem.appendChild(content.nodeType + ? content // content is a node + : document.createTextNode(content) // content is a string + ); + return elem; + } + +function appendNewElement(node, tagname, content) { + // appends a new element to "node", adding content if given + if (!node.appendChild) { + alert("Could not append: " + typeof(node)); + return null; + } + return node.appendChild(newElement(tagname, content)); + } + +function getDebug() { + if (Debug == null) { + Debug = document.getElementById('debug'); + if (Debug == null) { + if (!document.body) return null; + // its still too early! + Debug = appendNewElement(document.body, 'div'); + Debug.setAttribute('id', 'debug'); + Debug.className = 'debug'; + Debug.innerhtml = '

Debug

'; + }; + }; + return Debug; + } + +function debug() { + var msg = ""; + for (var i = 0; i