1 | function showFrame(anchor) { |
---|
2 | var tbid = anchor.getAttribute('tbid'); |
---|
3 | var expanded = anchor.expanded; |
---|
4 | if (expanded) { |
---|
5 | hideElement(anchor.expandedElement); |
---|
6 | anchor.expanded = false; |
---|
7 | _swapImage(anchor); |
---|
8 | return false; |
---|
9 | } |
---|
10 | anchor.expanded = true; |
---|
11 | if (anchor.expandedElement) { |
---|
12 | showElement(anchor.expandedElement); |
---|
13 | _swapImage(anchor); |
---|
14 | $('#debug_input_'+tbid).get(0).focus(); |
---|
15 | return false; |
---|
16 | } |
---|
17 | var url = debug_base |
---|
18 | + '/show_frame?tbid=' + tbid |
---|
19 | + '&debugcount=' + debug_count; |
---|
20 | callbackXHR(url, null, function (data) { |
---|
21 | var el = createElement('div'); |
---|
22 | anchor.parentNode.insertBefore(el, anchor.nextSibling); |
---|
23 | el.innerHTML = data.responseText; |
---|
24 | anchor.expandedElement = el; |
---|
25 | _swapImage(anchor); |
---|
26 | $('#debug_input_'+tbid).get(0).focus(); |
---|
27 | }); |
---|
28 | return false; |
---|
29 | } |
---|
30 | |
---|
31 | function _swapImage(anchor) { |
---|
32 | var el = anchor.getElementsByTagName('IMG')[0]; |
---|
33 | if (anchor.expanded) { |
---|
34 | var img = 'minus.jpg'; |
---|
35 | } else { |
---|
36 | var img = 'plus.jpg'; |
---|
37 | } |
---|
38 | el.src = debug_base + '/media/' + img; |
---|
39 | } |
---|
40 | |
---|
41 | function showSource(anchor) { |
---|
42 | var location = anchor.getAttribute('location'); |
---|
43 | showSourceCode(location); |
---|
44 | return false; |
---|
45 | } |
---|
46 | |
---|
47 | function showSourceCode(location) { |
---|
48 | var url = debug_base + '/source_code?location=' + escape(location); |
---|
49 | var source = document.getElementById('source_data'); |
---|
50 | source.innerHTML = 'Loading...'; |
---|
51 | switch_display('source_data'); |
---|
52 | callbackXHR(url, null, function (req) { |
---|
53 | source.innerHTML = req.responseText; |
---|
54 | if (location.indexOf(':') > 0) { |
---|
55 | var lineno = location.substring(location.indexOf(':')+1); |
---|
56 | lineno = parseInt(lineno) - 10; |
---|
57 | if (lineno > 1) { |
---|
58 | document.location.hash = '#'+(lineno-10); |
---|
59 | } |
---|
60 | } |
---|
61 | }); |
---|
62 | } |
---|
63 | |
---|
64 | function submitInput(button, tbid) { |
---|
65 | var input = $('#' + button.getAttribute('input-from')).get(0); |
---|
66 | var output = $('#' + button.getAttribute('output-to')).get(0); |
---|
67 | var url = debug_base |
---|
68 | + '/exec_input'; |
---|
69 | var history = input.form.history; |
---|
70 | input.historyPosition = 0; |
---|
71 | if (! history) { |
---|
72 | history = input.form.history = []; |
---|
73 | } |
---|
74 | history.push(input.value); |
---|
75 | var vars = { |
---|
76 | tbid: tbid, |
---|
77 | debugcount: debug_count, |
---|
78 | input: input.value |
---|
79 | }; |
---|
80 | showElement(output); |
---|
81 | callbackXHR(url, vars, function (data) { |
---|
82 | var result = data.responseText; |
---|
83 | output.innerHTML += result; |
---|
84 | input.value = ''; |
---|
85 | input.focus(); |
---|
86 | }); |
---|
87 | return false; |
---|
88 | } |
---|
89 | |
---|
90 | function showError(msg) { |
---|
91 | var el = $('#error-container').get(0); |
---|
92 | if (el.innerHTML) { |
---|
93 | el.innerHTML += '<hr noshade>\n' + msg; |
---|
94 | } else { |
---|
95 | el.innerHTML = msg; |
---|
96 | } |
---|
97 | showElement($('#error-area').get(0)); |
---|
98 | } |
---|
99 | |
---|
100 | function clearError() { |
---|
101 | var el = $('#error-container').get(0); |
---|
102 | el.innerHTML = ''; |
---|
103 | $('#error-area').hide(); |
---|
104 | } |
---|
105 | |
---|
106 | function expandInput(button) { |
---|
107 | var input = button.form.elements.input; |
---|
108 | stdops = { |
---|
109 | name: 'input', |
---|
110 | style: 'width: 100%', |
---|
111 | autocomplete: 'off' |
---|
112 | }; |
---|
113 | if (input.tagName == 'INPUT') { |
---|
114 | var newEl = createElement('textarea', stdops); |
---|
115 | var text = 'Contract'; |
---|
116 | } else { |
---|
117 | stdops['type'] = 'text'; |
---|
118 | stdops['onkeypress'] = 'upArrow(this)'; |
---|
119 | var newEl = createElement('input', stdops); |
---|
120 | var text = 'Expand'; |
---|
121 | } |
---|
122 | newEl.value = input.value; |
---|
123 | newEl.id = input.id; |
---|
124 | swapDOM(input, newEl); |
---|
125 | newEl.focus(); |
---|
126 | button.value = text; |
---|
127 | return false; |
---|
128 | } |
---|
129 | |
---|
130 | function upArrow(input, event) { |
---|
131 | if (window.event) { |
---|
132 | event = window.event; |
---|
133 | } |
---|
134 | if (event.keyCode != 38 && event.keyCode != 40) { |
---|
135 | // not an up- or down-arrow |
---|
136 | return true; |
---|
137 | } |
---|
138 | var dir = event.keyCode == 38 ? 1 : -1; |
---|
139 | var history = input.form.history; |
---|
140 | if (! history) { |
---|
141 | history = input.form.history = []; |
---|
142 | } |
---|
143 | var pos = input.historyPosition || 0; |
---|
144 | if (! pos && dir == -1) { |
---|
145 | return true; |
---|
146 | } |
---|
147 | if (! pos && input.value) { |
---|
148 | history.push(input.value); |
---|
149 | pos = 1; |
---|
150 | } |
---|
151 | pos += dir; |
---|
152 | if (history.length-pos < 0) { |
---|
153 | pos = 1; |
---|
154 | } |
---|
155 | if (history.length-pos > history.length-1) { |
---|
156 | input.value = ''; |
---|
157 | return true; |
---|
158 | } |
---|
159 | input.historyPosition = pos; |
---|
160 | var line = history[history.length-pos]; |
---|
161 | input.value = line; |
---|
162 | } |
---|
163 | |
---|
164 | function expandLong(anchor) { |
---|
165 | var span = anchor; |
---|
166 | while (span) { |
---|
167 | if (span.style && span.style.display == 'none') { |
---|
168 | break; |
---|
169 | } |
---|
170 | span = span.nextSibling; |
---|
171 | } |
---|
172 | if (! span) { |
---|
173 | return false; |
---|
174 | } |
---|
175 | showElement(span); |
---|
176 | hideElement(anchor); |
---|
177 | return false; |
---|
178 | } |
---|
179 | |
---|
180 | function showElement(el) { |
---|
181 | el.style.display = ''; |
---|
182 | } |
---|
183 | |
---|
184 | function hideElement(el) { |
---|
185 | el.style.display = 'none'; |
---|
186 | } |
---|
187 | |
---|
188 | function createElement(tag, attrs /*, sub-elements...*/) { |
---|
189 | var el = document.createElement(tag); |
---|
190 | if (attrs) { |
---|
191 | for (var i in attrs) { |
---|
192 | el.setAttribute(i, attrs[i]); |
---|
193 | } |
---|
194 | } |
---|
195 | for (var i=2; i<arguments.length; i++) { |
---|
196 | var item = arguments[i]; |
---|
197 | if (typeof item == 'string') { |
---|
198 | item = document.createTextNode(item); |
---|
199 | } |
---|
200 | el.appendChild(item); |
---|
201 | } |
---|
202 | return el; |
---|
203 | } |
---|
204 | |
---|
205 | function swapDOM(dest, src) { |
---|
206 | var parent = dest.parentNode; |
---|
207 | parent.replaceChild(src, dest); |
---|
208 | return src; |
---|
209 | } |
---|
210 | |
---|
211 | |
---|
212 | function getXMLHttpRequest() { |
---|
213 | /* Taken from MochiKit */ |
---|
214 | var tryThese = [ |
---|
215 | function () { return new XMLHttpRequest(); }, |
---|
216 | function () { return new ActiveXObject('Msxml2.XMLHTTP'); }, |
---|
217 | function () { return new ActiveXObject('Microsoft.XMLHTTP'); }, |
---|
218 | function () { return new ActiveXObject('Msxml2.XMLHTTP.4.0'); } |
---|
219 | ]; |
---|
220 | for (var i = 0; i < tryThese.length; i++) { |
---|
221 | var func = tryThese[i]; |
---|
222 | try { |
---|
223 | return func(); |
---|
224 | } catch (e) { |
---|
225 | // pass |
---|
226 | } |
---|
227 | } |
---|
228 | } |
---|
229 | |
---|
230 | function callbackXHR(url, data, callback) { |
---|
231 | var xhr = getXMLHttpRequest(); |
---|
232 | xhr.onreadystatechange = function () { |
---|
233 | if (xhr.readyState == 4) { |
---|
234 | if (xhr.status == 200) { |
---|
235 | callback(xhr); |
---|
236 | } else { |
---|
237 | showError(xhr.responseText); |
---|
238 | } |
---|
239 | } |
---|
240 | }; |
---|
241 | var method = data ? "POST" : "GET"; |
---|
242 | xhr.open(method, url); |
---|
243 | if (data) { |
---|
244 | if (! (typeof data == 'string')) { |
---|
245 | var newData = ''; |
---|
246 | for (var i in data) { |
---|
247 | if (newData) { |
---|
248 | newData += '&'; |
---|
249 | } |
---|
250 | newData += i + '=' + escape(data[i]); |
---|
251 | } |
---|
252 | data = newData; |
---|
253 | } |
---|
254 | xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded'); |
---|
255 | xhr.send(data); |
---|
256 | } else { |
---|
257 | xhr.send(null); |
---|
258 | } |
---|
259 | } |
---|
260 | |
---|
261 | function switch_display(id) { |
---|
262 | ids = ['extra_data', 'template_data', 'traceback_data', 'source_data']; |
---|
263 | for (i in ids){ |
---|
264 | part = ids[i]; |
---|
265 | var el = document.getElementById(part); |
---|
266 | el.className = "hidden-data"; |
---|
267 | var el = document.getElementById(part+'_tab'); |
---|
268 | el.className = "not-active"; |
---|
269 | var el = document.getElementById(part+'_link'); |
---|
270 | el.className = "not-active"; |
---|
271 | } |
---|
272 | var el = document.getElementById(id); |
---|
273 | el.className = "active"; |
---|
274 | var el = document.getElementById(id+'_link'); |
---|
275 | el.className = "active"; |
---|
276 | var el = document.getElementById(id+'_tab'); |
---|
277 | el.className = "active"; |
---|
278 | } |
---|
279 | |
---|
280 | function hide_display(id) { |
---|
281 | var el = document.getElementById(id); |
---|
282 | if (el.className == "hidden-data") { |
---|
283 | el.className = ""; |
---|
284 | return true; |
---|
285 | } else { |
---|
286 | el.className = "hidden-data"; |
---|
287 | return false; |
---|
288 | } |
---|
289 | } |
---|
290 | |
---|
291 | function show_button(toggle_id, name) { |
---|
292 | document.write('<a href="#' + toggle_id |
---|
293 | + '" onclick="javascript:hide_display(\'' + toggle_id |
---|
294 | + '\')" class="button">' + name + '</a><br>'); |
---|
295 | } |
---|
296 | |
---|
297 | function switch_source(el, hide_type) { |
---|
298 | while (el) { |
---|
299 | if (el.getAttribute && |
---|
300 | el.getAttribute('source-type') == hide_type) { |
---|
301 | break; |
---|
302 | } |
---|
303 | el = el.parentNode; |
---|
304 | } |
---|
305 | if (! el) { |
---|
306 | return false; |
---|
307 | } |
---|
308 | el.style.display = 'none'; |
---|
309 | if (hide_type == 'long') { |
---|
310 | while (el) { |
---|
311 | if (el.getAttribute && |
---|
312 | el.getAttribute('source-type') == 'short') { |
---|
313 | break; |
---|
314 | } |
---|
315 | el = el.nextSibling; |
---|
316 | } |
---|
317 | } else { |
---|
318 | while (el) { |
---|
319 | if (el.getAttribute && |
---|
320 | el.getAttribute('source-type') == 'long') { |
---|
321 | break; |
---|
322 | } |
---|
323 | el = el.previousSibling; |
---|
324 | } |
---|
325 | } |
---|
326 | if (el) { |
---|
327 | el.style.display = ''; |
---|
328 | } |
---|
329 | return false; |
---|
330 | } |
---|
331 | |
---|
332 | $(document).ready(function() { |
---|
333 | var hide_all = function() { |
---|
334 | $('#short_text_version, #long_text_version, #short_traceback, #full_traceback, #short_xml_version, #long_xml_version, div.feature-highlight').hide(); |
---|
335 | $('#view_long_text, #view_short_text, #view_long_html, #view_short_html, #view_short_xml, #view_long_xml').removeClass('active'); |
---|
336 | }; |
---|
337 | |
---|
338 | if ($('#long_text_version').length == 0) { |
---|
339 | $('#view_long_text').hide(); |
---|
340 | } |
---|
341 | if ($('#full_traceback').length == 0) { |
---|
342 | $('#view_long_html').hide(); |
---|
343 | } |
---|
344 | |
---|
345 | |
---|
346 | $('#view_short_text').click(function() { |
---|
347 | hide_all(); |
---|
348 | $('#short_text_version').show(); |
---|
349 | $(this).addClass('active'); |
---|
350 | return false; |
---|
351 | }); |
---|
352 | $('#view_long_text').click(function() { |
---|
353 | hide_all(); |
---|
354 | $('#long_text_version').show(); |
---|
355 | $(this).addClass('active'); |
---|
356 | return false; |
---|
357 | }); |
---|
358 | $('#view_short_html').click(function() { |
---|
359 | hide_all(); |
---|
360 | $('#short_traceback, div.feature-highlight').show(); |
---|
361 | $(this).addClass('active'); |
---|
362 | return false; |
---|
363 | }); |
---|
364 | $('#view_long_html').click(function () { |
---|
365 | hide_all(); |
---|
366 | $('#full_traceback, div.feature-highlight').show(); |
---|
367 | $(this).addClass('active'); |
---|
368 | return false; |
---|
369 | }); |
---|
370 | $('#view_short_xml').click(function () { |
---|
371 | hide_all(); |
---|
372 | $('#short_xml_version').show(); |
---|
373 | $(this).addClass('active'); |
---|
374 | return false; |
---|
375 | }); |
---|
376 | $('#view_long_xml').click(function () { |
---|
377 | hide_all(); |
---|
378 | $('#long_xml_version').show(); |
---|
379 | $(this).addClass('active'); |
---|
380 | return false; |
---|
381 | }); |
---|
382 | }); |
---|