changeset 484:b9b8e54ed3bb

Fixed a bug when the clicked zoom area was too small
author hertzhaft
date Fri, 11 May 2007 09:33:46 +0200
parents 2b72e97ec9da
children 351c5924b7a6
files client/digitallibrary/greyskin/debug.js
diffstat 1 files changed, 111 insertions(+), 102 deletions(-) [+]
line wrap: on
line diff
--- 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 = '<p class="debug">Debug</p>';
-			};
-		};
-	return Debug;
-	}
-
-function debug() {
-	var msg = "";
-	for (var i = 0; i<arguments.length; i++)
-		msg += arguments[i] + " ";
-	var D = getDebug();
-	if (!D) {
-		alert("Debug div not present!\n" + msg);
-		return null;
-		}
-	return appendNewElement(D, "p", msg);
-	}
-
-function debugProps(obj, msg) {
-	var D = getDebug();
-	if (msg) appendNewElement(D, "h1", msg);
-	for (var item in obj) {
-		var typ = typeof(obj[item]);
-		if (typ != "function") appendNewElement(D, "p",
-			item 
-			+ " (" + typ + "): "
-			+ obj[item]
-			);
-		};
-	}
-
-function debugObject(obj, msg) {
-	if (msg) appendNewElement(D, "h1", msg);
-	var D = getDebug();
-	var A = new Array();
-	for (var i in obj) A[i] = typeof(obj[i]); 
-	var T = appendNewElement(D, "table");
-	for (var item in A) {
-		var TR = appendNewElement(T, "tr");
-		appendNewElement(TR, "td", newElement("b", item));
-		appendNewElement(TR, "td", A[item]); 
-		if (A[item] == "function") 
-			appendNewElement(TR, "td", A[item].toSource());
-		};
-	}
-
-function strObject(obj) {
-	var res = "";
-	var A = new Array();
-	for (var i in obj) A[i] = typeof(obj[i]); 
-	for (var item in A) {
-		typ = A[item];
-		res += item + " (" + typ + "): ";
-		if (typ != "function") res += obj[item];
-		res += "\n";
-		}
-	return res;
-	}
-
-function alertObject(obj) {
-	return alert(strObject(obj));
-	}
-
-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.");
-	}
+var Debug = null;
+var _now = {};
+
+function element(name, content) {
+	var E = document.createElement(name);
+	if (content) {
+		if (content.nodeType) // it's a node
+			E.appendChild(content)
+		else // it's text
+			E.appendChild(document.createTextNode(content))
+		};
+	return E;
+	}
+	
+function appendElement(node, name, content) {
+	if (node == null || ! node.appendChild)
+        return node;
+	return node.appendChild(element(name,content));
+	}
+
+function getDebug() {
+	if (Debug == null) {
+		Debug = document.getElementById('debug');
+		if (Debug == null) {
+			Debug = appendElement(document.body, 'div');
+			Debug.setAttribute('class', 'debug');
+			Debug.setAttribute('id', 'debug');
+			Debug.innerhtml = '<h3>Debug</h3>';
+			};
+		};
+	return Debug;
+	}
+
+function debug() {
+	var D = getDebug();
+	// return alertObject(D);
+	var msg = "";
+	for (var i = 0; i<arguments.length; i++) msg += arguments[i] + " ";
+	return appendElement(D, "p", msg);
+	}
+
+function debugObject(obj, exclude) {
+	if (exclude == null)
+	    exclude = '';
+	var noConst = exclude.indexOf('const') > -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.");
+	}
+