Console.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
  2. * full list of contributors). Published under the Clear BSD license.
  3. * See http://svn.openlayers.org/trunk/openlayers/license.txt for the
  4. * full text of the license. */
  5. /**
  6. * @requires OpenLayers/BaseTypes/Class.js
  7. */
  8. /**
  9. * Namespace: OpenLayers.Console
  10. * The OpenLayers.Console namespace is used for debugging and error logging.
  11. * If the Firebug Lite (../Firebug/firebug.js) is included before this script,
  12. * calls to OpenLayers.Console methods will get redirected to window.console.
  13. * This makes use of the Firebug extension where available and allows for
  14. * cross-browser debugging Firebug style.
  15. *
  16. * Note:
  17. * Note that behavior will differ with the Firebug extention and Firebug Lite.
  18. * Most notably, the Firebug Lite console does not currently allow for
  19. * hyperlinks to code or for clicking on object to explore their properties.
  20. *
  21. */
  22. OpenLayers.Console = {
  23. /**
  24. * Create empty functions for all console methods. The real value of these
  25. * properties will be set if Firebug Lite (../Firebug/firebug.js script) is
  26. * included. We explicitly require the Firebug Lite script to trigger
  27. * functionality of the OpenLayers.Console methods.
  28. */
  29. /**
  30. * APIFunction: log
  31. * Log an object in the console. The Firebug Lite console logs string
  32. * representation of objects. Given multiple arguments, they will
  33. * be cast to strings and logged with a space delimiter. If the first
  34. * argument is a string with printf-like formatting, subsequent arguments
  35. * will be used in string substitution. Any additional arguments (beyond
  36. * the number substituted in a format string) will be appended in a space-
  37. * delimited line.
  38. *
  39. * Parameters:
  40. * object - {Object}
  41. */
  42. log: function() {},
  43. /**
  44. * APIFunction: debug
  45. * Writes a message to the console, including a hyperlink to the line
  46. * where it was called.
  47. *
  48. * May be called with multiple arguments as with OpenLayers.Console.log().
  49. *
  50. * Parameters:
  51. * object - {Object}
  52. */
  53. debug: function() {},
  54. /**
  55. * APIFunction: info
  56. * Writes a message to the console with the visual "info" icon and color
  57. * coding and a hyperlink to the line where it was called.
  58. *
  59. * May be called with multiple arguments as with OpenLayers.Console.log().
  60. *
  61. * Parameters:
  62. * object - {Object}
  63. */
  64. info: function() {},
  65. /**
  66. * APIFunction: warn
  67. * Writes a message to the console with the visual "warning" icon and
  68. * color coding and a hyperlink to the line where it was called.
  69. *
  70. * May be called with multiple arguments as with OpenLayers.Console.log().
  71. *
  72. * Parameters:
  73. * object - {Object}
  74. */
  75. warn: function() {},
  76. /**
  77. * APIFunction: error
  78. * Writes a message to the console with the visual "error" icon and color
  79. * coding and a hyperlink to the line where it was called.
  80. *
  81. * May be called with multiple arguments as with OpenLayers.Console.log().
  82. *
  83. * Parameters:
  84. * object - {Object}
  85. */
  86. error: function() {},
  87. /**
  88. * APIFunction: userError
  89. * A single interface for showing error messages to the user. The default
  90. * behavior is a Javascript alert, though this can be overridden by
  91. * reassigning OpenLayers.Console.userError to a different function.
  92. *
  93. * Expects a single error message
  94. *
  95. * Parameters:
  96. * error - {Object}
  97. */
  98. userError: function(error) {
  99. alert(error);
  100. },
  101. /**
  102. * APIFunction: assert
  103. * Tests that an expression is true. If not, it will write a message to
  104. * the console and throw an exception.
  105. *
  106. * May be called with multiple arguments as with OpenLayers.Console.log().
  107. *
  108. * Parameters:
  109. * object - {Object}
  110. */
  111. assert: function() {},
  112. /**
  113. * APIFunction: dir
  114. * Prints an interactive listing of all properties of the object. This
  115. * looks identical to the view that you would see in the DOM tab.
  116. *
  117. * Parameters:
  118. * object - {Object}
  119. */
  120. dir: function() {},
  121. /**
  122. * APIFunction: dirxml
  123. * Prints the XML source tree of an HTML or XML element. This looks
  124. * identical to the view that you would see in the HTML tab. You can click
  125. * on any node to inspect it in the HTML tab.
  126. *
  127. * Parameters:
  128. * object - {Object}
  129. */
  130. dirxml: function() {},
  131. /**
  132. * APIFunction: trace
  133. * Prints an interactive stack trace of JavaScript execution at the point
  134. * where it is called. The stack trace details the functions on the stack,
  135. * as well as the values that were passed as arguments to each function.
  136. * You can click each function to take you to its source in the Script tab,
  137. * and click each argument value to inspect it in the DOM or HTML tabs.
  138. *
  139. */
  140. trace: function() {},
  141. /**
  142. * APIFunction: group
  143. * Writes a message to the console and opens a nested block to indent all
  144. * future messages sent to the console. Call OpenLayers.Console.groupEnd()
  145. * to close the block.
  146. *
  147. * May be called with multiple arguments as with OpenLayers.Console.log().
  148. *
  149. * Parameters:
  150. * object - {Object}
  151. */
  152. group: function() {},
  153. /**
  154. * APIFunction: groupEnd
  155. * Closes the most recently opened block created by a call to
  156. * OpenLayers.Console.group
  157. */
  158. groupEnd: function() {},
  159. /**
  160. * APIFunction: time
  161. * Creates a new timer under the given name. Call
  162. * OpenLayers.Console.timeEnd(name)
  163. * with the same name to stop the timer and print the time elapsed.
  164. *
  165. * Parameters:
  166. * name - {String}
  167. */
  168. time: function() {},
  169. /**
  170. * APIFunction: timeEnd
  171. * Stops a timer created by a call to OpenLayers.Console.time(name) and
  172. * writes the time elapsed.
  173. *
  174. * Parameters:
  175. * name - {String}
  176. */
  177. timeEnd: function() {},
  178. /**
  179. * APIFunction: profile
  180. * Turns on the JavaScript profiler. The optional argument title would
  181. * contain the text to be printed in the header of the profile report.
  182. *
  183. * This function is not currently implemented in Firebug Lite.
  184. *
  185. * Parameters:
  186. * title - {String} Optional title for the profiler
  187. */
  188. profile: function() {},
  189. /**
  190. * APIFunction: profileEnd
  191. * Turns off the JavaScript profiler and prints its report.
  192. *
  193. * This function is not currently implemented in Firebug Lite.
  194. */
  195. profileEnd: function() {},
  196. /**
  197. * APIFunction: count
  198. * Writes the number of times that the line of code where count was called
  199. * was executed. The optional argument title will print a message in
  200. * addition to the number of the count.
  201. *
  202. * This function is not currently implemented in Firebug Lite.
  203. *
  204. * Parameters:
  205. * title - {String} Optional title to be printed with count
  206. */
  207. count: function() {},
  208. CLASS_NAME: "OpenLayers.Console"
  209. };
  210. /**
  211. * Execute an anonymous function to extend the OpenLayers.Console namespace
  212. * if the firebug.js script is included. This closure is used so that the
  213. * "scripts" and "i" variables don't pollute the global namespace.
  214. */
  215. (function() {
  216. /**
  217. * If Firebug Lite is included (before this script), re-route all
  218. * OpenLayers.Console calls to the console object.
  219. */
  220. var scripts = document.getElementsByTagName("script");
  221. for(var i=0, len=scripts.length; i<len; ++i) {
  222. if(scripts[i].src.indexOf("firebug.js") != -1) {
  223. if(console) {
  224. OpenLayers.Util.extend(OpenLayers.Console, console);
  225. break;
  226. }
  227. }
  228. }
  229. })();