From: Matteo Nastasi (mop) Date: Sat, 17 Dec 2011 14:17:26 +0000 (+0100) Subject: enhanced version of custom console object (for windows) X-Git-Tag: pre-sac~8 X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=commitdiff_plain;h=a4b476969bcf68491e377ed1ed15271ff9271df9;p=brisk.git enhanced version of custom console object (for windows) --- diff --git a/web/myconsole.js b/web/myconsole.js index 4d47f4d..223abdc 100644 --- a/web/myconsole.js +++ b/web/myconsole.js @@ -1,30 +1,76 @@ -function myconsole(ena) { +function xynt_console(ena) { var conbody, condiv; this.enable = ena; if (ena) { - this.win = window.open("","","scrollbars=yes,height=500,width=400,left=0,top=800"); + this.win = window.open("","xyntconsole","scrollbars=yes,height=500,width=800,left=0,top=800"); + conbody = this.win.document.createElement("body"); this.div = condiv = this.win.document.createElement("div"); conbody.id = "console_body"; this.win.document.body.appendChild(condiv); + this.win.document.title = "xynt console"; } } -myconsole.prototype = { +xynt_console.prototype = { win: null, div: null, enable: false, + escapeHTML: function(s) { + var v = s+""; + return v.replace(/&/g,'&'). + replace(/ /g,' '). + replace(/"/g,'"'). + // replace(/'/g,'''). + replace(/>/g,'>'). + replace(/\n"); + }, + log: function(s) { if (!this.enable) { return; } - this.div.innerHTML += s + "
"; + if (typeof(s) == "string" || typeof(s) == "function") { + this.div.innerHTML += this.escapeHTML(s); + } + else { + ind = 4; + this.dump_obj(s,ind); + } + this.div.innerHTML += "
\n"; this.win.document.body.scrollTop = 10000000; }, + dump_obj: function(s, ind) { + var sind = ""; + + sind = ""; + for (i = 0 ; i < ind ; i++) { + sind += " "; + } + sind += ""; + 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 + "]

\n"; + this.div.innerHTML += this.escapeHTML(i)+"
\n"; + this.div.innerHTML += ret + "

\n"; + } + else { + this.dump_obj(s[i], ind+4); + } + } + // this.div.innerHTML += "post-loop
"; + }, + logger: function(s) { if (!this.enable) { return; @@ -43,23 +89,22 @@ myconsole.prototype = { /* * create and destroy */ -var ismyconsole = false; +var is_xynt_console = false; var console_enable = true; if(typeof(console) == "undefined") { var console; - - console = new myconsole(console_enable); - ismyconsole = true; + console = new xynt_console(console_enable); + + is_xynt_console = true; } else { - // console.logger = console.log; - // console.log = function () { return 0; } + // conzole.logger = console.log; + // conzole.log = function () { return 0; } } - function deconsole() { - if (ismyconsole) { + if (is_xynt_console) { console.close(); } }