From 4c8c1f53b56f0caadd725a5e423042bed5d2c4c8 Mon Sep 17 00:00:00 2001 From: joassouza Date: Tue, 1 Dec 2015 11:53:49 -0300 Subject: Update the bowser.js to the new version With this new version of bowser.js is possible detect the OS as well, no only the browser as the previous one. It brings support to new browsers as well. --- src/static/js/ace2_inner.js | 2 +- src/static/js/browser.js | 100 +++++++++++++++++++++++++++++++++++------- src/templates/pad.html | 2 +- src/templates/timeslider.html | 14 +++--- 4 files changed, 92 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 220136af..2fd7978f 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -21,7 +21,7 @@ */ var _, $, jQuery, plugins, Ace2Common; -var browser = require('./browser').browser; +var browser = require('./browser'); if(browser.msie){ // Honestly fuck IE royally. // Basically every hack we have since V11 causes a problem 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 diff --git a/src/templates/pad.html b/src/templates/pad.html index 84f9fef8..7e38b472 100644 --- a/src/templates/pad.html +++ b/src/templates/pad.html @@ -390,7 +390,7 @@ require.setGlobalKeyPath("require"); $ = jQuery = require('ep_etherpad-lite/static/js/rjquery').jQuery; // Expose jQuery #HACK - browser = require('ep_etherpad-lite/static/js/browser').browser; + browser = require('ep_etherpad-lite/static/js/browser'); if ((!browser.msie) && (!(browser.mozilla && browser.version.indexOf("1.8.") == 0))) { document.domain = document.domain; // for comet } diff --git a/src/templates/timeslider.html b/src/templates/timeslider.html index 6ec27c05..af0a8f02 100644 --- a/src/templates/timeslider.html +++ b/src/templates/timeslider.html @@ -68,7 +68,7 @@ - +
@@ -231,20 +231,20 @@