1
0
mirror of https://github.com/lancedikson/bowser synced 2024-10-27 20:34:22 +00:00

first flush of refactorings, clarified identifiers, moved flag generation for OSes that may have multiple browsers out of browser-specific code

This commit is contained in:
BendingBender 2014-02-25 23:34:03 +01:00
parent c19a6672aa
commit 745c38b758
4 changed files with 212 additions and 259 deletions

234
bowser.js
View File

@ -13,235 +13,211 @@
* See useragents.js for examples of navigator.userAgent * See useragents.js for examples of navigator.userAgent
*/ */
var t = true, var t = true
v /* temporary placeholder for versions. */
function getVersion(ua, regex, matchedIdx) {
var match = ua.match(regex);
return (match && match.length > matchedIdx && match[matchedIdx]) || 0;
}
function detect(ua) { function detect(ua) {
var ie = /(msie|trident)/i.test(ua) function getVersion(regex) {
var match = ua.match(regex);
return (match && match.length > 1 && match[1]) || '';
}
var ie = /msie|trident/i.test(ua)
, chrome = /chrome|crios|crmo/i.test(ua) , chrome = /chrome|crios|crmo/i.test(ua)
, phantom = /phantom/i.test(ua) , phantom = /phantom/i.test(ua)
, iphone = /iphone/i.test(ua)
, ipad = /ipad/i.test(ua)
, ipod = /ipod/i.test(ua) , ipod = /ipod/i.test(ua)
, iphone = !ipod && /iphone/i.test(ua)
, ipad = /ipad/i.test(ua)
, ios = iphone || ipad || ipod
, silk = /silk/i.test(ua) , silk = /silk/i.test(ua)
, safari = /safari/i.test(ua) && !chrome && !phantom && !silk , likeAndroid = /like android/i.test(ua)
, android = /android/i.test(ua) , android = !likeAndroid && /android/i.test(ua)
, opera = /opera/i.test(ua) || /opr/i.test(ua) , opera = /opera|opr/i.test(ua)
, firefox = /(firefox|iceweasel)/i.test(ua) , firefox = /firefox|iceweasel/i.test(ua)
, gecko = /gecko\//i.test(ua) , gecko = /gecko\//i.test(ua)
, seamonkey = /seamonkey\//i.test(ua) , seamonkey = /seamonkey\//i.test(ua)
, webos = /(?:web|hpw)os/i.test(ua) , webos = /(web|hpw)os/i.test(ua)
, touchpad = /touchpad\//i.test(ua) , touchpad = /touchpad\//i.test(ua)
, windowsphone = /windows phone/i.test(ua) , windowsphone = /windows phone/i.test(ua)
, blackberry = /(blackberry|\bbb\d+)/i.test(ua) , blackberry = /blackberry|\bbb\d+/i.test(ua)
, rimtablet = /rim\stablet/i.test(ua) , rimtablet = /rim\stablet/i.test(ua)
, bada = /bada/i.test(ua) , bada = /bada/i.test(ua)
, tizen = /tizen/i.test(ua) , tizen = /tizen/i.test(ua)
, webkitVersion = /version\/(\d+(\.\d+)?)/i , safari = /safari/i.test(ua)
, firefoxVersion = /(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i , webkit = /applewebkit/i.test(ua)
, versionIdentifier = getVersion(/version\/(\d+(\.\d+)?)/i)
, mobile = /mobi/i.test(ua) , mobile = /mobi/i.test(ua)
, tablet = /tablet/i.test(ua) , tablet = /tablet/i.test(ua)
, o = {} , result
if (ipod) iphone = false if (windowsphone) result = {
if (windowsphone) o = {
name: 'Windows Phone' name: 'Windows Phone'
, windowsphone: t , windowsphone: t
, msie: t , msie: t
, version: getVersion(ua, /iemobile\/(\d+(\.\d+)?)/i, 1) , version: getVersion(/iemobile\/(\d+(\.\d+)?)/i)
} }
else if (opera) { else if (opera) {
v = getVersion(ua, webkitVersion, 1) || result = {
getVersion(ua, /opr\/(\d+(\.\d+)?)/i, 1) ||
getVersion(ua, /opera[ \/](\d+(\.\d+)?)/i, 1);
o = {
name: 'Opera' name: 'Opera'
, opera: t , opera: t
, version: v , version: versionIdentifier ||
} getVersion(/opr\/(\d+(\.\d+)?)/i) ||
if (android) { getVersion(/opera[ \/](\d+(\.\d+)?)/i)
o.android = t
}
if (chrome) {
o.webkit = t
} }
} }
else if (ie) o = { else if (ie) result = {
name: 'Internet Explorer' name: 'Internet Explorer'
, msie: t , msie: t
, version: getVersion(ua, /(msie |rv:)(\d+(\.\d+)?)/i, 2) , version: getVersion(/(?:msie |rv:)(\d+(\.\d+)?)/i)
} }
else if (chrome) { else if (chrome) {
o = { result = {
name: 'Chrome' name: 'Chrome'
, webkit: t
, chrome: t , chrome: t
, version: getVersion(ua, /(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i, 1) , version: getVersion(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)
}
if (android) o.android = t
if (ipad || ipod || iphone) {
o[iphone ? 'iphone' : ipad ? 'ipad' : 'ipod'] = t
o.ios = t
} }
} }
else if (phantom) o = { else if (phantom) result = {
name: 'PhantomJS' name: 'PhantomJS'
, webkit: t
, phantom: t , phantom: t
, version: getVersion(ua, /phantomjs\/(\d+(\.\d+)?)/i, 1) , version: getVersion(/phantomjs\/(\d+(\.\d+)?)/i)
} }
else if (silk) o = { else if (silk) result = {
name: 'Amazon Silk' name: 'Amazon Silk'
, silk: t , silk: t
, webkit: t , version : getVersion(/silk\/(\d+(\.\d+)?)/i)
, android: t
, version : getVersion(ua, /silk\/(\d+(\.\d+)?)/i, 1)
} }
else if (iphone || ipad || ipod) { else if (ios) {
o = { result = {
name : iphone ? 'iPhone' : ipad ? 'iPad' : 'iPod' name : iphone ? 'iPhone' : ipad ? 'iPad' : 'iPod'
, webkit: t
, ios: t
} }
o[iphone ? 'iphone' : ipad ? 'ipad' : 'ipod'] = t
// WTF: version is not part of user agent in web apps // WTF: version is not part of user agent in web apps
if (webkitVersion.test(ua)) { if (versionIdentifier) {
o.version = getVersion(ua, webkitVersion, 1) result.version = versionIdentifier
} }
} }
else if (blackberry || rimtablet) { else if (blackberry || rimtablet) {
o = { result = {
name: 'BlackBerry' name: 'BlackBerry'
, blackberry: t , blackberry: t
} , version: versionIdentifier || getVersion(/blackberry[\d]+\/(\d+(\.\d+)?)/i)
if ((v = getVersion(ua, webkitVersion, 1))) {
o.version = v
o.webkit = t
} else {
o.version = getVersion(ua, /blackberry[\d]+\/(\d+(\.\d+)?)/i, 1)
} }
} }
else if (webos) { else if (webos) {
o = { result = {
name: 'WebOS' name: 'WebOS'
, webkit: t
, webos: t , webos: t
, version: (getVersion(ua, webkitVersion, 1) || getVersion(ua, /w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i, 1)) , version: versionIdentifier || getVersion(/w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i)
}; };
touchpad && (o.touchpad = t) touchpad && (result.touchpad = t)
} }
else if (bada) { else if (bada) {
o = { result = {
name: 'Bada' name: 'Bada'
, webkit: t
, bada: t , bada: t
, version: getVersion(ua, /dolfin\/(\d+(\.\d+)?)/i, 1) , version: getVersion(/dolfin\/(\d+(\.\d+)?)/i)
}; };
touchpad && (o.touchpad = t)
} }
else if (tizen) { else if (tizen) {
o = { result = {
name: 'Tizen' name: 'Tizen'
, webkit: t
, tizen: t , tizen: t
, version: getVersion(ua, /(?:tizen\s?)?browser\/(\d+(\.\d+)?)/i, 1) || getVersion(ua, webkitVersion, 1) , version: getVersion(/(?:tizen\s?)?browser\/(\d+(\.\d+)?)/i) || versionIdentifier
}; };
} }
else if (gecko) { else if (gecko) {
o = { result = {
name: 'Gecko' name: 'Gecko'
, gecko: t , gecko: t
, mozilla: t , mozilla: t
, version: getVersion(ua, firefoxVersion, 1) , version: getVersion(/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i)
} }
if (seamonkey) { if (seamonkey) {
o.name = 'SeaMonkey' result.name = 'SeaMonkey'
o.seamonkey = t result.seamonkey = t
o.version = getVersion(ua, /seamonkey\/(\d+(\.\d+)?)/i, 1) result.version = getVersion(/seamonkey\/(\d+(\.\d+)?)/i)
} else if (firefox) { } else if (firefox) {
o.name = 'Firefox' result.name = 'Firefox'
o.firefox = t result.firefox = t
} if (/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(ua)) {
if (android) { result.firefoxos = t
o.android = t
} else if (!android && firefox && /\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(ua)) {
o.firefoxos = t
} }
} }
else if (android) o = { }
else if (android) result = {
name: 'Android' name: 'Android'
, webkit: t , version: versionIdentifier
, android: t
, version: getVersion(ua, webkitVersion, 1)
} }
else if (safari) o = { else if (safari) result = {
name: 'Safari' name: 'Safari'
, webkit: t
, safari: t , safari: t
, version: getVersion(ua, webkitVersion, 1) , version: versionIdentifier
} }
else result = {}
// set OS flags for platforms that have multiple browsers
if (android || silk) {
result.android = t
} else if (ios) {
result[iphone ? 'iphone' : ipad ? 'ipad' : 'ipod'] = t
result.ios = t
}
if (webkit) {
result.webkit = t
}
// OS version extraction // OS version extraction
var osVersion; var osVersion;
if (tizen) { if (ios) {
osVersion = getVersion(ua, /tizen[\/\s](\d+(\.\d+)*)/i, 1); osVersion = getVersion(/os (\d+([_\s]\d+)*) like mac os x/i);
} else if (windowsphone) { osVersion = osVersion.replace(/[_\s]/g, '.');
osVersion = getVersion(ua, /windows phone (?:os)?\s?(\d+(\.\d+)*)/i, 1);
} else if (webos) {
osVersion = getVersion(ua, /(?:web|hpw)os\/(\d+(\.\d+)*)/i, 1);
} else if (rimtablet) {
osVersion = getVersion(ua, /rim\stablet\sos\s(\d+(\.\d+)*)/i, 1);
} else if (bada) {
osVersion = getVersion(ua, /bada\/(\d+(\.\d+)*)/i, 1);
} else if (iphone || ipad || ipod) {
osVersion = getVersion(ua, /os (\d+([_\s]\d+)*) like mac os x/i, 1);
osVersion = (osVersion || "").replace(/[_\s]/g, '.');
} else if (android) { } else if (android) {
osVersion = getVersion(ua, /android[ \/-](\d+(\.\d+)*)/i, 1); osVersion = getVersion(/android[ \/-](\d+(\.\d+)*)/i);
} else if (windowsphone) {
osVersion = getVersion(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i);
} else if (webos) {
osVersion = getVersion(/(?:web|hpw)os\/(\d+(\.\d+)*)/i);
} else if (rimtablet) {
osVersion = getVersion(/rim\stablet\sos\s(\d+(\.\d+)*)/i);
} else if (bada) {
osVersion = getVersion(/bada\/(\d+(\.\d+)*)/i);
} else if (tizen) {
osVersion = getVersion(/tizen[\/\s](\d+(\.\d+)*)/i);
} }
if (osVersion) { if (osVersion) {
o.osversion = osVersion; result.osversion = osVersion;
} }
// device type extraction // device type extraction
var osMajorVersion = (osVersion || '').split('.')[0]; var osMajorVersion = (osVersion || '').split('.')[0];
if (tablet || ipad || (android && (osMajorVersion == 3 || (osMajorVersion == 4 && !mobile))) || rimtablet || silk || touchpad) { if (tablet || ipad || (android && (osMajorVersion == 3 || (osMajorVersion == 4 && !mobile))) || rimtablet || silk || touchpad) {
o.tablet = t result.tablet = t
} else if (iphone || ipod || (android && mobile) || windowsphone || blackberry || webos || bada || tizen || mobile) { } else if (iphone || ipod || (android && mobile) || windowsphone || blackberry || webos || bada || tizen || mobile) {
o.mobile = t result.mobile = t
} }
// Graded Browser Support // Graded Browser Support
// http://developer.yahoo.com/yui/articles/gbs // http://developer.yahoo.com/yui/articles/gbs
if ((o.msie && o.version >= 9) || if ((result.msie && result.version >= 9) ||
(o.chrome && o.version >= 20) || (result.chrome && result.version >= 20) ||
(o.firefox && o.version >= 10.0) || (result.firefox && result.version >= 10.0) ||
(o.safari && o.version >= 5) || (result.safari && result.version >= 5) ||
(o.opera && o.version >= 10.0) || (result.opera && result.version >= 10.0) ||
(o.ios && o.osversion && o.osversion.split(".")[0] >= 6) (result.ios && result.osversion && result.osversion.split(".")[0] >= 6)
) { ) {
o.a = t; result.a = t;
} }
else if ((result.msie && result.version < 9) ||
else if ((o.msie && o.version < 9) || (result.chrome && result.version < 20) ||
(o.chrome && o.version < 20) || (result.firefox && result.version < 10.0) ||
(o.firefox && o.version < 10.0) || (result.safari && result.version < 5) ||
(o.safari && o.version < 5) || (result.opera && result.version < 10.0) ||
(o.opera && o.version < 10.0) || (result.ios && result.osversion && result.osversion.split(".")[0] < 6)
(o.ios && o.osversion && o.osversion.split(".")[0] < 6)
) { ) {
o.c = t result.c = t
} else o.x = t } else result.x = t
return o return result
} }
var bowser = detect(typeof navigator !== 'undefined' ? navigator.userAgent : '') var bowser = detect(typeof navigator !== 'undefined' ? navigator.userAgent : '')

2
bowser.min.js vendored
View File

@ -3,4 +3,4 @@
* https://github.com/ded/bowser * https://github.com/ded/bowser
* MIT License | (c) Dustin Diaz 2014 * MIT License | (c) Dustin Diaz 2014
*/ */
!function(e,t){typeof module!="undefined"&&module.exports?module.exports.browser=t():typeof define=="function"?define(t):this[e]=t()}("bowser",function(){function n(e,t,n){var r=e.match(t);return r&&r.length>n&&r[n]||0}function r(r){var i=/(msie|trident)/i.test(r),s=/chrome|crios|crmo/i.test(r),o=/phantom/i.test(r),u=/iphone/i.test(r),a=/ipad/i.test(r),f=/ipod/i.test(r),l=/silk/i.test(r),c=/safari/i.test(r)&&!s&&!o&&!l,h=/android/i.test(r),p=/opera/i.test(r)||/opr/i.test(r),d=/(firefox|iceweasel)/i.test(r),m=/gecko\//i.test(r),g=/seamonkey\//i.test(r),y=/(?:web|hpw)os/i.test(r),b=/touchpad\//i.test(r),w=/windows phone/i.test(r),E=/(blackberry|\bbb\d+)/i.test(r),S=/rim\stablet/i.test(r),x=/bada/i.test(r),T=/tizen/i.test(r),N=/version\/(\d+(\.\d+)?)/i,C=/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i,k=/mobi/i.test(r),L=/tablet/i.test(r),A={};f&&(u=!1);if(w)A={name:"Windows Phone",windowsphone:e,msie:e,version:n(r,/iemobile\/(\d+(\.\d+)?)/i,1)};else if(p)t=n(r,N,1)||n(r,/opr\/(\d+(\.\d+)?)/i,1)||n(r,/opera[ \/](\d+(\.\d+)?)/i,1),A={name:"Opera",opera:e,version:t},h&&(A.android=e),s&&(A.webkit=e);else if(i)A={name:"Internet Explorer",msie:e,version:n(r,/(msie |rv:)(\d+(\.\d+)?)/i,2)};else if(s){A={name:"Chrome",webkit:e,chrome:e,version:n(r,/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i,1)},h&&(A.android=e);if(a||f||u)A[u?"iphone":a?"ipad":"ipod"]=e,A.ios=e}else o?A={name:"PhantomJS",webkit:e,phantom:e,version:n(r,/phantomjs\/(\d+(\.\d+)?)/i,1)}:l?A={name:"Amazon Silk",silk:e,webkit:e,android:e,version:n(r,/silk\/(\d+(\.\d+)?)/i,1)}:u||a||f?(A={name:u?"iPhone":a?"iPad":"iPod",webkit:e,ios:e},A[u?"iphone":a?"ipad":"ipod"]=e,N.test(r)&&(A.version=n(r,N,1))):E||S?(A={name:"BlackBerry",blackberry:e},(t=n(r,N,1))?(A.version=t,A.webkit=e):A.version=n(r,/blackberry[\d]+\/(\d+(\.\d+)?)/i,1)):y?(A={name:"WebOS",webkit:e,webos:e,version:n(r,N,1)||n(r,/w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i,1)},b&&(A.touchpad=e)):x?(A={name:"Bada",webkit:e,bada:e,version:n(r,/dolfin\/(\d+(\.\d+)?)/i,1)},b&&(A.touchpad=e)):T?A={name:"Tizen",webkit:e,tizen:e,version:n(r,/(?:tizen\s?)?browser\/(\d+(\.\d+)?)/i,1)||n(r,N,1)}:m?(A={name:"Gecko",gecko:e,mozilla:e,version:n(r,C,1)},g?(A.name="SeaMonkey",A.seamonkey=e,A.version=n(r,/seamonkey\/(\d+(\.\d+)?)/i,1)):d&&(A.name="Firefox",A.firefox=e),h?A.android=e:!h&&d&&/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(r)&&(A.firefoxos=e)):h?A={name:"Android",webkit:e,android:e,version:n(r,N,1)}:c&&(A={name:"Safari",webkit:e,safari:e,version:n(r,N,1)});var O;T?O=n(r,/tizen[\/\s](\d+(\.\d+)*)/i,1):w?O=n(r,/windows phone (?:os)?\s?(\d+(\.\d+)*)/i,1):y?O=n(r,/(?:web|hpw)os\/(\d+(\.\d+)*)/i,1):S?O=n(r,/rim\stablet\sos\s(\d+(\.\d+)*)/i,1):x?O=n(r,/bada\/(\d+(\.\d+)*)/i,1):u||a||f?(O=n(r,/os (\d+([_\s]\d+)*) like mac os x/i,1),O=(O||"").replace(/[_\s]/g,".")):h&&(O=n(r,/android[ \/-](\d+(\.\d+)*)/i,1)),O&&(A.osversion=O);var M=(O||"").split(".")[0];if(L||a||h&&(M==3||M==4&&!k)||S||l||b)A.tablet=e;else if(u||f||h&&k||w||E||y||x||T||k)A.mobile=e;return A.msie&&A.version>=9||A.chrome&&A.version>=20||A.firefox&&A.version>=10||A.safari&&A.version>=5||A.opera&&A.version>=10||A.ios&&A.osversion&&A.osversion.split(".")[0]>=6?A.a=e:A.msie&&A.version<9||A.chrome&&A.version<20||A.firefox&&A.version<10||A.safari&&A.version<5||A.opera&&A.version<10||A.ios&&A.osversion&&A.osversion.split(".")[0]<6?A.c=e:A.x=e,A}var e=!0,t,i=r(typeof navigator!="undefined"?navigator.userAgent:"");return i._detect=r,i}) !function(e,t){typeof module!="undefined"&&module.exports?module.exports.browser=t():typeof define=="function"?define(t):this[e]=t()}("bowser",function(){function t(t){function n(e){var n=t.match(e);return n&&n.length>1&&n[1]||""}var r=/msie|trident/i.test(t),i=/chrome|crios|crmo/i.test(t),s=/phantom/i.test(t),o=/ipod/i.test(t),u=!o&&/iphone/i.test(t),a=/ipad/i.test(t),f=u||a||o,l=/silk/i.test(t),c=/like android/i.test(t),h=!c&&/android/i.test(t),p=/opera|opr/i.test(t),d=/firefox|iceweasel/i.test(t),v=/gecko\//i.test(t),m=/seamonkey\//i.test(t),g=/(web|hpw)os/i.test(t),y=/touchpad\//i.test(t),b=/windows phone/i.test(t),w=/blackberry|\bbb\d+/i.test(t),E=/rim\stablet/i.test(t),S=/bada/i.test(t),x=/tizen/i.test(t),T=/safari/i.test(t),N=/applewebkit/i.test(t),C=n(/version\/(\d+(\.\d+)?)/i),k=/mobi/i.test(t),L=/tablet/i.test(t),A;b?A={name:"Windows Phone",windowsphone:e,msie:e,version:n(/iemobile\/(\d+(\.\d+)?)/i)}:p?A={name:"Opera",opera:e,version:C||n(/opr\/(\d+(\.\d+)?)/i)||n(/opera[ \/](\d+(\.\d+)?)/i)}:r?A={name:"Internet Explorer",msie:e,version:n(/(?:msie |rv:)(\d+(\.\d+)?)/i)}:i?A={name:"Chrome",chrome:e,version:n(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)}:s?A={name:"PhantomJS",phantom:e,version:n(/phantomjs\/(\d+(\.\d+)?)/i)}:l?A={name:"Amazon Silk",silk:e,version:n(/silk\/(\d+(\.\d+)?)/i)}:f?(A={name:u?"iPhone":a?"iPad":"iPod"},C&&(A.version=C)):w||E?A={name:"BlackBerry",blackberry:e,version:C||n(/blackberry[\d]+\/(\d+(\.\d+)?)/i)}:g?(A={name:"WebOS",webos:e,version:C||n(/w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i)},y&&(A.touchpad=e)):S?A={name:"Bada",bada:e,version:n(/dolfin\/(\d+(\.\d+)?)/i)}:x?A={name:"Tizen",tizen:e,version:n(/(?:tizen\s?)?browser\/(\d+(\.\d+)?)/i)||C}:v?(A={name:"Gecko",gecko:e,mozilla:e,version:n(/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i)},m?(A.name="SeaMonkey",A.seamonkey=e,A.version=n(/seamonkey\/(\d+(\.\d+)?)/i)):d&&(A.name="Firefox",A.firefox=e,/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(t)&&(A.firefoxos=e))):h?A={name:"Android",version:C}:T?A={name:"Safari",safari:e,version:C}:A={},h||l?A.android=e:f&&(A[u?"iphone":a?"ipad":"ipod"]=e,A.ios=e),N&&(A.webkit=e);var O;f?(O=n(/os (\d+([_\s]\d+)*) like mac os x/i),O=O.replace(/[_\s]/g,".")):h?O=n(/android[ \/-](\d+(\.\d+)*)/i):b?O=n(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i):g?O=n(/(?:web|hpw)os\/(\d+(\.\d+)*)/i):E?O=n(/rim\stablet\sos\s(\d+(\.\d+)*)/i):S?O=n(/bada\/(\d+(\.\d+)*)/i):x&&(O=n(/tizen[\/\s](\d+(\.\d+)*)/i)),O&&(A.osversion=O);var M=(O||"").split(".")[0];if(L||a||h&&(M==3||M==4&&!k)||E||l||y)A.tablet=e;else if(u||o||h&&k||b||w||g||S||x||k)A.mobile=e;return A.msie&&A.version>=9||A.chrome&&A.version>=20||A.firefox&&A.version>=10||A.safari&&A.version>=5||A.opera&&A.version>=10||A.ios&&A.osversion&&A.osversion.split(".")[0]>=6?A.a=e:A.msie&&A.version<9||A.chrome&&A.version<20||A.firefox&&A.version<10||A.safari&&A.version<5||A.opera&&A.version<10||A.ios&&A.osversion&&A.osversion.split(".")[0]<6?A.c=e:A.x=e,A}var e=!0,n=t(typeof navigator!="undefined"?navigator.userAgent:"");return n._detect=t,n})

View File

@ -21,5 +21,6 @@ require('smoosh').config({
, "asi": true , "asi": true
, "laxbreak": true , "laxbreak": true
, "laxcomma": true , "laxcomma": true
, "eqnull": true
} }
}).run().build().analyze() }).run().build().analyze()

View File

@ -7,235 +7,211 @@
* See useragents.js for examples of navigator.userAgent * See useragents.js for examples of navigator.userAgent
*/ */
var t = true, var t = true
v /* temporary placeholder for versions. */
function getVersion(ua, regex, matchedIdx) {
var match = ua.match(regex);
return (match && match.length > matchedIdx && match[matchedIdx]) || 0;
}
function detect(ua) { function detect(ua) {
var ie = /(msie|trident)/i.test(ua) function getVersion(regex) {
var match = ua.match(regex);
return (match && match.length > 1 && match[1]) || '';
}
var ie = /msie|trident/i.test(ua)
, chrome = /chrome|crios|crmo/i.test(ua) , chrome = /chrome|crios|crmo/i.test(ua)
, phantom = /phantom/i.test(ua) , phantom = /phantom/i.test(ua)
, iphone = /iphone/i.test(ua)
, ipad = /ipad/i.test(ua)
, ipod = /ipod/i.test(ua) , ipod = /ipod/i.test(ua)
, iphone = !ipod && /iphone/i.test(ua)
, ipad = /ipad/i.test(ua)
, ios = iphone || ipad || ipod
, silk = /silk/i.test(ua) , silk = /silk/i.test(ua)
, safari = /safari/i.test(ua) && !chrome && !phantom && !silk , likeAndroid = /like android/i.test(ua)
, android = /android/i.test(ua) , android = !likeAndroid && /android/i.test(ua)
, opera = /opera/i.test(ua) || /opr/i.test(ua) , opera = /opera|opr/i.test(ua)
, firefox = /(firefox|iceweasel)/i.test(ua) , firefox = /firefox|iceweasel/i.test(ua)
, gecko = /gecko\//i.test(ua) , gecko = /gecko\//i.test(ua)
, seamonkey = /seamonkey\//i.test(ua) , seamonkey = /seamonkey\//i.test(ua)
, webos = /(?:web|hpw)os/i.test(ua) , webos = /(web|hpw)os/i.test(ua)
, touchpad = /touchpad\//i.test(ua) , touchpad = /touchpad\//i.test(ua)
, windowsphone = /windows phone/i.test(ua) , windowsphone = /windows phone/i.test(ua)
, blackberry = /(blackberry|\bbb\d+)/i.test(ua) , blackberry = /blackberry|\bbb\d+/i.test(ua)
, rimtablet = /rim\stablet/i.test(ua) , rimtablet = /rim\stablet/i.test(ua)
, bada = /bada/i.test(ua) , bada = /bada/i.test(ua)
, tizen = /tizen/i.test(ua) , tizen = /tizen/i.test(ua)
, webkitVersion = /version\/(\d+(\.\d+)?)/i , safari = /safari/i.test(ua)
, firefoxVersion = /(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i , webkit = /applewebkit/i.test(ua)
, versionIdentifier = getVersion(/version\/(\d+(\.\d+)?)/i)
, mobile = /mobi/i.test(ua) , mobile = /mobi/i.test(ua)
, tablet = /tablet/i.test(ua) , tablet = /tablet/i.test(ua)
, o = {} , result
if (ipod) iphone = false if (windowsphone) result = {
if (windowsphone) o = {
name: 'Windows Phone' name: 'Windows Phone'
, windowsphone: t , windowsphone: t
, msie: t , msie: t
, version: getVersion(ua, /iemobile\/(\d+(\.\d+)?)/i, 1) , version: getVersion(/iemobile\/(\d+(\.\d+)?)/i)
} }
else if (opera) { else if (opera) {
v = getVersion(ua, webkitVersion, 1) || result = {
getVersion(ua, /opr\/(\d+(\.\d+)?)/i, 1) ||
getVersion(ua, /opera[ \/](\d+(\.\d+)?)/i, 1);
o = {
name: 'Opera' name: 'Opera'
, opera: t , opera: t
, version: v , version: versionIdentifier ||
} getVersion(/opr\/(\d+(\.\d+)?)/i) ||
if (android) { getVersion(/opera[ \/](\d+(\.\d+)?)/i)
o.android = t
}
if (chrome) {
o.webkit = t
} }
} }
else if (ie) o = { else if (ie) result = {
name: 'Internet Explorer' name: 'Internet Explorer'
, msie: t , msie: t
, version: getVersion(ua, /(msie |rv:)(\d+(\.\d+)?)/i, 2) , version: getVersion(/(?:msie |rv:)(\d+(\.\d+)?)/i)
} }
else if (chrome) { else if (chrome) {
o = { result = {
name: 'Chrome' name: 'Chrome'
, webkit: t
, chrome: t , chrome: t
, version: getVersion(ua, /(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i, 1) , version: getVersion(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)
}
if (android) o.android = t
if (ipad || ipod || iphone) {
o[iphone ? 'iphone' : ipad ? 'ipad' : 'ipod'] = t
o.ios = t
} }
} }
else if (phantom) o = { else if (phantom) result = {
name: 'PhantomJS' name: 'PhantomJS'
, webkit: t
, phantom: t , phantom: t
, version: getVersion(ua, /phantomjs\/(\d+(\.\d+)?)/i, 1) , version: getVersion(/phantomjs\/(\d+(\.\d+)?)/i)
} }
else if (silk) o = { else if (silk) result = {
name: 'Amazon Silk' name: 'Amazon Silk'
, silk: t , silk: t
, webkit: t , version : getVersion(/silk\/(\d+(\.\d+)?)/i)
, android: t
, version : getVersion(ua, /silk\/(\d+(\.\d+)?)/i, 1)
} }
else if (iphone || ipad || ipod) { else if (ios) {
o = { result = {
name : iphone ? 'iPhone' : ipad ? 'iPad' : 'iPod' name : iphone ? 'iPhone' : ipad ? 'iPad' : 'iPod'
, webkit: t
, ios: t
} }
o[iphone ? 'iphone' : ipad ? 'ipad' : 'ipod'] = t
// WTF: version is not part of user agent in web apps // WTF: version is not part of user agent in web apps
if (webkitVersion.test(ua)) { if (versionIdentifier) {
o.version = getVersion(ua, webkitVersion, 1) result.version = versionIdentifier
} }
} }
else if (blackberry || rimtablet) { else if (blackberry || rimtablet) {
o = { result = {
name: 'BlackBerry' name: 'BlackBerry'
, blackberry: t , blackberry: t
} , version: versionIdentifier || getVersion(/blackberry[\d]+\/(\d+(\.\d+)?)/i)
if ((v = getVersion(ua, webkitVersion, 1))) {
o.version = v
o.webkit = t
} else {
o.version = getVersion(ua, /blackberry[\d]+\/(\d+(\.\d+)?)/i, 1)
} }
} }
else if (webos) { else if (webos) {
o = { result = {
name: 'WebOS' name: 'WebOS'
, webkit: t
, webos: t , webos: t
, version: (getVersion(ua, webkitVersion, 1) || getVersion(ua, /w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i, 1)) , version: versionIdentifier || getVersion(/w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i)
}; };
touchpad && (o.touchpad = t) touchpad && (result.touchpad = t)
} }
else if (bada) { else if (bada) {
o = { result = {
name: 'Bada' name: 'Bada'
, webkit: t
, bada: t , bada: t
, version: getVersion(ua, /dolfin\/(\d+(\.\d+)?)/i, 1) , version: getVersion(/dolfin\/(\d+(\.\d+)?)/i)
}; };
touchpad && (o.touchpad = t)
} }
else if (tizen) { else if (tizen) {
o = { result = {
name: 'Tizen' name: 'Tizen'
, webkit: t
, tizen: t , tizen: t
, version: getVersion(ua, /(?:tizen\s?)?browser\/(\d+(\.\d+)?)/i, 1) || getVersion(ua, webkitVersion, 1) , version: getVersion(/(?:tizen\s?)?browser\/(\d+(\.\d+)?)/i) || versionIdentifier
}; };
} }
else if (gecko) { else if (gecko) {
o = { result = {
name: 'Gecko' name: 'Gecko'
, gecko: t , gecko: t
, mozilla: t , mozilla: t
, version: getVersion(ua, firefoxVersion, 1) , version: getVersion(/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i)
} }
if (seamonkey) { if (seamonkey) {
o.name = 'SeaMonkey' result.name = 'SeaMonkey'
o.seamonkey = t result.seamonkey = t
o.version = getVersion(ua, /seamonkey\/(\d+(\.\d+)?)/i, 1) result.version = getVersion(/seamonkey\/(\d+(\.\d+)?)/i)
} else if (firefox) { } else if (firefox) {
o.name = 'Firefox' result.name = 'Firefox'
o.firefox = t result.firefox = t
} if (/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(ua)) {
if (android) { result.firefoxos = t
o.android = t
} else if (!android && firefox && /\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(ua)) {
o.firefoxos = t
} }
} }
else if (android) o = { }
else if (android) result = {
name: 'Android' name: 'Android'
, webkit: t , version: versionIdentifier
, android: t
, version: getVersion(ua, webkitVersion, 1)
} }
else if (safari) o = { else if (safari) result = {
name: 'Safari' name: 'Safari'
, webkit: t
, safari: t , safari: t
, version: getVersion(ua, webkitVersion, 1) , version: versionIdentifier
} }
else result = {}
// set OS flags for platforms that have multiple browsers
if (android || silk) {
result.android = t
} else if (ios) {
result[iphone ? 'iphone' : ipad ? 'ipad' : 'ipod'] = t
result.ios = t
}
if (webkit) {
result.webkit = t
}
// OS version extraction // OS version extraction
var osVersion; var osVersion;
if (tizen) { if (ios) {
osVersion = getVersion(ua, /tizen[\/\s](\d+(\.\d+)*)/i, 1); osVersion = getVersion(/os (\d+([_\s]\d+)*) like mac os x/i);
} else if (windowsphone) { osVersion = osVersion.replace(/[_\s]/g, '.');
osVersion = getVersion(ua, /windows phone (?:os)?\s?(\d+(\.\d+)*)/i, 1);
} else if (webos) {
osVersion = getVersion(ua, /(?:web|hpw)os\/(\d+(\.\d+)*)/i, 1);
} else if (rimtablet) {
osVersion = getVersion(ua, /rim\stablet\sos\s(\d+(\.\d+)*)/i, 1);
} else if (bada) {
osVersion = getVersion(ua, /bada\/(\d+(\.\d+)*)/i, 1);
} else if (iphone || ipad || ipod) {
osVersion = getVersion(ua, /os (\d+([_\s]\d+)*) like mac os x/i, 1);
osVersion = (osVersion || "").replace(/[_\s]/g, '.');
} else if (android) { } else if (android) {
osVersion = getVersion(ua, /android[ \/-](\d+(\.\d+)*)/i, 1); osVersion = getVersion(/android[ \/-](\d+(\.\d+)*)/i);
} else if (windowsphone) {
osVersion = getVersion(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i);
} else if (webos) {
osVersion = getVersion(/(?:web|hpw)os\/(\d+(\.\d+)*)/i);
} else if (rimtablet) {
osVersion = getVersion(/rim\stablet\sos\s(\d+(\.\d+)*)/i);
} else if (bada) {
osVersion = getVersion(/bada\/(\d+(\.\d+)*)/i);
} else if (tizen) {
osVersion = getVersion(/tizen[\/\s](\d+(\.\d+)*)/i);
} }
if (osVersion) { if (osVersion) {
o.osversion = osVersion; result.osversion = osVersion;
} }
// device type extraction // device type extraction
var osMajorVersion = (osVersion || '').split('.')[0]; var osMajorVersion = (osVersion || '').split('.')[0];
if (tablet || ipad || (android && (osMajorVersion == 3 || (osMajorVersion == 4 && !mobile))) || rimtablet || silk || touchpad) { if (tablet || ipad || (android && (osMajorVersion == 3 || (osMajorVersion == 4 && !mobile))) || rimtablet || silk || touchpad) {
o.tablet = t result.tablet = t
} else if (iphone || ipod || (android && mobile) || windowsphone || blackberry || webos || bada || tizen || mobile) { } else if (iphone || ipod || (android && mobile) || windowsphone || blackberry || webos || bada || tizen || mobile) {
o.mobile = t result.mobile = t
} }
// Graded Browser Support // Graded Browser Support
// http://developer.yahoo.com/yui/articles/gbs // http://developer.yahoo.com/yui/articles/gbs
if ((o.msie && o.version >= 9) || if ((result.msie && result.version >= 9) ||
(o.chrome && o.version >= 20) || (result.chrome && result.version >= 20) ||
(o.firefox && o.version >= 10.0) || (result.firefox && result.version >= 10.0) ||
(o.safari && o.version >= 5) || (result.safari && result.version >= 5) ||
(o.opera && o.version >= 10.0) || (result.opera && result.version >= 10.0) ||
(o.ios && o.osversion && o.osversion.split(".")[0] >= 6) (result.ios && result.osversion && result.osversion.split(".")[0] >= 6)
) { ) {
o.a = t; result.a = t;
} }
else if ((result.msie && result.version < 9) ||
else if ((o.msie && o.version < 9) || (result.chrome && result.version < 20) ||
(o.chrome && o.version < 20) || (result.firefox && result.version < 10.0) ||
(o.firefox && o.version < 10.0) || (result.safari && result.version < 5) ||
(o.safari && o.version < 5) || (result.opera && result.version < 10.0) ||
(o.opera && o.version < 10.0) || (result.ios && result.osversion && result.osversion.split(".")[0] < 6)
(o.ios && o.osversion && o.osversion.split(".")[0] < 6)
) { ) {
o.c = t result.c = t
} else o.x = t } else result.x = t
return o return result
} }
var bowser = detect(typeof navigator !== 'undefined' ? navigator.userAgent : '') var bowser = detect(typeof navigator !== 'undefined' ? navigator.userAgent : '')