diff options
Diffstat (limited to 'src/static/js/browser.js')
-rw-r--r-- | src/static/js/browser.js | 100 |
1 files changed, 83 insertions, 17 deletions
diff --git a/src/static/js/browser.js b/src/static/js/browser.js index f763963e..5d5f741a 100644 --- a/src/static/js/browser.js +++ b/src/static/js/browser.js @@ -1,11 +1,11 @@ /*! * Bowser - a browser detector * https://github.com/ded/bowser - * MIT License | (c) Dustin Diaz 2014 + * MIT License | (c) Dustin Diaz 2015 */ !function (name, definition) { - if (typeof module != 'undefined' && module.exports) module.exports['browser'] = definition() + if (typeof module != 'undefined' && module.exports) module.exports = definition() else if (typeof define == 'function' && define.amd) define(definition) else this[name] = definition() }('bowser', function () { @@ -22,9 +22,24 @@ return (match && match.length > 1 && match[1]) || ''; } + function getSecondMatch(regex) { + var match = ua.match(regex); + return (match && match.length > 1 && match[2]) || ''; + } + var iosdevice = getFirstMatch(/(ipod|iphone|ipad)/i).toLowerCase() , likeAndroid = /like android/i.test(ua) , android = !likeAndroid && /android/i.test(ua) + , chromeos = /CrOS/.test(ua) + , silk = /silk/i.test(ua) + , sailfish = /sailfish/i.test(ua) + , tizen = /tizen/i.test(ua) + , webos = /(web|hpw)os/i.test(ua) + , windowsphone = /windows phone/i.test(ua) + , windows = !windowsphone && /windows/i.test(ua) + , mac = !iosdevice && !silk && /macintosh/i.test(ua) + , linux = !android && !sailfish && !tizen && !webos && /linux/i.test(ua) + , edgeVersion = getFirstMatch(/edge\/(\d+(\.\d+)?)/i) , versionIdentifier = getFirstMatch(/version\/(\d+(\.\d+)?)/i) , tablet = /tablet/i.test(ua) , mobile = !tablet && /[^-]mobi/i.test(ua) @@ -37,12 +52,25 @@ , version: versionIdentifier || getFirstMatch(/(?:opera|opr)[\s\/](\d+(\.\d+)?)/i) } } - else if (/windows phone/i.test(ua)) { + else if (/yabrowser/i.test(ua)) { + result = { + name: 'Yandex Browser' + , yandexbrowser: t + , version: versionIdentifier || getFirstMatch(/(?:yabrowser)[\s\/](\d+(\.\d+)?)/i) + } + } + else if (windowsphone) { result = { name: 'Windows Phone' , windowsphone: t - , msie: t - , version: getFirstMatch(/iemobile\/(\d+(\.\d+)?)/i) + } + if (edgeVersion) { + result.msedge = t + result.version = edgeVersion + } + else { + result.msie = t + result.version = getFirstMatch(/iemobile\/(\d+(\.\d+)?)/i) } } else if (/msie|trident/i.test(ua)) { @@ -51,6 +79,20 @@ , msie: t , version: getFirstMatch(/(?:msie |rv:)(\d+(\.\d+)?)/i) } + } else if (chromeos) { + result = { + name: 'Chrome' + , chromeos: t + , chromeBook: t + , chrome: t + , version: getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i) + } + } else if (/chrome.+? edge/i.test(ua)) { + result = { + name: 'Microsoft Edge' + , msedge: t + , version: edgeVersion + } } else if (/chrome|crios|crmo/i.test(ua)) { result = { @@ -68,7 +110,7 @@ result.version = versionIdentifier } } - else if (/sailfish/i.test(ua)) { + else if (sailfish) { result = { name: 'Sailfish' , sailfish: t @@ -92,7 +134,7 @@ result.firefoxos = t } } - else if (/silk/i.test(ua)) { + else if (silk) { result = { name: 'Amazon Silk' , silk: t @@ -119,7 +161,7 @@ , version: versionIdentifier || getFirstMatch(/blackberry[\d]+\/(\d+(\.\d+)?)/i) } } - else if (/(web|hpw)os/i.test(ua)) { + else if (webos) { result = { name: 'WebOS' , webos: t @@ -134,7 +176,7 @@ , version: getFirstMatch(/dolfin\/(\d+(\.\d+)?)/i) }; } - else if (/tizen/i.test(ua)) { + else if (tizen) { result = { name: 'Tizen' , tizen: t @@ -148,10 +190,15 @@ , version: versionIdentifier } } - else result = {} + else { + result = { + name: getFirstMatch(/^(.*)\/(.*) /), + version: getSecondMatch(/^(.*)\/(.*) /) + }; + } // set webkit or gecko flag for browsers based on these engines - if (/(apple)?webkit/i.test(ua)) { + if (!result.msedge && /(apple)?webkit/i.test(ua)) { result.name = result.name || "Webkit" result.webkit = t if (!result.version && versionIdentifier) { @@ -164,22 +211,28 @@ } // set OS flags for platforms that have multiple browsers - if (android || result.silk) { + if (!result.msedge && (android || result.silk)) { result.android = t } else if (iosdevice) { result[iosdevice] = t result.ios = t + } else if (windows) { + result.windows = t + } else if (mac) { + result.mac = t + } else if (linux) { + result.linux = t } // OS version extraction var osVersion = ''; - if (iosdevice) { + if (result.windowsphone) { + osVersion = getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i); + } else if (iosdevice) { osVersion = getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i); osVersion = osVersion.replace(/[_\s]/g, '.'); } else if (android) { osVersion = getFirstMatch(/android[ \/-](\d+(\.\d+)*)/i); - } else if (result.windowsphone) { - osVersion = getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i); } else if (result.webos) { osVersion = getFirstMatch(/(?:web|hpw)os\/(\d+(\.\d+)*)/i); } else if (result.blackberry) { @@ -203,7 +256,9 @@ // Graded Browser Support // http://developer.yahoo.com/yui/articles/gbs - if ((result.msie && result.version >= 10) || + if (result.msedge || + (result.msie && result.version >= 10) || + (result.yandexbrowser && result.version >= 15) || (result.chrome && result.version >= 20) || (result.firefox && result.version >= 20.0) || (result.safari && result.version >= 6) || @@ -228,6 +283,17 @@ var bowser = detect(typeof navigator !== 'undefined' ? navigator.userAgent : '') + bowser.test = function (browserList) { + for (var i = 0; i < browserList.length; ++i) { + var browserItem = browserList[i]; + if (typeof browserItem=== 'string') { + if (browserItem in bowser) { + return true; + } + } + } + return false; + } /* * Set our detect method to the main bowser object so we can @@ -237,4 +303,4 @@ bowser._detect = detect; return bowser -}); +});
\ No newline at end of file |