Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 KB | None | 0 0
  1. /**
  2. * Debug function v0.2
  3. *
  4. * Guiilherme Vieira <eunao@live.com>
  5. * Feb 2, 2006
  6. * Jul 26, 2006
  7. */
  8. window.debug = function(mixedVar) {
  9. if (!document || !document.createElement) {
  10. return false;
  11. }
  12. var d = document;
  13. if (!d.body) {
  14. d.body = d.createElement("body");
  15. }
  16. d._debug = d.body.appendChild(d.createElement("div"));
  17. d._debug.style.whiteSpace = "pre";
  18. window.debugCore(mixedVar, d._debug, false, false);
  19. }
  20. window.debugCore = function(v, parent, hideName, hideProperties) {
  21. hideName = hideName || false;
  22. hideProperties = hideProperties || false;
  23. var d = document;
  24. d.newElement = d.createElement;
  25. d.newText = d.createTextNode;
  26. var type = parent.appendChild(d.newText(""));
  27. var value = parent.appendChild(d.newElement("span"));
  28. switch (typeof v) {
  29. case "string":
  30. type.insertData(0, "string(" + v.length + ") ");
  31. value.appendChild(d.newText("\"" + v + "\""));
  32. value.style.color = "#c00";
  33. break;
  34. case "boolean":
  35. parent.appendChild(d.newText(")"));
  36. type.insertData(0, "boolean(");
  37. value.appendChild(d.newText(v ? "true" : "false"));
  38. value.style.color = "#080";
  39. break;
  40. case "number":
  41. parent.appendChild(d.newText(")"));
  42. var isFloat = (String(v).indexOf('.') != -1);
  43. type.insertData(0, ((isFloat ? "float" : "integer") + "("));
  44. value.appendChild(d.newText(v));
  45. value.style.color = "#f00";
  46. break;
  47. case "function":
  48. value.appendChild(d.newText(String(v).replace(/\s+/g, " ")));
  49. value.style.color = "#00c";
  50. break;
  51. case "object":
  52. if (!hideName) {
  53. var name = String(v);
  54. if (v) {
  55. switch (v.constructor) {
  56. case Array: name = "[Array]"; break;
  57. case Error: name = "[object Error]"; break;
  58. default:
  59. if ((typeof Location != "undefined") && (v.constructor == Location)) {
  60. name = "[object Location]";
  61. }
  62. }
  63. }
  64. value.appendChild(d.newText(name));
  65. value.style.color = "#080";
  66. }
  67. if (hideProperties) {
  68. break;
  69. }
  70. if ((v == document.all) || (v == document.childen)) {
  71. var em = value.appendChild(d.newElement("em"));
  72. em.appendChild(d.newText("(not displayed for security reasons)"));
  73. break;
  74. }
  75. var ul = parent.appendChild(d.newElement("ul")), li, span;
  76. ul.style.margin = "2px 0 5px 30px";
  77. ul.style.padding = "0";
  78. ul.style.listStyle = "none";
  79. for (var i in v) {
  80. li = ul.appendChild(d.newElement("li"));
  81. li.style.margin = "0";
  82. li.style.padding = "2px 0";
  83. span = li.appendChild(d.newElement("span"));
  84. span.style.fontWeight = "bold";
  85. span.appendChild(d.newText(i + ": "));
  86. if (v[i] && (typeof v[i] == "object")) {
  87. span.style.cursor = "pointer";
  88. span._objIcon = span.insertBefore(d.newElement("span"), span.firstChild);
  89. li.style.position = "relative";
  90. span._objIcon.style.position = "absolute";
  91. span._objIcon.style.left = "-15px";
  92. span._objIcon.innerHTML = "▶ ";
  93. span._toDebug = v[i];
  94. span._debugged = null;
  95. span.onclick = function(e) {
  96. if (this._debugged) {
  97. var icon = this._objIcon, style = this._debugged.style;
  98. if (style.display == "none") {
  99. style.display = "";
  100. icon.innerHTML = "▼ ";
  101. } else {
  102. style.display = "none";
  103. icon.innerHTML = "▶ ";
  104. }
  105. return false;
  106. }
  107. this._objIcon.innerHTML = "▼ ";
  108. this._debugged = this.parentNode.appendChild(document.createElement("div"));
  109. window.debugCore(this._toDebug, this._debugged, true, false);
  110. };
  111. span.onmouseover = function(e) {this.style.color = "#f00"; this._objIcon.style.color = "#f00";};
  112. span.onmouseout = function(e) {this.style.color = "#000"; this._objIcon.style.color = "#000";};
  113. }
  114. window.debugCore(v[i], li, false, true);
  115. }
  116. break;
  117. default:
  118. value.appendChild(d.newText(String(v)));
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement