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