PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/eggs/WebError-0.10.2-py2.6.egg/weberror/eval-media/debug.js

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