Move the versionNumber matcher to the matcher function to improve minification.

pull/24/head
Hannes Diercks 11 years ago
parent 2d6b83fc2d
commit 4d5db699bd

@ -68,42 +68,43 @@
}
/**
* Get version numbers from our user agent.
* Append version number matcher to our starting string
* and get version number from our user agent.
*
* @param {RegExp} regex
* @param {String} start
* @return {Number}
*/
function versionTest(regex, i) {
var match = ua.match(regex);
function versionTest(start, i) {
var match = ua.match(new RegExp(start + '(\\d+(\\.\\d+)?)', 'i'));
return match ? match[i || 1] : 0;
}
var iphone = uaTest(/iphone/i)
, ipad = uaTest(/ipad/i)
, webkitVersion = /version\/(\d+(\.\d+)?)/i
, firefoxVersion = /firefox\/(\d+(\.\d+)?)/i
, webkitVersion = versionTest(STR_VERSION + '\/')
, firefoxVersion = versionTest(STR_FIREFOX + '[\/ ]')
, o = {}
, version = 0;
if (uaTest(/(msie|trident)/i)) {
o[STR_MSIE] = TRUE;
o[STR_VERSION] = versionTest(/(msie |rv:)(\d+(\.\d+)?)/i, 2);
o[STR_VERSION] = versionTest('(msie |rv:)', 2);
} else if (uaTest(/opera/i) || uaTest(/opr/i)) {
o[STR_OPERA] = TRUE;
o[STR_VERSION] = versionTest(webkitVersion) || versionTest(/opr\/(\d+(\.\d+)?)/i);
o[STR_VERSION] = webkitVersion || versionTest('opr\/');
} else if (uaTest(/chrome/i)) {
o[STR_CHROME] = o[STR_WEBKIT] = TRUE;
o[STR_VERSION] = versionTest(/chrome\/(\d+(\.\d+)?)/i);
o[STR_VERSION] = versionTest(STR_CHROME + '\/');
} else if (uaTest(/phantom/i)) {
o.phantom = o[STR_WEBKIT] = TRUE;
o[STR_VERSION] = versionTest(/phantomjs\/(\d+(\.\d+)?)/i);
o[STR_VERSION] = versionTest('phantomjs\/');
} else if (uaTest(/touchpad/i)) {
o.touchpad = o[STR_WEBKIT] = TRUE;
o[STR_VERSION] = versionTest(/touchpad\/(\d+(\.\d+)?)/i);
o[STR_VERSION] = versionTest('touchpad\/');
} else if (iphone || ipad) {
o.ios = o[STR_MOBILE] = o[STR_WEBKIT] = TRUE;
// WTF: version is not part of user agent in web apps
o[STR_VERSION] = versionTest(webkitVersion);
o[STR_VERSION] = webkitVersion;
if (iphone) {
o.iphone = TRUE;
} else if (ipad) {
@ -111,19 +112,19 @@
}
} else if (uaTest(/android/i)) {
o.android = o[STR_MOBILE] = o[STR_WEBKIT] = TRUE;
o[STR_VERSION] = versionTest(webkitVersion) || versionTest(firefoxVersion);
o[STR_VERSION] = webkitVersion || firefoxVersion;
} else if (uaTest(/safari/i)) {
o[STR_SAFARI] = o[STR_WEBKIT] = TRUE;
o[STR_VERSION] = versionTest(webkitVersion);
o[STR_VERSION] = webkitVersion;
} else if (uaTest(/gecko\//i)) {
o.gecko = o.mozilla = TRUE;
o[STR_VERSION] = versionTest(firefoxVersion);
o[STR_VERSION] = firefoxVersion;
if (uaTest(/firefox/i)) {
o.firefox = TRUE;
}
} else if (uaTest(/seamonkey\//i)) {
o.seamonkey = TRUE;
o[STR_VERSION] = versionTest(/seamonkey\/(\d+(\.\d+)?)/i);
o[STR_VERSION] = versionTest('seamonkey\/');
} else {
o[STR_VERSION] = 0;
}

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(e);return n?n[t||1]:0}var h=l(/iphone/i),p=l(/ipad/i),d=/version\/(\d+(\.\d+)?)/i,v=/firefox\/(\d+(\.\d+)?)/i,m={},g=0;return l(/(msie|trident)/i)?(m[r]=e,m[t]=c(/(msie |rv:)(\d+(\.\d+)?)/i,2)):l(/opera/i)||l(/opr/i)?(m[i]=e,m[t]=c(d)||c(/opr\/(\d+(\.\d+)?)/i)):l(/chrome/i)?(m[s]=m[o]=e,m[t]=c(/chrome\/(\d+(\.\d+)?)/i)):l(/phantom/i)?(m.phantom=m[o]=e,m[t]=c(/phantomjs\/(\d+(\.\d+)?)/i)):l(/touchpad/i)?(m.touchpad=m[o]=e,m[t]=c(/touchpad\/(\d+(\.\d+)?)/i)):h||p?(m.ios=m[n]=m[o]=e,m[t]=c(d),h?m.iphone=e:p&&(m.ipad=e)):l(/android/i)?(m.android=m[n]=m[o]=e,m[t]=c(d)||c(v)):l(/safari/i)?(m[u]=m[o]=e,m[t]=c(d)):l(/gecko\//i)?(m.gecko=m.mozilla=e,m[t]=c(v),l(/firefox/i)&&(m.firefox=e)):l(/seamonkey\//i)?(m.seamonkey=e,m[t]=c(/seamonkey\/(\d+(\.\d+)?)/i)):m[t]=0,g=m[t],m[r]&&g>=8||m[s]&&g>=10||m[a]&&g>=4||m[u]&&g>=5||m[i]&&g>=10?m.a=e:m[r]&&g<8||m[s]&&g<10||m[a]&&g<4||m[u]&&g<5||m[i]&&g<10?m.c=e:m.x=e,m}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 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=c(t+"/"),v=c(a+"[/ ]"),m={},g=0;return l(/(msie|trident)/i)?(m[r]=e,m[t]=c("(msie |rv:)",2)):l(/opera/i)||l(/opr/i)?(m[i]=e,m[t]=d||c("opr/")):l(/chrome/i)?(m[s]=m[o]=e,m[t]=c(s+"/")):l(/phantom/i)?(m.phantom=m[o]=e,m[t]=c("phantomjs/")):l(/touchpad/i)?(m.touchpad=m[o]=e,m[t]=c("touchpad/")):h||p?(m.ios=m[n]=m[o]=e,m[t]=d,h?m.iphone=e:p&&(m.ipad=e)):l(/android/i)?(m.android=m[n]=m[o]=e,m[t]=d||v):l(/safari/i)?(m[u]=m[o]=e,m[t]=d):l(/gecko\//i)?(m.gecko=m.mozilla=e,m[t]=v,l(/firefox/i)&&(m.firefox=e)):l(/seamonkey\//i)?(m.seamonkey=e,m[t]=c("seamonkey/")):m[t]=0,g=m[t],m[r]&&g>=8||m[s]&&g>=10||m[a]&&g>=4||m[u]&&g>=5||m[i]&&g>=10?m.a=e:m[r]&&g<8||m[s]&&g<10||m[a]&&g<4||m[u]&&g<5||m[i]&&g<10?m.c=e:m.x=e,m}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})

@ -62,42 +62,43 @@
}
/**
* Get version numbers from our user agent.
* Append version number matcher to our starting string
* and get version number from our user agent.
*
* @param {RegExp} regex
* @param {String} start
* @return {Number}
*/
function versionTest(regex, i) {
var match = ua.match(regex);
function versionTest(start, i) {
var match = ua.match(new RegExp(start + '(\\d+(\\.\\d+)?)', 'i'));
return match ? match[i || 1] : 0;
}
var iphone = uaTest(/iphone/i)
, ipad = uaTest(/ipad/i)
, webkitVersion = /version\/(\d+(\.\d+)?)/i
, firefoxVersion = /firefox\/(\d+(\.\d+)?)/i
, webkitVersion = versionTest(STR_VERSION + '\/')
, firefoxVersion = versionTest(STR_FIREFOX + '[\/ ]')
, o = {}
, version = 0;
if (uaTest(/(msie|trident)/i)) {
o[STR_MSIE] = TRUE;
o[STR_VERSION] = versionTest(/(msie |rv:)(\d+(\.\d+)?)/i, 2);
o[STR_VERSION] = versionTest('(msie |rv:)', 2);
} else if (uaTest(/opera/i) || uaTest(/opr/i)) {
o[STR_OPERA] = TRUE;
o[STR_VERSION] = versionTest(webkitVersion) || versionTest(/opr\/(\d+(\.\d+)?)/i);
o[STR_VERSION] = webkitVersion || versionTest('opr\/');
} else if (uaTest(/chrome/i)) {
o[STR_CHROME] = o[STR_WEBKIT] = TRUE;
o[STR_VERSION] = versionTest(/chrome\/(\d+(\.\d+)?)/i);
o[STR_VERSION] = versionTest(STR_CHROME + '\/');
} else if (uaTest(/phantom/i)) {
o.phantom = o[STR_WEBKIT] = TRUE;
o[STR_VERSION] = versionTest(/phantomjs\/(\d+(\.\d+)?)/i);
o[STR_VERSION] = versionTest('phantomjs\/');
} else if (uaTest(/touchpad/i)) {
o.touchpad = o[STR_WEBKIT] = TRUE;
o[STR_VERSION] = versionTest(/touchpad\/(\d+(\.\d+)?)/i);
o[STR_VERSION] = versionTest('touchpad\/');
} else if (iphone || ipad) {
o.ios = o[STR_MOBILE] = o[STR_WEBKIT] = TRUE;
// WTF: version is not part of user agent in web apps
o[STR_VERSION] = versionTest(webkitVersion);
o[STR_VERSION] = webkitVersion;
if (iphone) {
o.iphone = TRUE;
} else if (ipad) {
@ -105,19 +106,19 @@
}
} else if (uaTest(/android/i)) {
o.android = o[STR_MOBILE] = o[STR_WEBKIT] = TRUE;
o[STR_VERSION] = versionTest(webkitVersion) || versionTest(firefoxVersion);
o[STR_VERSION] = webkitVersion || firefoxVersion;
} else if (uaTest(/safari/i)) {
o[STR_SAFARI] = o[STR_WEBKIT] = TRUE;
o[STR_VERSION] = versionTest(webkitVersion);
o[STR_VERSION] = webkitVersion;
} else if (uaTest(/gecko\//i)) {
o.gecko = o.mozilla = TRUE;
o[STR_VERSION] = versionTest(firefoxVersion);
o[STR_VERSION] = firefoxVersion;
if (uaTest(/firefox/i)) {
o.firefox = TRUE;
}
} else if (uaTest(/seamonkey\//i)) {
o.seamonkey = TRUE;
o[STR_VERSION] = versionTest(/seamonkey\/(\d+(\.\d+)?)/i);
o[STR_VERSION] = versionTest('seamonkey\/');
} else {
o[STR_VERSION] = 0;
}

Loading…
Cancel
Save