Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.debug.console");
14
dojo.require("dojo.logging.ConsoleLogger");
15
if (window.console) {
16
	if (console.info != null) {
17
		dojo.hostenv.println = function () {
18
			if (!djConfig.isDebug) {
19
				return;
20
			}
21
			console.info.apply(console, arguments);
22
		};
23
		dojo.debug = dojo.hostenv.println;
24
		dojo.debugDeep = dojo.debug;
25
		dojo.debugShallow = function (obj, showMethods, sort) {
26
			if (!djConfig.isDebug) {
27
				return;
28
			}
29
			showMethods = (showMethods != false);
30
			sort = (sort != false);
31
			if (obj == null || obj.constructor == null) {
32
				return dojo.debug(obj);
33
			}
34
			var type = obj.declaredClass;
35
			if (type == null) {
36
				type = obj.constructor.toString().match(/function\s*(.*)\(/);
37
				if (type) {
38
					type = type[1];
39
				}
40
			}
41
			if (type) {
42
				if (type == "String" || type == "Number") {
43
					return dojo.debug(type + ": ", obj);
44
				}
45
				if (showMethods && !sort) {
46
					var sortedObj = obj;
47
				} else {
48
					var propNames = [];
49
					if (showMethods) {
50
						for (var prop in obj) {
51
							propNames.push(prop);
52
						}
53
					} else {
54
						for (var prop in obj) {
55
							if (typeof obj[prop] != "function") {
56
								propNames.push(prop);
57
							} else {
58
								dojo.debug(prop);
59
							}
60
						}
61
					}
62
					if (sort) {
63
						propNames.sort();
64
					}
65
					var sortedObj = {};
66
					dojo.lang.forEach(propNames, function (prop) {
67
						sortedObj[prop] = obj[prop];
68
					});
69
				}
70
				return dojo.debug(type + ": %o\n%2.o", obj, sortedObj);
71
			}
72
			return dojo.debug(obj.constructor + ": ", obj);
73
		};
74
	} else {
75
		if (console.log != null) {
76
			dojo.hostenv.println = function () {
77
				if (!djConfig.isDebug) {
78
					return;
79
				}
80
				var args = dojo.lang.toArray(arguments);
81
				console.log("DEBUG: " + args.join(" "));
82
			};
83
			dojo.debug = dojo.hostenv.println;
84
		} else {
85
			dojo.debug("dojo.debug.console requires Firebug > 0.4");
86
		}
87
	}
88
} else {
89
	if (dojo.render.html.opera) {
90
		if (opera && opera.postError) {
91
			dojo.hostenv.println = opera.postError;
92
		} else {
93
			dojo.debug("dojo.debug.Opera requires Opera > 8.0");
94
		}
95
	}
96
}
97