mirror of
https://github.com/lancedikson/bowser
synced 2024-10-27 20:34:22 +00:00
Further minifications and bugfixes.
This commit is contained in:
parent
c9ee5e4efe
commit
5376cc67dc
93
bowser.js
93
bowser.js
@ -55,6 +55,30 @@
|
||||
/** @const */
|
||||
var STR_FIREFOX = 'firefox';
|
||||
|
||||
/** @const */
|
||||
var STR_BLACKBERRY = 'blackberry';
|
||||
|
||||
/** @const */
|
||||
var STR_WEBOS = 'webos';
|
||||
|
||||
/** @const */
|
||||
var STR_GECKO = 'gecko';
|
||||
|
||||
/** @const */
|
||||
var STR_ANDROID = 'android';
|
||||
|
||||
/** @const */
|
||||
var STR_TOUCHPAD = 'touchpad';
|
||||
|
||||
/** @const */
|
||||
var STR_IPHONE = 'iphone';
|
||||
|
||||
/** @const */
|
||||
var STR_IPAD = 'ipad';
|
||||
|
||||
/** @const */
|
||||
var STR_IPOD = 'ipod';
|
||||
|
||||
|
||||
function detect(ua) {
|
||||
/**
|
||||
@ -63,8 +87,8 @@
|
||||
* @param {RegExp} regex
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function uaTest(regex) {
|
||||
return regex.test(ua);
|
||||
function uaTest(test) {
|
||||
return new RegExp(test, 'i').test(ua);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,69 +103,82 @@
|
||||
return match ? match[i || 1] : 0;
|
||||
}
|
||||
|
||||
var iphone = uaTest(/iphone/i)
|
||||
, ipad = uaTest(/ipad/i)
|
||||
, ipod = uaTest(/ipod/i)
|
||||
var iphone = uaTest(STR_IPHONE)
|
||||
, ipad = uaTest(STR_IPAD)
|
||||
, ipod = uaTest(STR_IPOD)
|
||||
, webkitVersion = versionTest(STR_VERSION + '\/')
|
||||
, firefoxVersion = versionTest(STR_FIREFOX + '[\/ ]')
|
||||
, o = {}
|
||||
, version = 0;
|
||||
|
||||
if (uaTest(/windows phone/i)) {
|
||||
if (uaTest('windows phone')) {
|
||||
o.windowsphone = o[STR_MOBILE] = TRUE;
|
||||
o[STR_VERSION] = versionTest('iemobile\/');
|
||||
} else if (uaTest(/opera/i) || uaTest(/opr/i)) {
|
||||
|
||||
} else if (uaTest(STR_OPERA) || uaTest('opr')) {
|
||||
o[STR_OPERA] = TRUE;
|
||||
o[STR_VERSION] = webkitVersion || versionTest('opr\/') || versionTest('opera[ \/]');
|
||||
} else if (uaTest(/(msie|trident)/i)) {
|
||||
|
||||
} else if (uaTest('(msie|trident)')) {
|
||||
o[STR_MSIE] = TRUE;
|
||||
o[STR_VERSION] = versionTest('(msie |rv:)', 2);
|
||||
} else if (uaTest(/chrome/i)) {
|
||||
|
||||
} else if (uaTest(STR_CHROME)) {
|
||||
o[STR_CHROME] = o[STR_WEBKIT] = TRUE;
|
||||
o[STR_VERSION] = versionTest(STR_CHROME + '\/');
|
||||
} else if (uaTest(/phantom/i)) {
|
||||
|
||||
} else if (uaTest('phantom')) {
|
||||
o.phantom = o[STR_WEBKIT] = TRUE;
|
||||
o[STR_VERSION] = versionTest('phantomjs\/');
|
||||
} else if (uaTest(/touchpad/i)) {
|
||||
o.touchpad = o[STR_WEBKIT] = TRUE;
|
||||
o[STR_VERSION] = versionTest('touchpad\/');
|
||||
|
||||
} else if (uaTest(STR_TOUCHPAD)) {
|
||||
o[STR_TOUCHPAD] = o[STR_WEBKIT] = TRUE;
|
||||
o[STR_VERSION] = versionTest(STR_TOUCHPAD + '\/');
|
||||
|
||||
} else if (iphone || ipad || ipod) {
|
||||
o.ios = o[STR_MOBILE] = o[STR_WEBKIT] = TRUE;
|
||||
// CAUTION: version is not part of user agent in web apps
|
||||
o[STR_VERSION] = webkitVersion;
|
||||
if (ipod) {
|
||||
o.ipod = TRUE;
|
||||
o[STR_IPOD] = TRUE;
|
||||
} else if (iphone) {
|
||||
o.iphone = TRUE;
|
||||
o[STR_IPHONE] = TRUE;
|
||||
} else if (ipad) {
|
||||
o.ipad = TRUE;
|
||||
o[STR_IPAD] = TRUE;
|
||||
}
|
||||
} else if (uaTest(/blackberry/i)) {
|
||||
o.blackberry = o[STR_MOBILE] = TRUE;
|
||||
|
||||
} else if (uaTest(STR_BLACKBERRY)) {
|
||||
o[STR_BLACKBERRY] = o[STR_MOBILE] = TRUE;
|
||||
if (webkitVersion) {
|
||||
o[STR_WEBKIT] = TRUE;
|
||||
o[STR_VERSION] = webkitVersion;
|
||||
} else {
|
||||
o[STR_VERSION] = versionTest('blackberry[\\d]+\/');
|
||||
o[STR_VERSION] = versionTest(STR_BLACKBERRY + '[\\d]+\/');
|
||||
}
|
||||
} else if (uaTest(/webos/i)) {
|
||||
o.webos = o[STR_MOBILE] = o[STR_WEBKIT] = TRUE;
|
||||
|
||||
} else if (uaTest(STR_WEBOS)) {
|
||||
o[STR_WEBOS] = o[STR_MOBILE] = o[STR_WEBKIT] = TRUE;
|
||||
o[STR_VERSION] = webkitVersion || versionTest('wosbrowser\/');
|
||||
} else if (uaTest(/android/i)) {
|
||||
o.android = o[STR_MOBILE] = o[STR_WEBKIT] = TRUE;
|
||||
|
||||
} else if (uaTest(STR_ANDROID)) {
|
||||
o[STR_ANDROID] = o[STR_MOBILE] = o[STR_WEBKIT] = TRUE;
|
||||
o[STR_VERSION] = webkitVersion || firefoxVersion;
|
||||
} else if (uaTest(/safari/i)) {
|
||||
|
||||
} else if (uaTest(STR_SAFARI)) {
|
||||
o[STR_SAFARI] = o[STR_WEBKIT] = TRUE;
|
||||
o[STR_VERSION] = webkitVersion;
|
||||
} else if (uaTest(/gecko\//i)) {
|
||||
o.gecko = o.mozilla = TRUE;
|
||||
|
||||
} else if (uaTest(STR_GECKO)) {
|
||||
o[STR_GECKO] = o.mozilla = TRUE;
|
||||
o[STR_VERSION] = firefoxVersion;
|
||||
if (uaTest(/firefox/i)) {
|
||||
if (uaTest(STR_FIREFOX)) {
|
||||
o.firefox = TRUE;
|
||||
}
|
||||
} else if (uaTest(/seamonkey\//i)) {
|
||||
|
||||
} else if (uaTest('seamonkey\/')) {
|
||||
o.seamonkey = TRUE;
|
||||
o[STR_VERSION] = versionTest('seamonkey\/');
|
||||
|
||||
} else {
|
||||
o[STR_VERSION] = 0;
|
||||
}
|
||||
|
2
bowser.min.js
vendored
2
bowser.min.js
vendored
@ -3,4 +3,4 @@
|
||||
* https://github.com/ded/bowser
|
||||
* MIT License | (c) Dustin Diaz 2013
|
||||
*/
|
||||
!function(e,t){typeof define=="function"?define(t):typeof module!="undefined"&&module.exports?module.exports[e]=t():this[e]=t()}("bowser",function(){function f(f){function l(e){return e.test(f)}function c(e,t){var n=f.match(new RegExp(e+"(\\d+(\\.\\d+)?)","i"));return n?n[t||1]:0}var h=l(/iphone/i),p=l(/ipad/i),d=l(/ipod/i),v=c(t+"/"),m=c(a+"[/ ]"),g={},y=0;return l(/windows phone/i)?(g.windowsphone=g[n]=e,g[t]=c("iemobile/")):l(/opera/i)||l(/opr/i)?(g[i]=e,g[t]=v||c("opr/")||c("opera[ /]")):l(/(msie|trident)/i)?(g[r]=e,g[t]=c("(msie |rv:)",2)):l(/chrome/i)?(g[s]=g[o]=e,g[t]=c(s+"/")):l(/phantom/i)?(g.phantom=g[o]=e,g[t]=c("phantomjs/")):l(/touchpad/i)?(g.touchpad=g[o]=e,g[t]=c("touchpad/")):h||p||d?(g.ios=g[n]=g[o]=e,g[t]=v,d?g.ipod=e:h?g.iphone=e:p&&(g.ipad=e)):l(/blackberry/i)?(g.blackberry=g[n]=e,v?(g[o]=e,g[t]=v):g[t]=c("blackberry[\\d]+/")):l(/webos/i)?(g.webos=g[n]=g[o]=e,g[t]=v||c("wosbrowser/")):l(/android/i)?(g.android=g[n]=g[o]=e,g[t]=v||m):l(/safari/i)?(g[u]=g[o]=e,g[t]=v):l(/gecko\//i)?(g.gecko=g.mozilla=e,g[t]=m,l(/firefox/i)&&(g.firefox=e)):l(/seamonkey\//i)?(g.seamonkey=e,g[t]=c("seamonkey/")):g[t]=0,y=g[t],g[r]&&y>=8||g[s]&&y>=10||g[a]&&y>=4||g[u]&&y>=5||g[i]&&y>=10?g.a=e:g[r]&&y<8||g[s]&&y<10||g[a]&&y<4||g[u]&&y<5||g[i]&&y<10?g.c=e:g.x=e,g}var e=!0,t="version",n="mobile",r="msie",i="opera",s="chrome",o="webkit",u="safari",a="firefox",l=f(typeof navigator!="undefined"?navigator.userAgent:"");return l._detect=f,l})
|
||||
!function(e,t){typeof define=="function"?define(t):typeof module!="undefined"&&module.exports?module.exports[e]=t():this[e]=t()}("bowser",function(){function g(g){function y(e){return(new RegExp(e,"i")).test(g)}function b(e,t){var n=g.match(new RegExp(e+"(\\d+(\\.\\d+)?)","i"));return n?n[t||1]:0}var w=y(d),E=y(v),S=y(m),x=b(t+"/"),T=b(a+"[/ ]"),N={},C=0;return y("windows phone")?(N.windowsphone=N[n]=e,N[t]=b("iemobile/")):y(i)||y("opr")?(N[i]=e,N[t]=x||b("opr/")||b("opera[ /]")):y("(msie|trident)")?(N[r]=e,N[t]=b("(msie |rv:)",2)):y(s)?(N[s]=N[o]=e,N[t]=b(s+"/")):y("phantom")?(N.phantom=N[o]=e,N[t]=b("phantomjs/")):y(p)?(N[p]=N[o]=e,N[t]=b(p+"/")):w||E||S?(N.ios=N[n]=N[o]=e,N[t]=x,S?N[m]=e:w?N[d]=e:E&&(N[v]=e)):y(f)?(N[f]=N[n]=e,x?(N[o]=e,N[t]=x):N[t]=b(f+"[\\d]+/")):y(l)?(N[l]=N[n]=N[o]=e,N[t]=x||b("wosbrowser/")):y(h)?(N[h]=N[n]=N[o]=e,N[t]=x||T):y(u)?(N[u]=N[o]=e,N[t]=x):y(c)?(N[c]=N.mozilla=e,N[t]=T,y(a)&&(N.firefox=e)):y("seamonkey/")?(N.seamonkey=e,N[t]=b("seamonkey/")):N[t]=0,C=N[t],N[r]&&C>=8||N[s]&&C>=10||N[a]&&C>=4||N[u]&&C>=5||N[i]&&C>=10?N.a=e:N[r]&&C<8||N[s]&&C<10||N[a]&&C<4||N[u]&&C<5||N[i]&&C<10?N.c=e:N.x=e,N}var e=!0,t="version",n="mobile",r="msie",i="opera",s="chrome",o="webkit",u="safari",a="firefox",f="blackberry",l="webos",c="gecko",h="android",p="touchpad",d="iphone",v="ipad",m="ipod",y=g(typeof navigator!="undefined"?navigator.userAgent:"");return y._detect=g,y})
|
@ -49,6 +49,30 @@
|
||||
/** @const */
|
||||
var STR_FIREFOX = 'firefox';
|
||||
|
||||
/** @const */
|
||||
var STR_BLACKBERRY = 'blackberry';
|
||||
|
||||
/** @const */
|
||||
var STR_WEBOS = 'webos';
|
||||
|
||||
/** @const */
|
||||
var STR_GECKO = 'gecko';
|
||||
|
||||
/** @const */
|
||||
var STR_ANDROID = 'android';
|
||||
|
||||
/** @const */
|
||||
var STR_TOUCHPAD = 'touchpad';
|
||||
|
||||
/** @const */
|
||||
var STR_IPHONE = 'iphone';
|
||||
|
||||
/** @const */
|
||||
var STR_IPAD = 'ipad';
|
||||
|
||||
/** @const */
|
||||
var STR_IPOD = 'ipod';
|
||||
|
||||
|
||||
function detect(ua) {
|
||||
/**
|
||||
@ -57,8 +81,8 @@
|
||||
* @param {RegExp} regex
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function uaTest(regex) {
|
||||
return regex.test(ua);
|
||||
function uaTest(test) {
|
||||
return new RegExp(test, 'i').test(ua);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,69 +97,82 @@
|
||||
return match ? match[i || 1] : 0;
|
||||
}
|
||||
|
||||
var iphone = uaTest(/iphone/i)
|
||||
, ipad = uaTest(/ipad/i)
|
||||
, ipod = uaTest(/ipod/i)
|
||||
var iphone = uaTest(STR_IPHONE)
|
||||
, ipad = uaTest(STR_IPAD)
|
||||
, ipod = uaTest(STR_IPOD)
|
||||
, webkitVersion = versionTest(STR_VERSION + '\/')
|
||||
, firefoxVersion = versionTest(STR_FIREFOX + '[\/ ]')
|
||||
, o = {}
|
||||
, version = 0;
|
||||
|
||||
if (uaTest(/windows phone/i)) {
|
||||
if (uaTest('windows phone')) {
|
||||
o.windowsphone = o[STR_MOBILE] = TRUE;
|
||||
o[STR_VERSION] = versionTest('iemobile\/');
|
||||
} else if (uaTest(/opera/i) || uaTest(/opr/i)) {
|
||||
|
||||
} else if (uaTest(STR_OPERA) || uaTest('opr')) {
|
||||
o[STR_OPERA] = TRUE;
|
||||
o[STR_VERSION] = webkitVersion || versionTest('opr\/') || versionTest('opera[ \/]');
|
||||
} else if (uaTest(/(msie|trident)/i)) {
|
||||
|
||||
} else if (uaTest('(msie|trident)')) {
|
||||
o[STR_MSIE] = TRUE;
|
||||
o[STR_VERSION] = versionTest('(msie |rv:)', 2);
|
||||
} else if (uaTest(/chrome/i)) {
|
||||
|
||||
} else if (uaTest(STR_CHROME)) {
|
||||
o[STR_CHROME] = o[STR_WEBKIT] = TRUE;
|
||||
o[STR_VERSION] = versionTest(STR_CHROME + '\/');
|
||||
} else if (uaTest(/phantom/i)) {
|
||||
|
||||
} else if (uaTest('phantom')) {
|
||||
o.phantom = o[STR_WEBKIT] = TRUE;
|
||||
o[STR_VERSION] = versionTest('phantomjs\/');
|
||||
} else if (uaTest(/touchpad/i)) {
|
||||
o.touchpad = o[STR_WEBKIT] = TRUE;
|
||||
o[STR_VERSION] = versionTest('touchpad\/');
|
||||
|
||||
} else if (uaTest(STR_TOUCHPAD)) {
|
||||
o[STR_TOUCHPAD] = o[STR_WEBKIT] = TRUE;
|
||||
o[STR_VERSION] = versionTest(STR_TOUCHPAD + '\/');
|
||||
|
||||
} else if (iphone || ipad || ipod) {
|
||||
o.ios = o[STR_MOBILE] = o[STR_WEBKIT] = TRUE;
|
||||
// CAUTION: version is not part of user agent in web apps
|
||||
o[STR_VERSION] = webkitVersion;
|
||||
if (ipod) {
|
||||
o.ipod = TRUE;
|
||||
o[STR_IPOD] = TRUE;
|
||||
} else if (iphone) {
|
||||
o.iphone = TRUE;
|
||||
o[STR_IPHONE] = TRUE;
|
||||
} else if (ipad) {
|
||||
o.ipad = TRUE;
|
||||
o[STR_IPAD] = TRUE;
|
||||
}
|
||||
} else if (uaTest(/blackberry/i)) {
|
||||
o.blackberry = o[STR_MOBILE] = TRUE;
|
||||
|
||||
} else if (uaTest(STR_BLACKBERRY)) {
|
||||
o[STR_BLACKBERRY] = o[STR_MOBILE] = TRUE;
|
||||
if (webkitVersion) {
|
||||
o[STR_WEBKIT] = TRUE;
|
||||
o[STR_VERSION] = webkitVersion;
|
||||
} else {
|
||||
o[STR_VERSION] = versionTest('blackberry[\\d]+\/');
|
||||
o[STR_VERSION] = versionTest(STR_BLACKBERRY + '[\\d]+\/');
|
||||
}
|
||||
} else if (uaTest(/webos/i)) {
|
||||
o.webos = o[STR_MOBILE] = o[STR_WEBKIT] = TRUE;
|
||||
|
||||
} else if (uaTest(STR_WEBOS)) {
|
||||
o[STR_WEBOS] = o[STR_MOBILE] = o[STR_WEBKIT] = TRUE;
|
||||
o[STR_VERSION] = webkitVersion || versionTest('wosbrowser\/');
|
||||
} else if (uaTest(/android/i)) {
|
||||
o.android = o[STR_MOBILE] = o[STR_WEBKIT] = TRUE;
|
||||
|
||||
} else if (uaTest(STR_ANDROID)) {
|
||||
o[STR_ANDROID] = o[STR_MOBILE] = o[STR_WEBKIT] = TRUE;
|
||||
o[STR_VERSION] = webkitVersion || firefoxVersion;
|
||||
} else if (uaTest(/safari/i)) {
|
||||
|
||||
} else if (uaTest(STR_SAFARI)) {
|
||||
o[STR_SAFARI] = o[STR_WEBKIT] = TRUE;
|
||||
o[STR_VERSION] = webkitVersion;
|
||||
} else if (uaTest(/gecko\//i)) {
|
||||
o.gecko = o.mozilla = TRUE;
|
||||
|
||||
} else if (uaTest(STR_GECKO)) {
|
||||
o[STR_GECKO] = o.mozilla = TRUE;
|
||||
o[STR_VERSION] = firefoxVersion;
|
||||
if (uaTest(/firefox/i)) {
|
||||
if (uaTest(STR_FIREFOX)) {
|
||||
o.firefox = TRUE;
|
||||
}
|
||||
} else if (uaTest(/seamonkey\//i)) {
|
||||
|
||||
} else if (uaTest('seamonkey\/')) {
|
||||
o.seamonkey = TRUE;
|
||||
o[STR_VERSION] = versionTest('seamonkey\/');
|
||||
|
||||
} else {
|
||||
o[STR_VERSION] = 0;
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
* @see test/test.js
|
||||
* @author hannes.diercks@jimdo.com
|
||||
*/
|
||||
|
||||
module.exports.useragents = {
|
||||
Chrome: {
|
||||
'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36': {
|
||||
|
Loading…
Reference in New Issue
Block a user