myconsole.js facility to debug ie with console.log and probrowser.js facility for...
[brisk.git] / web / myconsole.js
1 function myconsole(ena) {
2     var conbody, condiv;
3
4     this.enable = ena;
5     if (ena) {
6         this.win = window.open("","","scrollbars=yes,height=500,width=400,left=0,top=800");
7         conbody = this.win.document.createElement("body");
8         this.div = condiv = this.win.document.createElement("div");
9
10         conbody.id = "console_body";
11         this.win.document.body.appendChild(condiv);
12     }
13 }
14
15 myconsole.prototype = {
16     win: null,
17     div: null,
18     enable: false,
19
20     log: function(s) {
21         if (!this.enable) {
22             return;
23         }
24         this.div.innerHTML += s + "<br>";
25         this.win.document.body.scrollTop = 10000000;
26     },
27
28     logger: function(s) {
29         if (!this.enable) {
30             return;
31         }
32         this.div.innerHTML += s + "<br>";
33         this.win.document.body.scrollTop = 10000000;
34     },
35
36     close: function() {
37         if (this.enable) {
38             this.win.close();
39         }
40     }
41 }
42
43 /*
44  *  create and destroy 
45  */
46 var ismyconsole = false;
47 var console_enable = true;
48
49 if(typeof(console) == "undefined") {
50     var console;
51     
52     console = new myconsole(console_enable);
53
54     ismyconsole = true;
55 }
56 else {
57     // console.logger = console.log;
58     // console.log = function () { return 0; }
59 }
60
61 function deconsole() {
62     if (ismyconsole) {
63         console.close();
64     }
65 }
66
67 function log_walk(curtag)
68 {
69     var ind = 0;
70     var ancestor = curtag;
71     do {
72         console.log(spcs("_", "+", ind)+" ["+curtag.tagName+"]  nodeType: "+curtag.nodeType+" inner: ["+curtag.innerHTML+"]");
73         if (curtag.firstChild != null && curtag.tagName != "TD") {
74             ind += 2;
75             curtag = curtag.firstChild;
76         }
77         else if (curtag.nextSibling != null) {
78             curtag = curtag.nextSibling;
79         }
80         else if (curtag.parentNode.nextSibling != null) {
81             ind -= 2;
82             curtag = curtag.parentNode.nextSibling;
83         }
84         else
85             curtag = null;
86     } while (curtag != null && curtag != ancestor);
87 }
88
89