annotate client/src/main/webapp/greyskin/debug.js @ 889:b72d958ef7c8 mvnify

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