1 | var debugWindow = null; |
---|
2 | function debug(text, reverse) { |
---|
3 | if (debugWindow == null) |
---|
4 | return; |
---|
5 | |
---|
6 | time = "-"; //new Date(); |
---|
7 | if (reverse) { |
---|
8 | $('debug').innerHTML = time + " " + text + "<br>"+ $('debug').innerHTML; |
---|
9 | debugWindow.getContent().scrollTop=0; |
---|
10 | } |
---|
11 | else { |
---|
12 | $('debug').innerHTML += time + " " + text + "<br>"; |
---|
13 | debugWindow.getContent().scrollTop=10000; // Far away |
---|
14 | } |
---|
15 | } |
---|
16 | |
---|
17 | function hideDebug() { |
---|
18 | if (debugWindow) { |
---|
19 | debugWindow.destroy(); |
---|
20 | debugWindow = null; |
---|
21 | } |
---|
22 | } |
---|
23 | |
---|
24 | function showDebug(bShow) { |
---|
25 | if (debugWindow == null) { |
---|
26 | debugWindow = new Window('debug_window', {className: 'dialog',width:250, height:100, right:4, bottom:42, zIndex:1000, opacity:1, showEffect: Element.show, resizable: true, title: "Debug"}) |
---|
27 | debugWindow.getContent().innerHTML = "<style>#debug_window .dialog_content {background:#000;}</style> <div id='debug'></div>"; |
---|
28 | date=new Date; |
---|
29 | date.setMonth(date.getMonth()+3); |
---|
30 | |
---|
31 | //debugWindow.setCookie(null, date); |
---|
32 | } |
---|
33 | if( typeof bShow == 'undefined' || bShow)debugWindow.show() |
---|
34 | } |
---|
35 | |
---|
36 | |
---|
37 | function clearDebug() { |
---|
38 | if (debugWindow == null) |
---|
39 | return; |
---|
40 | $('debug').innerHTML = ""; |
---|
41 | } |
---|
42 | |
---|
43 | /** |
---|
44 | * document.createElement convenience wrapper |
---|
45 | * |
---|
46 | * The data parameter is an object that must have the "tag" key, containing |
---|
47 | * a string with the tagname of the element to create. It can optionally have |
---|
48 | * a "children" key which can be: a string, "data" object, or an array of "data" |
---|
49 | * objects to append to this element as children. Any other key is taken as an |
---|
50 | * attribute to be applied to this tag. |
---|
51 | * |
---|
52 | * Available under an MIT license: |
---|
53 | * http://www.opensource.org/licenses/mit-license.php |
---|
54 | * |
---|
55 | * @param {Object} data The data representing the element to create |
---|
56 | * @return {Element} The element created. |
---|
57 | */ |
---|
58 | function $E(data) { |
---|
59 | var el; |
---|
60 | if ('string'==typeof data) { |
---|
61 | el=document.createTextNode(data); |
---|
62 | } else { |
---|
63 | //create the element |
---|
64 | el=document.createElement(data.tag); |
---|
65 | delete(data.tag); |
---|
66 | |
---|
67 | //append the children |
---|
68 | if ('undefined'!=typeof data.children) { |
---|
69 | if ('string'==typeof data.children ||'undefined'==typeof data.children.length) { |
---|
70 | //strings and single elements |
---|
71 | el.appendChild($E(data.children)); |
---|
72 | } else { |
---|
73 | //arrays of elements |
---|
74 | for (var i=0, child=null; 'undefined'!=typeof (child=data.children[i]); i++) { |
---|
75 | el.appendChild($E(child)); |
---|
76 | } |
---|
77 | } |
---|
78 | delete(data.children); |
---|
79 | } |
---|
80 | |
---|
81 | //any other data is attributes |
---|
82 | for (attr in data) { |
---|
83 | el[attr]=data[attr]; |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | return el; |
---|
88 | } |
---|
89 | |
---|
90 | // FROM Nick Hemsley |
---|
91 | var Debug = { |
---|
92 | inspectOutput: function (container, within) { |
---|
93 | within = within || debugWindow.getContent() |
---|
94 | |
---|
95 | if (debugWindow == null) |
---|
96 | return; |
---|
97 | |
---|
98 | within.appendChild(container) |
---|
99 | }, |
---|
100 | |
---|
101 | inspect: function(object) { |
---|
102 | var cont = $E({tag: "div", className: "inspector"}) |
---|
103 | Debug.inspectObj(object, cont) |
---|
104 | debugWindow.getContent().appendChild(cont) |
---|
105 | }, |
---|
106 | |
---|
107 | inspectObj: function (object, container) { |
---|
108 | for (prop in object) { |
---|
109 | Debug.inspectOutput(Debug.inspectable(object, prop), container) |
---|
110 | } |
---|
111 | }, |
---|
112 | |
---|
113 | inspectable: function(object, prop) { |
---|
114 | cont = $E({tag: 'div', className: 'inspectable', children: [prop + " value: " + object[prop] ]}) |
---|
115 | cont.toInspect = object[prop] |
---|
116 | Event.observe(cont, 'click', Debug.inspectClicked, false) |
---|
117 | return cont |
---|
118 | }, |
---|
119 | |
---|
120 | inspectClicked: function(e) { |
---|
121 | Debug.inspectContained(Event.element(e)) |
---|
122 | Event.stop(e) |
---|
123 | }, |
---|
124 | |
---|
125 | inspectContained: function(container) { |
---|
126 | if (container.opened) { |
---|
127 | container.parentNode.removeChild(container.opened) |
---|
128 | delete(container.opened) |
---|
129 | } else { |
---|
130 | sibling = container.parentNode.insertBefore($E({tag: "div", className: "child"}), container.nextSibling) |
---|
131 | if (container.toInspect) |
---|
132 | Debug.inspectObj(container.toInspect, sibling) |
---|
133 | container.opened = sibling |
---|
134 | } |
---|
135 | } |
---|
136 | } |
---|
137 | var inspect = Debug.inspect; |
---|