X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2Fxynt%2Fxynt-console.js;fp=web%2Fxynt%2Fxynt-console.js;h=c4bf044f2bedcf9eb680f65c35d1848d4869da40;hb=9f0cbf62feaea515635cfc85bddd5292b2170440;hp=0000000000000000000000000000000000000000;hpb=ff96d86813afe7c2d607bc6ca9d5c18c378c6fed;p=xynt.git diff --git a/web/xynt/xynt-console.js b/web/xynt/xynt-console.js new file mode 100644 index 0000000..c4bf044 --- /dev/null +++ b/web/xynt/xynt-console.js @@ -0,0 +1,137 @@ +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,'&'). + replace(/ /g,' '). + replace(/"/g,'"'). + // replace(/'/g,'''). + replace(/>/g,'>'). + replace(/\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 += "
\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; + } + this.div.innerHTML += s + "
"; + 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 { + // conzole.logger = console.log; + // conzole.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); +} + +