# HG changeset patch # User hertzhaft # Date 1178868826 -7200 # Node ID b9b8e54ed3bbe24d0000658e4d03e6109c58de8e # Parent 2b72e97ec9dad520291a3e019085cee36cc275ae Fixed a bug when the clicked zoom area was too small diff -r 2b72e97ec9da -r b9b8e54ed3bb client/digitallibrary/greyskin/debug.js --- a/client/digitallibrary/greyskin/debug.js Fri May 04 18:59:55 2007 +0200 +++ b/client/digitallibrary/greyskin/debug.js Fri May 11 09:33:46 2007 +0200 @@ -1,102 +1,111 @@ -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 '" + tagname + "' to " + 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 -1; + var A = new Array(); + for (var prop in obj) A.push(prop); + A.sort(); + var D = getDebug(); + var T = appendElement(D, "table"); + for (var i = 0; i < A.length; i++) { + var key = A[i]; + var value = obj[key]; + var type = typeof(value); + // exclude specified types + if (exclude.indexOf(type) > -1) + continue; + // exclude uppercase-only properties (= constants) + if (noConst && key.search(/^[A-Z0-9_]+$/) > -1) + continue; + var TR = appendElement(T, "tr"); + appendElement(TR, "td", element("b", key)); + appendElement(TR, "td", type); + appendElement(TR, "td", value + ""); + if (type == "function") + appendElement(TR, "td", value.toSource()); + }; + } + +function strObject(obj) { + var res = ""; + var A = new Array(); + try { + for (var i in obj) A[i] = typeof(obj[i]); + } + catch(e) { typ = "unknown" }; + var count = 0; + for (var item in A) { + count++; + typ = A[item]; + res += item + " (" + typ + "): "; + if (typ != "function") res += obj[item]; + res += "\t"; + if (count % 4 == 0) + res += "\n"; + } + return res; + } + +function alertObject(obj) { + return alert(strObject(obj)); + } + +function alertHTML(obj) { + if (obj) + return alert(obj.tagName + ".innerHTML:\n" + obj.innerHTML); + } + +function serialize(xmlobject) { + return (new XMLSerializer()).serializeToString(xmlobject); + } + +function startTime(s) { + _now[s] = new Date(); + } + +function elapsedTime(s) { + var diff = new Date(new Date - _now[s]); + debug(s + ": " + diff.getSeconds() + "." + diff.getMilliseconds() + " sec."); + } +