Project

General

Profile

Download (7.7 KB) Statistics
| Branch: | Tag: | Revision:
1
/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
2
 * full list of contributors). Published under the 2-clause BSD license.
3
 * See license.txt in the OpenLayers distribution or repository for the
4
 * full text of the license. */
5

    
6
/**
7
 * @requires OpenLayers/BaseTypes/Class.js
8
 */
9

    
10
/**
11
 * Namespace: OpenLayers.Console
12
 * The OpenLayers.Console namespace is used for debugging and error logging.
13
 * If the Firebug Lite (../Firebug/firebug.js) is included before this script,
14
 * calls to OpenLayers.Console methods will get redirected to window.console.
15
 * This makes use of the Firebug extension where available and allows for
16
 * cross-browser debugging Firebug style.
17
 *
18
 * Note:
19
 * Note that behavior will differ with the Firebug extention and Firebug Lite.
20
 * Most notably, the Firebug Lite console does not currently allow for
21
 * hyperlinks to code or for clicking on object to explore their properties.
22
 * 
23
 */
24
OpenLayers.Console = {
25
    /**
26
     * Create empty functions for all console methods.  The real value of these
27
     * properties will be set if Firebug Lite (../Firebug/firebug.js script) is
28
     * included.  We explicitly require the Firebug Lite script to trigger
29
     * functionality of the OpenLayers.Console methods.
30
     */
31
    
32
    /**
33
     * APIFunction: log
34
     * Log an object in the console.  The Firebug Lite console logs string
35
     * representation of objects.  Given multiple arguments, they will
36
     * be cast to strings and logged with a space delimiter.  If the first
37
     * argument is a string with printf-like formatting, subsequent arguments
38
     * will be used in string substitution.  Any additional arguments (beyond
39
     * the number substituted in a format string) will be appended in a space-
40
     * delimited line.
41
     * 
42
     * Parameters:
43
     * object - {Object}
44
     */
45
    log: function() {},
46

    
47
    /**
48
     * APIFunction: debug
49
     * Writes a message to the console, including a hyperlink to the line
50
     * where it was called.
51
     *
52
     * May be called with multiple arguments as with OpenLayers.Console.log().
53
     * 
54
     * Parameters:
55
     * object - {Object}
56
     */
57
    debug: function() {},
58

    
59
    /**
60
     * APIFunction: info
61
     * Writes a message to the console with the visual "info" icon and color
62
     * coding and a hyperlink to the line where it was called.
63
     *
64
     * May be called with multiple arguments as with OpenLayers.Console.log().
65
     * 
66
     * Parameters:
67
     * object - {Object}
68
     */
69
    info: function() {},
70

    
71
    /**
72
     * APIFunction: warn
73
     * Writes a message to the console with the visual "warning" icon and
74
     * color coding and a hyperlink to the line where it was called.
75
     *
76
     * May be called with multiple arguments as with OpenLayers.Console.log().
77
     * 
78
     * Parameters:
79
     * object - {Object}
80
     */
81
    warn: function() {},
82

    
83
    /**
84
     * APIFunction: error
85
     * Writes a message to the console with the visual "error" icon and color
86
     * coding and a hyperlink to the line where it was called.
87
     *
88
     * May be called with multiple arguments as with OpenLayers.Console.log().
89
     * 
90
     * Parameters:
91
     * object - {Object}
92
     */
93
    error: function() {},
94
    
95
    /**
96
     * APIFunction: userError
97
     * A single interface for showing error messages to the user. The default
98
     * behavior is a Javascript alert, though this can be overridden by
99
     * reassigning OpenLayers.Console.userError to a different function.
100
     *
101
     * Expects a single error message
102
     * 
103
     * Parameters:
104
     * error - {Object}
105
     */
106
    userError: function(error) {
107
        alert(error);
108
    },
109

    
110
    /**
111
     * APIFunction: assert
112
     * Tests that an expression is true. If not, it will write a message to
113
     * the console and throw an exception.
114
     *
115
     * May be called with multiple arguments as with OpenLayers.Console.log().
116
     * 
117
     * Parameters:
118
     * object - {Object}
119
     */
120
    assert: function() {},
121

    
122
    /**
123
     * APIFunction: dir
124
     * Prints an interactive listing of all properties of the object. This
125
     * looks identical to the view that you would see in the DOM tab.
126
     * 
127
     * Parameters:
128
     * object - {Object}
129
     */
130
    dir: function() {},
131

    
132
    /**
133
     * APIFunction: dirxml
134
     * Prints the XML source tree of an HTML or XML element. This looks
135
     * identical to the view that you would see in the HTML tab. You can click
136
     * on any node to inspect it in the HTML tab.
137
     * 
138
     * Parameters:
139
     * object - {Object}
140
     */
141
    dirxml: function() {},
142

    
143
    /**
144
     * APIFunction: trace
145
     * Prints an interactive stack trace of JavaScript execution at the point
146
     * where it is called.  The stack trace details the functions on the stack,
147
     * as well as the values that were passed as arguments to each function.
148
     * You can click each function to take you to its source in the Script tab,
149
     * and click each argument value to inspect it in the DOM or HTML tabs.
150
     * 
151
     */
152
    trace: function() {},
153

    
154
    /**
155
     * APIFunction: group
156
     * Writes a message to the console and opens a nested block to indent all
157
     * future messages sent to the console. Call OpenLayers.Console.groupEnd()
158
     * to close the block.
159
     *
160
     * May be called with multiple arguments as with OpenLayers.Console.log().
161
     * 
162
     * Parameters:
163
     * object - {Object}
164
     */
165
    group: function() {},
166

    
167
    /**
168
     * APIFunction: groupEnd
169
     * Closes the most recently opened block created by a call to
170
     * OpenLayers.Console.group
171
     */
172
    groupEnd: function() {},
173
    
174
    /**
175
     * APIFunction: time
176
     * Creates a new timer under the given name. Call
177
     * OpenLayers.Console.timeEnd(name)
178
     * with the same name to stop the timer and print the time elapsed.
179
     *
180
     * Parameters:
181
     * name - {String}
182
     */
183
    time: function() {},
184

    
185
    /**
186
     * APIFunction: timeEnd
187
     * Stops a timer created by a call to OpenLayers.Console.time(name) and
188
     * writes the time elapsed.
189
     *
190
     * Parameters:
191
     * name - {String}
192
     */
193
    timeEnd: function() {},
194

    
195
    /**
196
     * APIFunction: profile
197
     * Turns on the JavaScript profiler. The optional argument title would
198
     * contain the text to be printed in the header of the profile report.
199
     *
200
     * This function is not currently implemented in Firebug Lite.
201
     * 
202
     * Parameters:
203
     * title - {String} Optional title for the profiler
204
     */
205
    profile: function() {},
206

    
207
    /**
208
     * APIFunction: profileEnd
209
     * Turns off the JavaScript profiler and prints its report.
210
     * 
211
     * This function is not currently implemented in Firebug Lite.
212
     */
213
    profileEnd: function() {},
214

    
215
    /**
216
     * APIFunction: count
217
     * Writes the number of times that the line of code where count was called
218
     * was executed. The optional argument title will print a message in
219
     * addition to the number of the count.
220
     *
221
     * This function is not currently implemented in Firebug Lite.
222
     *
223
     * Parameters:
224
     * title - {String} Optional title to be printed with count
225
     */
226
    count: function() {},
227

    
228
    CLASS_NAME: "OpenLayers.Console"
229
};
230

    
231
/**
232
 * Execute an anonymous function to extend the OpenLayers.Console namespace
233
 * if the firebug.js script is included.  This closure is used so that the
234
 * "scripts" and "i" variables don't pollute the global namespace.
235
 */
236
(function() {
237
    /**
238
     * If Firebug Lite is included (before this script), re-route all
239
     * OpenLayers.Console calls to the console object.
240
     */
241
    var scripts = document.getElementsByTagName("script");
242
    for(var i=0, len=scripts.length; i<len; ++i) {
243
        if(scripts[i].src.indexOf("firebug.js") != -1) {
244
            if(console) {
245
                OpenLayers.Util.extend(OpenLayers.Console, console);
246
                break;
247
            }
248
        }
249
    }
250
})();
(3-3/35)