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

Move user agent tests to if clauses for better minification and less function calls.

This commit is contained in:
Hannes Diercks 2013-09-13 14:30:33 +02:00
parent 73ac715e1e
commit 38478c576d
3 changed files with 25 additions and 41 deletions

View File

@ -51,45 +51,35 @@
}
var t = true
, ie = uaTest(/(msie|trident)/i)
, chrome = uaTest(/chrome/i)
, phantom = uaTest(/phantom/i)
, safari = uaTest(/safari/i) && !chrome && !phantom
, iphone = uaTest(/iphone/i)
, ipad = uaTest(/ipad/i)
, touchpad = uaTest(/touchpad/i)
, android = uaTest(/android/i)
, opera = uaTest(/opera/i) || uaTest(/opr/i)
, firefox = uaTest(/firefox/i)
, gecko = uaTest(/gecko\//i)
, seamonkey = uaTest(/seamonkey\//i)
, webkitVersion = /version\/(\d+(\.\d+)?)/i
, firefoxVersion = /firefox\/(\d+(\.\d+)?)/i
, o;
if (ie) {
if (uaTest(/(msie|trident)/i)) {
o = {
msie: t
, version: versionTest(/(msie |rv:)(\d+(\.\d+)?)/i, 2)
};
} else if (opera) {
} else if (uaTest(/opera/i) || uaTest(/opr/i)) {
o = {
opera: t
, version: versionTest(webkitVersion) || versionTest(/opr\/(\d+(\.\d+)?)/i)
};
} else if (chrome) {
} else if (uaTest(/chrome/i)) {
o = {
webkit: t
, chrome: t
, version: versionTest(/chrome\/(\d+(\.\d+)?)/i)
};
} else if (phantom) {
} else if (uaTest(/phantom/i)) {
o = {
webkit: t
, phantom: t
, version: versionTest(/phantomjs\/(\d+(\.\d+)+)/i)
};
} else if (touchpad) {
} else if (uaTest(/touchpad/i)) {
o = {
webkit: t
, touchpad: t
@ -105,27 +95,29 @@
// WTF: version is not part of user agent in web apps
, version: versionTest(webkitVersion)
};
} else if (android) {
} else if (uaTest(/android/i)) {
o = {
webkit: t
, android: t
, mobile: t
, version: versionTest(webkitVersion) || versionTest(firefoxVersion)
};
} else if (safari) {
} else if (uaTest(/safari/i)) {
o = {
webkit: t
, safari: t
, version: versionTest(webkitVersion)
};
} else if (gecko) {
} else if (uaTest(/gecko\//i)) {
o = {
gecko: t
, mozilla: t
, version: versionTest(firefoxVersion)
};
if (firefox) o.firefox = t;
} else if (seamonkey) {
if (uaTest(/firefox/i)) {
o.firefox = t;
}
} else if (uaTest(/seamonkey\//i)) {
o = {
seamonkey: t
, version: versionTest(/seamonkey\/(\d+(\.\d+)?)/i)

2
bowser.min.js vendored
View File

@ -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 e(e){function t(t){return t.test(e)}function n(t,n){var r=e.match(t);return r?r[n||1]:0}var r=!0,i=t(/(msie|trident)/i),s=t(/chrome/i),o=t(/phantom/i),u=t(/safari/i)&&!s&&!o,a=t(/iphone/i),f=t(/ipad/i),l=t(/touchpad/i),c=t(/android/i),h=t(/opera/i)||t(/opr/i),p=t(/firefox/i),d=t(/gecko\//i),v=t(/seamonkey\//i),m=/version\/(\d+(\.\d+)?)/i,g=/firefox\/(\d+(\.\d+)?)/i,y;return i?y={msie:r,version:n(/(msie |rv:)(\d+(\.\d+)?)/i,2)}:h?y={opera:r,version:n(m)||n(/opr\/(\d+(\.\d+)?)/i)}:s?y={webkit:r,chrome:r,version:n(/chrome\/(\d+(\.\d+)?)/i)}:o?y={webkit:r,phantom:r,version:n(/phantomjs\/(\d+(\.\d+)+)/i)}:l?y={webkit:r,touchpad:r,version:n(/touchpad\/(\d+(\.\d+)?)/i)}:a||f?y={webkit:r,mobile:r,ios:r,iphone:a,ipad:f,version:n(m)}:c?y={webkit:r,android:r,mobile:r,version:n(m)||n(g)}:u?y={webkit:r,safari:r,version:n(m)}:d?(y={gecko:r,mozilla:r,version:n(g)},p&&(y.firefox=r)):v?y={seamonkey:r,version:n(/seamonkey\/(\d+(\.\d+)?)/i)}:y={},y.msie&&y.version>=8||y.chrome&&y.version>=10||y.firefox&&y.version>=4||y.safari&&y.version>=5||y.opera&&y.version>=10?y.a=r:y.msie&&y.version<8||y.chrome&&y.version<10||y.firefox&&y.version<4||y.safari&&y.version<5||y.opera&&y.version<10?y.c=r:y.x=r,y}var t=e(typeof navigator!="undefined"?navigator.userAgent:"");return t._detect=e,t})
!function(e,t){typeof define=="function"?define(t):typeof module!="undefined"&&module.exports?module.exports[e]=t():this[e]=t()}("bowser",function(){function e(e){function t(t){return t.test(e)}function n(t,n){var r=e.match(t);return r?r[n||1]:0}var r=!0,i=t(/iphone/i),s=t(/ipad/i),o=/version\/(\d+(\.\d+)?)/i,u=/firefox\/(\d+(\.\d+)?)/i,a;if(t(/(msie|trident)/i))a={msie:r,version:n(/(msie |rv:)(\d+(\.\d+)?)/i,2)};else if(t(/opera/i)||t(/opr/i))a={opera:r,version:n(o)||n(/opr\/(\d+(\.\d+)?)/i)};else if(t(/chrome/i))a={webkit:r,chrome:r,version:n(/chrome\/(\d+(\.\d+)?)/i)};else if(t(/phantom/i))a={webkit:r,phantom:r,version:n(/phantomjs\/(\d+(\.\d+)+)/i)};else{if(t(/touchpad/i))return{webkit:r,touchpad:r,version:n(/touchpad\/(\d+(\.\d+)?)/i)};i||s?a={webkit:r,mobile:r,ios:r,iphone:i,ipad:s,version:n(o)}:t(/android/i)?a={webkit:r,android:r,mobile:r,version:n(o)||n(u)}:t(/safari/i)?a={webkit:r,safari:r,version:n(o)}:t(/gecko\//i)?(a={gecko:r,mozilla:r,version:n(u)},t(/firefox/i)&&(a.firefox=r)):t(/seamonkey\//i)?a={seamonkey:r,version:n(/seamonkey\/(\d+(\.\d+)?)/i)}:a={}}return a.msie&&a.version>=8||a.chrome&&a.version>=10||a.firefox&&a.version>=4||a.safari&&a.version>=5||a.opera&&a.version>=10?a.a=r:a.msie&&a.version<8||a.chrome&&a.version<10||a.firefox&&a.version<4||a.safari&&a.version<5||a.opera&&a.version<10?a.c=r:a.x=r,a}var t=e(typeof navigator!="undefined"?navigator.userAgent:"");return t._detect=e,t})

View File

@ -45,45 +45,35 @@
}
var t = true
, ie = uaTest(/(msie|trident)/i)
, chrome = uaTest(/chrome/i)
, phantom = uaTest(/phantom/i)
, safari = uaTest(/safari/i) && !chrome && !phantom
, iphone = uaTest(/iphone/i)
, ipad = uaTest(/ipad/i)
, touchpad = uaTest(/touchpad/i)
, android = uaTest(/android/i)
, opera = uaTest(/opera/i) || uaTest(/opr/i)
, firefox = uaTest(/firefox/i)
, gecko = uaTest(/gecko\//i)
, seamonkey = uaTest(/seamonkey\//i)
, webkitVersion = /version\/(\d+(\.\d+)?)/i
, firefoxVersion = /firefox\/(\d+(\.\d+)?)/i
, o;
if (ie) {
if (uaTest(/(msie|trident)/i)) {
o = {
msie: t
, version: versionTest(/(msie |rv:)(\d+(\.\d+)?)/i, 2)
};
} else if (opera) {
} else if (uaTest(/opera/i) || uaTest(/opr/i)) {
o = {
opera: t
, version: versionTest(webkitVersion) || versionTest(/opr\/(\d+(\.\d+)?)/i)
};
} else if (chrome) {
} else if (uaTest(/chrome/i)) {
o = {
webkit: t
, chrome: t
, version: versionTest(/chrome\/(\d+(\.\d+)?)/i)
};
} else if (phantom) {
} else if (uaTest(/phantom/i)) {
o = {
webkit: t
, phantom: t
, version: versionTest(/phantomjs\/(\d+(\.\d+)+)/i)
};
} else if (touchpad) {
} else if (uaTest(/touchpad/i)) {
o = {
webkit: t
, touchpad: t
@ -99,27 +89,29 @@
// WTF: version is not part of user agent in web apps
, version: versionTest(webkitVersion)
};
} else if (android) {
} else if (uaTest(/android/i)) {
o = {
webkit: t
, android: t
, mobile: t
, version: versionTest(webkitVersion) || versionTest(firefoxVersion)
};
} else if (safari) {
} else if (uaTest(/safari/i)) {
o = {
webkit: t
, safari: t
, version: versionTest(webkitVersion)
};
} else if (gecko) {
} else if (uaTest(/gecko\//i)) {
o = {
gecko: t
, mozilla: t
, version: versionTest(firefoxVersion)
};
if (firefox) o.firefox = t;
} else if (seamonkey) {
if (uaTest(/firefox/i)) {
o.firefox = t;
}
} else if (uaTest(/seamonkey\//i)) {
o = {
seamonkey: t
, version: versionTest(/seamonkey\/(\d+(\.\d+)?)/i)