console surrogate added
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Thu, 1 Dec 2011 18:17:18 +0000 (19:17 +0100)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Thu, 1 Dec 2011 18:17:18 +0000 (19:17 +0100)
base-test.html
xynt-base-test.js
xynt-base.js
xynt-console.js [new file with mode: 0644]

index dbc4b8d..5fb1830 100644 (file)
@@ -1,6 +1,7 @@
 <html>
 <head>
 <script type="text/javascript" src="commons.js"></script>
+<script type="text/javascript" src="xynt-console.js"></script>
 <script type="text/javascript" src="xynt-base.js"></script>
 <script type="text/javascript" src="xynt-base-test.js"></script>
 
index 1e296f8..2b45c79 100644 (file)
@@ -68,6 +68,7 @@ function print_dynstat(inst, name)
 }
 
 window.onload = function () {
+    console.log("Window.onload: begin");
     show_class(A);
     show_class(B);
     show_class(C);
index f74baa5..35dd58e 100644 (file)
@@ -7,7 +7,7 @@ function Extends(sub)
     inh.xynt_sup = [];
     inh.xynt_sup_cl = [];
 
-    console.log("INIZIO EXT");
+    console.log("EXT START");
 
     var multi = function(sub, super, is_last)
     {
@@ -63,7 +63,9 @@ function Extends(sub)
     sub.prototype = inh;
 
     console.log(sub.prototype.xynt_sup);
-    console.log(sub.prototype.xynt_sup_cl);
+    console.log([ [ "xynt_sup_cl", "zogo" ], sub.prototype.xynt_sup_cl]);
+
+    console.log("EXT FINISH");
 }
 
 function ExtendsInst(sub)
@@ -152,7 +154,8 @@ function ExtendsInst(sub)
 function show_class(cl) {
     console.log("Attributes Class of "+cl);
     for (f in cl.prototype) {
-        console.log(f+": ["+cl.prototype[f]+"]");
+        console.log(f+"-v");
+        console.log(cl.prototype[f]);
     }
     console.log("---");
 }
@@ -160,7 +163,8 @@ function show_class(cl) {
 function show_inst(inst) {
     console.log("Attributes Instance of "+inst);
     for (f in inst) {
-        console.log("["+f+"]: ["+inst[f]+"]");
+        console.log(f+"-v");
+        // console.log(inst[f]);
     }
     console.log("---");
 }
diff --git a/xynt-console.js b/xynt-console.js
new file mode 100644 (file)
index 0000000..b0cb0ff
--- /dev/null
@@ -0,0 +1,138 @@
+function xynt_console(ena) {
+    var conbody, condiv;
+
+    this.enable = ena;
+    if (ena) {
+        this.win = window.open("","xynt console","navigation=no,scrollbars=yes,height=500,width=800,left=0,top=800");
+        // titl = this.win.document.createElement("title");
+        // titl.innerHTML = "xynt console";
+        conbody = this.win.document.createElement("body");
+        this.div = condiv = this.win.document.createElement("div");
+
+        conbody.id = "console_body";
+        // this.win.document.head.appendChild(titl);
+        this.win.document.body.appendChild(condiv);
+        this.win.document.title = "xynt console";
+    }
+}
+
+xynt_console.prototype = {
+    win: null,
+    div: null,
+    enable: false,
+
+    escapeHTML: function(s) {
+        var v = s+"";
+        return v.replace(/&/g,'&amp;').
+                replace(/ /g,'&nbsp;').
+                replace(/"/g,'&quot;').
+            // replace(/'/g,'&#039;').
+                replace(/>/g,'&gt;').
+                replace(/</g,'&lt;').                        
+                replace(/\n/g, "<br>\n");
+    },
+
+    log: function(s) {
+        if (!this.enable) {
+            return;
+        }
+        if (typeof(s) == "string" || typeof(s) == "function") {
+            this.div.innerHTML += this.escapeHTML(s);
+        }
+        else {
+            ind = 4;
+            this.dump_obj(s,ind);
+        }
+        this.div.innerHTML += "<hr style=\"height: 1px;\">\n";
+        this.win.document.body.scrollTop = 10000000;
+    },
+
+    dump_obj: function(s, ind) {
+        var sind = "";
+
+        alert(ind);
+        sind = "<span style=\"background-color:#f0f0f0;\">";
+        for (i = 0 ; i < ind ; i++) {
+            sind += "&nbsp;";
+        }
+        sind += "</span>";
+        for (i in s) {
+            if (typeof(s[i]) == 'string' || typeof(s[i]) == "function") {
+                var ret = "";
+                var arr = this.escapeHTML(s[i]).split("\n");
+                for (el in arr) {
+                    ret += sind + arr[el] + "\n";
+                }
+                // this.div.innerHTML += "xx["+this.escapeHTML(i) + "] : [" + ret + "]<hr style=\"height: 1px; width: 100px;\"><br>\n";
+                this.div.innerHTML += this.escapeHTML(i)+"<br>\n";
+                this.div.innerHTML += ret + "<hr style=\"height: 1px; width: 100px;\"><br>\n";
+            }
+            else {
+                this.dump_obj(s[i], ind+4);
+            }
+        }       
+        // this.div.innerHTML += "post-loop<br>";
+    },
+
+    logger: function(s) {
+        if (!this.enable) {
+            return;
+        }
+        this.div.innerHTML += s + "<br>";
+        this.win.document.body.scrollTop = 10000000;
+    },
+
+    close: function() {
+        if (this.enable) {
+            this.win.close();
+        }
+    }
+}
+
+/*
+ *  create and destroy 
+ */
+var is_xynt_console = false;
+var console_enable = true;
+
+if(typeof(console) == "undefined") {
+    var console;
+    
+    console = new xynt_console(console_enable);
+
+    is_xynt_console = true;
+}
+else {
+    // console.logger = console.log;
+    // console.log = function () { return 0; }
+}
+
+function deconsole() {
+    if (is_xynt_console) {
+        console.close();
+    }
+}
+
+function log_walk(curtag)
+{
+    var ind = 0;
+    var ancestor = curtag;
+    do {
+        console.log(spcs("_", "+", ind)+" ["+curtag.tagName+"]  nodeType: "+curtag.nodeType+" inner: ["+curtag.innerHTML+"]");
+        if (curtag.firstChild != null && curtag.tagName != "TD") {
+            ind += 2;
+            curtag = curtag.firstChild;
+        }
+        else if (curtag.nextSibling != null) {
+            curtag = curtag.nextSibling;
+        }
+        else if (curtag.parentNode.nextSibling != null) {
+            ind -= 2;
+            curtag = curtag.parentNode.nextSibling;
+        }
+        else
+            curtag = null;
+    } while (curtag != null && curtag != ancestor);
+}
+
+