From 29d268c228f3bbea50358d0f489e1f434c078d21 Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Sat, 21 Feb 2009 17:46:05 +0000 Subject: [PATCH] myconsole.js facility to debug ie with console.log and probrowser.js facility for checking of browser type added --- web/myconsole.js | 89 +++++++++++++++++++++++++++++++++++++++++++++++ web/probrowser.js | 60 ++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 web/myconsole.js create mode 100644 web/probrowser.js diff --git a/web/myconsole.js b/web/myconsole.js new file mode 100644 index 0000000..4d47f4d --- /dev/null +++ b/web/myconsole.js @@ -0,0 +1,89 @@ +function myconsole(ena) { + var conbody, condiv; + + this.enable = ena; + if (ena) { + this.win = window.open("","","scrollbars=yes,height=500,width=400,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); + } +} + +myconsole.prototype = { + win: null, + div: null, + enable: false, + + log: function(s) { + if (!this.enable) { + return; + } + this.div.innerHTML += s + "
"; + this.win.document.body.scrollTop = 10000000; + }, + + 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 ismyconsole = false; +var console_enable = true; + +if(typeof(console) == "undefined") { + var console; + + console = new myconsole(console_enable); + + ismyconsole = true; +} +else { + // console.logger = console.log; + // console.log = function () { return 0; } +} + +function deconsole() { + if (ismyconsole) { + 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); +} + + diff --git a/web/probrowser.js b/web/probrowser.js new file mode 100644 index 0000000..d4cc1db --- /dev/null +++ b/web/probrowser.js @@ -0,0 +1,60 @@ +function get_browser_agent() +{ + var ua = navigator.userAgent.toLowerCase(); + var opera = ((ua.indexOf('opera') != -1) ? true : false); + var espial = ((ua.indexOf('escape') != -1) ? true : false); + var safari = ((ua.indexOf('safari') != -1) ? true : false); + var firefox = ((ua.indexOf('firefox') != -1) ? true : false); + var msie = ((ua.indexOf('msie') != -1) ? true : false); + var mac = ((ua.indexOf('mac') != -1) ? true : false); + var unix = ((ua.indexOf('x11') != -1) ? true : false); + var win = ((mac || unix) ? false : true); + var version = false; + var mozilla = false; + + if (!firefox && !safari && (ua.indexOf('gecko') != -1)) { + mozilla = true; + var _tmp = ua.split('/'); + version = _tmp[_tmp.length - 1].split(' ')[0]; + } + + if (firefox) + { + var _tmp = ua.split('/'); + version = _tmp[_tmp.length - 1].split(' ')[0]; + } + if (msie) + version = ua.substring((ua.indexOf('msie ') + 5)).split(';')[0]; + + if (safari) + { + /** + * Safari doesn't report a string, have to use getBrowserEngine to get it + */ + // version = this.getBrowserEngine().version; + version = ua.substring((ua.indexOf('safari/') + 7)).split(' ')[0]; + + } + + if (opera) + version = ua.substring((ua.indexOf('opera/') + 6)).split(' ')[0]; + + /** + * Return the Browser Object + * @type Object + */ + var browsers = { + ua: navigator.userAgent, + opera: opera, + espial: espial, + safari: safari, + firefox: firefox, + mozilla: mozilla, + msie: msie, + mac: mac, + win: win, + unix: unix, + version: version + } + return browsers; +} -- 2.17.1