Mercurial > hg > digilib-old
comparison client/digitallibrary/greyskin/debug.js @ 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 | 84aee0e6d64e |
children |
comparison
equal
deleted
inserted
replaced
483:2b72e97ec9da | 484:b9b8e54ed3bb |
---|---|
1 var Debug; | 1 var Debug = null; |
2 var _now = {}; | 2 var _now = {}; |
3 | 3 |
4 function newElement(tagname, content) { | 4 function element(name, content) { |
5 // creates a new element, adding node or text content if given | 5 var E = document.createElement(name); |
6 var elem = document.createElement(tagname); | 6 if (content) { |
7 if (content) elem.appendChild(content.nodeType | 7 if (content.nodeType) // it's a node |
8 ? content // content is a node | 8 E.appendChild(content) |
9 : document.createTextNode(content) // content is a string | 9 else // it's text |
10 ); | 10 E.appendChild(document.createTextNode(content)) |
11 return elem; | 11 }; |
12 return E; | |
12 } | 13 } |
13 | 14 |
14 function appendNewElement(node, tagname, content) { | 15 function appendElement(node, name, content) { |
15 // appends a new element to "node", adding content if given | 16 if (node == null || ! node.appendChild) |
16 if (!node.appendChild) { | 17 return node; |
17 alert("Could not append '" + tagname + "' to " + typeof(node)); | 18 return node.appendChild(element(name,content)); |
18 return null; | |
19 } | |
20 return node.appendChild(newElement(tagname, content)); | |
21 } | 19 } |
22 | 20 |
23 function getDebug() { | 21 function getDebug() { |
24 if (Debug == null) { | 22 if (Debug == null) { |
25 Debug = document.getElementById('debug'); | 23 Debug = document.getElementById('debug'); |
26 if (Debug == null) { | 24 if (Debug == null) { |
27 if (!document.body) return null; | 25 Debug = appendElement(document.body, 'div'); |
28 // its still too early! | 26 Debug.setAttribute('class', 'debug'); |
29 Debug = appendNewElement(document.body, 'div'); | |
30 Debug.setAttribute('id', 'debug'); | 27 Debug.setAttribute('id', 'debug'); |
31 Debug.className = 'debug'; | 28 Debug.innerhtml = '<h3>Debug</h3>'; |
32 Debug.innerhtml = '<p class="debug">Debug</p>'; | |
33 }; | 29 }; |
34 }; | 30 }; |
35 return Debug; | 31 return Debug; |
36 } | 32 } |
37 | 33 |
38 function debug() { | 34 function debug() { |
35 var D = getDebug(); | |
36 // return alertObject(D); | |
39 var msg = ""; | 37 var msg = ""; |
40 for (var i = 0; i<arguments.length; i++) | 38 for (var i = 0; i<arguments.length; i++) msg += arguments[i] + " "; |
41 msg += arguments[i] + " "; | 39 return appendElement(D, "p", msg); |
42 var D = getDebug(); | |
43 if (!D) { | |
44 alert("Debug div not present!\n" + msg); | |
45 return null; | |
46 } | |
47 return appendNewElement(D, "p", msg); | |
48 } | 40 } |
49 | 41 |
50 function debugProps(obj, msg) { | 42 function debugObject(obj, exclude) { |
43 if (exclude == null) | |
44 exclude = ''; | |
45 var noConst = exclude.indexOf('const') > -1; | |
46 var A = new Array(); | |
47 for (var prop in obj) A.push(prop); | |
48 A.sort(); | |
51 var D = getDebug(); | 49 var D = getDebug(); |
52 if (msg) appendNewElement(D, "h1", msg); | 50 var T = appendElement(D, "table"); |
53 for (var item in obj) { | 51 for (var i = 0; i < A.length; i++) { |
54 var typ = typeof(obj[item]); | 52 var key = A[i]; |
55 if (typ != "function") appendNewElement(D, "p", | 53 var value = obj[key]; |
56 item | 54 var type = typeof(value); |
57 + " (" + typ + "): " | 55 // exclude specified types |
58 + obj[item] | 56 if (exclude.indexOf(type) > -1) |
59 ); | 57 continue; |
60 }; | 58 // exclude uppercase-only properties (= constants) |
61 } | 59 if (noConst && key.search(/^[A-Z0-9_]+$/) > -1) |
62 | 60 continue; |
63 function debugObject(obj, msg) { | 61 var TR = appendElement(T, "tr"); |
64 if (msg) appendNewElement(D, "h1", msg); | 62 appendElement(TR, "td", element("b", key)); |
65 var D = getDebug(); | 63 appendElement(TR, "td", type); |
66 var A = new Array(); | 64 appendElement(TR, "td", value + ""); |
67 for (var i in obj) A[i] = typeof(obj[i]); | 65 if (type == "function") |
68 var T = appendNewElement(D, "table"); | 66 appendElement(TR, "td", value.toSource()); |
69 for (var item in A) { | |
70 var TR = appendNewElement(T, "tr"); | |
71 appendNewElement(TR, "td", newElement("b", item)); | |
72 appendNewElement(TR, "td", A[item]); | |
73 if (A[item] == "function") | |
74 appendNewElement(TR, "td", A[item].toSource()); | |
75 }; | 67 }; |
76 } | 68 } |
77 | 69 |
78 function strObject(obj) { | 70 function strObject(obj) { |
79 var res = ""; | 71 var res = ""; |
80 var A = new Array(); | 72 var A = new Array(); |
81 for (var i in obj) A[i] = typeof(obj[i]); | 73 try { |
74 for (var i in obj) A[i] = typeof(obj[i]); | |
75 } | |
76 catch(e) { typ = "unknown" }; | |
77 var count = 0; | |
82 for (var item in A) { | 78 for (var item in A) { |
83 typ = A[item]; | 79 count++; |
80 typ = A[item]; | |
84 res += item + " (" + typ + "): "; | 81 res += item + " (" + typ + "): "; |
85 if (typ != "function") res += obj[item]; | 82 if (typ != "function") res += obj[item]; |
86 res += "\n"; | 83 res += "\t"; |
84 if (count % 4 == 0) | |
85 res += "\n"; | |
87 } | 86 } |
88 return res; | 87 return res; |
89 } | 88 } |
90 | 89 |
91 function alertObject(obj) { | 90 function alertObject(obj) { |
92 return alert(strObject(obj)); | 91 return alert(strObject(obj)); |
93 } | 92 } |
94 | 93 |
94 function alertHTML(obj) { | |
95 if (obj) | |
96 return alert(obj.tagName + ".innerHTML:\n" + obj.innerHTML); | |
97 } | |
98 | |
99 function serialize(xmlobject) { | |
100 return (new XMLSerializer()).serializeToString(xmlobject); | |
101 } | |
102 | |
95 function startTime(s) { | 103 function startTime(s) { |
96 _now[s] = new Date(); | 104 _now[s] = new Date(); |
97 } | 105 } |
98 | 106 |
99 function elapsedTime(s) { | 107 function elapsedTime(s) { |
100 var diff = new Date(new Date - _now[s]); | 108 var diff = new Date(new Date - _now[s]); |
101 debug(s + ": " + diff.getSeconds() + "." + diff.getMilliseconds() + " sec."); | 109 debug(s + ": " + diff.getSeconds() + "." + diff.getMilliseconds() + " sec."); |
102 } | 110 } |
111 |