From 62fc1fb1aa453f74fb8d77dfc47f5e1647a01369 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Fri, 8 Jan 2021 09:32:51 -0600 Subject: [PATCH] replace Mootools Browser object with our own --- web/js/logger.js | 102 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 90 insertions(+), 12 deletions(-) diff --git a/web/js/logger.js b/web/js/logger.js index 56638b946..341b28b39 100644 --- a/web/js/logger.js +++ b/web/js/logger.js @@ -57,24 +57,13 @@ function logReport( level, message, file, line ) { //console.log("arguments"); } - var browser = {}; - if ( Browser ) { - browser.name = Browser.name; - browser.version = Browser.version; - browser.platform = Browser.Platform ? Browser.Platform.name : 'unknown'; - } else { - browser.name = 'unknown'; - browser.version = 'unknown'; - browser.platform = 'unknown'; - } - var data = { view: 'request', request: 'log', task: 'create', level: level, message: encodeURIComponent(message), - browser: browser + browser: browserInfo() }; if ( file ) { @@ -125,3 +114,92 @@ function Dump(value, label) { if ( label ) console.debug(label+" => "); console.debug(value); } + +/* +JQuery has deprecated its browser object. This function implements our own +browser object. It strikes a compromise between importing a full browser +detection js library and using the js navigator object in its umodified form. +*/ + +function browserInfo() { + var browser = {}; + var nVer = navigator.appVersion; + var nAgt = navigator.userAgent; + var browserName = navigator.appName; + var fullVersion = ''+parseFloat(navigator.appVersion); + var majorVersion = parseInt(navigator.appVersion,10); + var nameOffset,verOffset,ix; + + // In Opera, the true version is after "Opera" or after "Version" + if ((verOffset=nAgt.indexOf("Opera")) != -1) { + browserName = "Opera"; + fullVersion = nAgt.substring(verOffset+6); + if ((verOffset=nAgt.indexOf("Version")) != -1) + fullVersion = nAgt.substring(verOffset+8); + } + + // In MSIE, the true version is after "MSIE" in userAgent + else if ((verOffset=nAgt.indexOf("MSIE")) != -1) { + browserName = "Microsoft Internet Explorer"; + fullVersion = nAgt.substring(verOffset+5); + } + + // In Chrome, the true version is after "Chrome" + else if ((verOffset=nAgt.indexOf("Chrome")) != -1) { + browserName = "Chrome"; + fullVersion = nAgt.substring(verOffset+7); + } + + // In Safari, the true version is after "Safari" or after "Version" + else if ((verOffset=nAgt.indexOf("Safari")) != -1) { + browserName = "Safari"; + fullVersion = nAgt.substring(verOffset+7); + if ((verOffset=nAgt.indexOf("Version")) != -1) + fullVersion = nAgt.substring(verOffset+8); + } + + // In Firefox, the true version is after "Firefox" + else if ((verOffset=nAgt.indexOf("Firefox")) != -1) { + browserName = "Firefox"; + fullVersion = nAgt.substring(verOffset+8); + } + + // In most other browsers, "name/version" is at the end of userAgent + else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) { + browserName = nAgt.substring(nameOffset,verOffset); + fullVersion = nAgt.substring(verOffset+1); + if (browserName.toLowerCase()==browserName.toUpperCase()) { + browserName = navigator.appName; + } + } + + // trim the fullVersion string at semicolon/space if present + if ((ix=fullVersion.indexOf(";")) != -1) + fullVersion=fullVersion.substring(0,ix); + if ((ix=fullVersion.indexOf(" ")) != -1) + fullVersion=fullVersion.substring(0,ix); + + majorVersion = parseInt(''+fullVersion,10); + if (isNaN(majorVersion)) { + fullVersion = ''+parseFloat(navigator.appVersion); + majorVersion = parseInt(navigator.appVersion,10); + } + + // OSName variable is set as follows: + // "Windows" for all versions of Windows + // "MacOS" for all versions of Macintosh OS + // "Linux" for all versions of Linux + // "UNIX" for all other UNIX flavors + // "Unknown OS" indicates failure to detect the OS + var OSName="Unknown OS"; + if (navigator.appVersion.indexOf("Win") != -1) OSName="Windows"; + if (navigator.appVersion.indexOf("Mac") != -1) OSName="MacOS"; + if (navigator.appVersion.indexOf("X11") != -1) OSName="UNIX"; + if (navigator.appVersion.indexOf("Linux") != -1) OSName="Linux"; + + browser.name = browserName; + browser.version = fullVersion; + browser.platform = OSName; + + return browser; +}