annotate client/digitallibrary/greyskin/debug.js @ 517:72604a10ee1a Root_jquery

fixes for zoom when birds-eye view open fixes for IE (works mostly in IE7 and IE8)
author robcast
date Fri, 04 Sep 2009 12:27:02 +0200
parents b9b8e54ed3bb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
484
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
1 var Debug = null;
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
2 var _now = {};
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
3
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
4 function element(name, content) {
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
5 var E = document.createElement(name);
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
6 if (content) {
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
7 if (content.nodeType) // it's a node
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
8 E.appendChild(content)
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
9 else // it's text
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
10 E.appendChild(document.createTextNode(content))
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
11 };
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
12 return E;
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
13 }
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
14
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
15 function appendElement(node, name, content) {
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
16 if (node == null || ! node.appendChild)
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
17 return node;
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
18 return node.appendChild(element(name,content));
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
19 }
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
20
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
21 function getDebug() {
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
22 if (Debug == null) {
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
23 Debug = document.getElementById('debug');
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
24 if (Debug == null) {
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
25 Debug = appendElement(document.body, 'div');
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
26 Debug.setAttribute('class', 'debug');
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
27 Debug.setAttribute('id', 'debug');
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
28 Debug.innerhtml = '<h3>Debug</h3>';
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
29 };
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
30 };
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
31 return Debug;
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
32 }
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
33
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
34 function debug() {
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
35 var D = getDebug();
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
36 // return alertObject(D);
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
37 var msg = "";
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
38 for (var i = 0; i<arguments.length; i++) msg += arguments[i] + " ";
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
39 return appendElement(D, "p", msg);
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
40 }
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
41
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
42 function debugObject(obj, exclude) {
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
43 if (exclude == null)
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
44 exclude = '';
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
45 var noConst = exclude.indexOf('const') > -1;
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
46 var A = new Array();
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
47 for (var prop in obj) A.push(prop);
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
48 A.sort();
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
49 var D = getDebug();
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
50 var T = appendElement(D, "table");
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
51 for (var i = 0; i < A.length; i++) {
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
52 var key = A[i];
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
53 var value = obj[key];
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
54 var type = typeof(value);
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
55 // exclude specified types
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
56 if (exclude.indexOf(type) > -1)
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
57 continue;
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
58 // exclude uppercase-only properties (= constants)
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
59 if (noConst && key.search(/^[A-Z0-9_]+$/) > -1)
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
60 continue;
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
61 var TR = appendElement(T, "tr");
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
62 appendElement(TR, "td", element("b", key));
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
63 appendElement(TR, "td", type);
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
64 appendElement(TR, "td", value + "");
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
65 if (type == "function")
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
66 appendElement(TR, "td", value.toSource());
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
67 };
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
68 }
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
69
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
70 function strObject(obj) {
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
71 var res = "";
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
72 var A = new Array();
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
73 try {
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
74 for (var i in obj) A[i] = typeof(obj[i]);
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
75 }
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
76 catch(e) { typ = "unknown" };
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
77 var count = 0;
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
78 for (var item in A) {
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
79 count++;
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
80 typ = A[item];
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
81 res += item + " (" + typ + "): ";
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
82 if (typ != "function") res += obj[item];
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
83 res += "\t";
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
84 if (count % 4 == 0)
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
85 res += "\n";
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
86 }
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
87 return res;
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
88 }
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
89
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
90 function alertObject(obj) {
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
91 return alert(strObject(obj));
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
92 }
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
93
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
94 function alertHTML(obj) {
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
95 if (obj)
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
96 return alert(obj.tagName + ".innerHTML:\n" + obj.innerHTML);
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
97 }
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
98
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
99 function serialize(xmlobject) {
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
100 return (new XMLSerializer()).serializeToString(xmlobject);
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
101 }
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
102
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
103 function startTime(s) {
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
104 _now[s] = new Date();
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
105 }
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
106
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
107 function elapsedTime(s) {
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
108 var diff = new Date(new Date - _now[s]);
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
109 debug(s + ": " + diff.getSeconds() + "." + diff.getMilliseconds() + " sec.");
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
110 }
b9b8e54ed3bb Fixed a bug when the clicked zoom area was too small
hertzhaft
parents: 427
diff changeset
111