comparison geotemco/lib/simile/ajax/scripts/debug.js @ 0:b12c99b7c3f0

commit for previous development
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 19 Jan 2015 17:13:49 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:b12c99b7c3f0
1 /*==================================================
2 * Debug Utility Functions
3 *==================================================
4 */
5
6 SimileAjax.Debug = {
7 silent: false
8 };
9
10 SimileAjax.Debug.log = function(msg) {
11 var f;
12 if ("console" in window && "log" in window.console) { // FireBug installed
13 f = function(msg2) {
14 console.log(msg2);
15 }
16 } else {
17 f = function(msg2) {
18 if (!SimileAjax.Debug.silent) {
19 alert(msg2);
20 }
21 }
22 }
23 SimileAjax.Debug.log = f;
24 f(msg);
25 };
26
27 SimileAjax.Debug.warn = function(msg) {
28 var f;
29 if ("console" in window && "warn" in window.console) { // FireBug installed
30 f = function(msg2) {
31 console.warn(msg2);
32 }
33 } else {
34 f = function(msg2) {
35 if (!SimileAjax.Debug.silent) {
36 alert(msg2);
37 }
38 }
39 }
40 SimileAjax.Debug.warn = f;
41 f(msg);
42 };
43
44 SimileAjax.Debug.exception = function(e, msg) {
45 var f, params = SimileAjax.parseURLParameters();
46 if (params.errors == "throw" || SimileAjax.params.errors == "throw") {
47 f = function(e2, msg2) {
48 throw(e2); // do not hide from browser's native debugging features
49 };
50 } else if ("console" in window && "error" in window.console) { // FireBug installed
51 f = function(e2, msg2) {
52 if (msg2 != null) {
53 console.error(msg2 + " %o", e2);
54 } else {
55 console.error(e2);
56 }
57 throw(e2); // do not hide from browser's native debugging features
58 };
59 } else {
60 f = function(e2, msg2) {
61 if (!SimileAjax.Debug.silent) {
62 alert("Caught exception: " + msg2 + "\n\nDetails: " + ("description" in e2 ? e2.description : e2));
63 }
64 throw(e2); // do not hide from browser's native debugging features
65 };
66 }
67 SimileAjax.Debug.exception = f;
68 f(e, msg);
69 };
70
71 SimileAjax.Debug.objectToString = function(o) {
72 return SimileAjax.Debug._objectToString(o, "");
73 };
74
75 SimileAjax.Debug._objectToString = function(o, indent) {
76 var indent2 = indent + " ";
77 if (typeof o == "object") {
78 var s = "{";
79 for (n in o) {
80 s += indent2 + n + ": " + SimileAjax.Debug._objectToString(o[n], indent2) + "\n";
81 }
82 s += indent + "}";
83 return s;
84 } else if (typeof o == "array") {
85 var s = "[";
86 for (var n = 0; n < o.length; n++) {
87 s += SimileAjax.Debug._objectToString(o[n], indent2) + "\n";
88 }
89 s += indent + "]";
90 return s;
91 } else {
92 return o;
93 }
94 };