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:
parent
c19a6672aa
commit
745c38b758
234
bowser.js
234
bowser.js
@ -13,235 +13,211 @@
|
||||
* See useragents.js for examples of navigator.userAgent
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
var t = true
|
||||
|
||||
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)
|
||||
, phantom = /phantom/i.test(ua)
|
||||
, iphone = /iphone/i.test(ua)
|
||||
, ipad = /ipad/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)
|
||||
, safari = /safari/i.test(ua) && !chrome && !phantom && !silk
|
||||
, android = /android/i.test(ua)
|
||||
, opera = /opera/i.test(ua) || /opr/i.test(ua)
|
||||
, firefox = /(firefox|iceweasel)/i.test(ua)
|
||||
, likeAndroid = /like android/i.test(ua)
|
||||
, android = !likeAndroid && /android/i.test(ua)
|
||||
, opera = /opera|opr/i.test(ua)
|
||||
, firefox = /firefox|iceweasel/i.test(ua)
|
||||
, gecko = /gecko\//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)
|
||||
, 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)
|
||||
, bada = /bada/i.test(ua)
|
||||
, tizen = /tizen/i.test(ua)
|
||||
, webkitVersion = /version\/(\d+(\.\d+)?)/i
|
||||
, firefoxVersion = /(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i
|
||||
, safari = /safari/i.test(ua)
|
||||
, webkit = /applewebkit/i.test(ua)
|
||||
, versionIdentifier = getVersion(/version\/(\d+(\.\d+)?)/i)
|
||||
, mobile = /mobi/i.test(ua)
|
||||
, tablet = /tablet/i.test(ua)
|
||||
, o = {}
|
||||
, result
|
||||
|
||||
if (ipod) iphone = false
|
||||
|
||||
if (windowsphone) o = {
|
||||
if (windowsphone) result = {
|
||||
name: 'Windows Phone'
|
||||
, windowsphone: t
|
||||
, msie: t
|
||||
, version: getVersion(ua, /iemobile\/(\d+(\.\d+)?)/i, 1)
|
||||
, version: getVersion(/iemobile\/(\d+(\.\d+)?)/i)
|
||||
}
|
||||
else if (opera) {
|
||||
v = getVersion(ua, webkitVersion, 1) ||
|
||||
getVersion(ua, /opr\/(\d+(\.\d+)?)/i, 1) ||
|
||||
getVersion(ua, /opera[ \/](\d+(\.\d+)?)/i, 1);
|
||||
o = {
|
||||
result = {
|
||||
name: 'Opera'
|
||||
, opera: t
|
||||
, version: v
|
||||
}
|
||||
if (android) {
|
||||
o.android = t
|
||||
}
|
||||
if (chrome) {
|
||||
o.webkit = t
|
||||
, version: versionIdentifier ||
|
||||
getVersion(/opr\/(\d+(\.\d+)?)/i) ||
|
||||
getVersion(/opera[ \/](\d+(\.\d+)?)/i)
|
||||
}
|
||||
}
|
||||
else if (ie) o = {
|
||||
else if (ie) result = {
|
||||
name: 'Internet Explorer'
|
||||
, msie: t
|
||||
, version: getVersion(ua, /(msie |rv:)(\d+(\.\d+)?)/i, 2)
|
||||
, version: getVersion(/(?:msie |rv:)(\d+(\.\d+)?)/i)
|
||||
}
|
||||
else if (chrome) {
|
||||
o = {
|
||||
result = {
|
||||
name: 'Chrome'
|
||||
, webkit: t
|
||||
, chrome: t
|
||||
, version: getVersion(ua, /(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i, 1)
|
||||
}
|
||||
if (android) o.android = t
|
||||
if (ipad || ipod || iphone) {
|
||||
o[iphone ? 'iphone' : ipad ? 'ipad' : 'ipod'] = t
|
||||
o.ios = t
|
||||
, version: getVersion(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)
|
||||
}
|
||||
}
|
||||
else if (phantom) o = {
|
||||
else if (phantom) result = {
|
||||
name: 'PhantomJS'
|
||||
, webkit: 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'
|
||||
, silk: t
|
||||
, webkit: t
|
||||
, android: t
|
||||
, version : getVersion(ua, /silk\/(\d+(\.\d+)?)/i, 1)
|
||||
, version : getVersion(/silk\/(\d+(\.\d+)?)/i)
|
||||
}
|
||||
else if (iphone || ipad || ipod) {
|
||||
o = {
|
||||
else if (ios) {
|
||||
result = {
|
||||
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
|
||||
if (webkitVersion.test(ua)) {
|
||||
o.version = getVersion(ua, webkitVersion, 1)
|
||||
if (versionIdentifier) {
|
||||
result.version = versionIdentifier
|
||||
}
|
||||
}
|
||||
else if (blackberry || rimtablet) {
|
||||
o = {
|
||||
result = {
|
||||
name: 'BlackBerry'
|
||||
, blackberry: t
|
||||
}
|
||||
if ((v = getVersion(ua, webkitVersion, 1))) {
|
||||
o.version = v
|
||||
o.webkit = t
|
||||
} else {
|
||||
o.version = getVersion(ua, /blackberry[\d]+\/(\d+(\.\d+)?)/i, 1)
|
||||
, version: versionIdentifier || getVersion(/blackberry[\d]+\/(\d+(\.\d+)?)/i)
|
||||
}
|
||||
}
|
||||
else if (webos) {
|
||||
o = {
|
||||
result = {
|
||||
name: 'WebOS'
|
||||
, webkit: 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) {
|
||||
o = {
|
||||
result = {
|
||||
name: 'Bada'
|
||||
, webkit: t
|
||||
, bada: t
|
||||
, version: getVersion(ua, /dolfin\/(\d+(\.\d+)?)/i, 1)
|
||||
, version: getVersion(/dolfin\/(\d+(\.\d+)?)/i)
|
||||
};
|
||||
touchpad && (o.touchpad = t)
|
||||
}
|
||||
else if (tizen) {
|
||||
o = {
|
||||
result = {
|
||||
name: 'Tizen'
|
||||
, webkit: 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) {
|
||||
o = {
|
||||
result = {
|
||||
name: 'Gecko'
|
||||
, gecko: t
|
||||
, mozilla: t
|
||||
, version: getVersion(ua, firefoxVersion, 1)
|
||||
, version: getVersion(/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i)
|
||||
}
|
||||
if (seamonkey) {
|
||||
o.name = 'SeaMonkey'
|
||||
o.seamonkey = t
|
||||
o.version = getVersion(ua, /seamonkey\/(\d+(\.\d+)?)/i, 1)
|
||||
result.name = 'SeaMonkey'
|
||||
result.seamonkey = t
|
||||
result.version = getVersion(/seamonkey\/(\d+(\.\d+)?)/i)
|
||||
} else if (firefox) {
|
||||
o.name = 'Firefox'
|
||||
o.firefox = t
|
||||
}
|
||||
if (android) {
|
||||
o.android = t
|
||||
} else if (!android && firefox && /\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(ua)) {
|
||||
o.firefoxos = t
|
||||
result.name = 'Firefox'
|
||||
result.firefox = t
|
||||
if (/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(ua)) {
|
||||
result.firefoxos = t
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (android) o = {
|
||||
else if (android) result = {
|
||||
name: 'Android'
|
||||
, webkit: t
|
||||
, android: t
|
||||
, version: getVersion(ua, webkitVersion, 1)
|
||||
, version: versionIdentifier
|
||||
}
|
||||
else if (safari) o = {
|
||||
else if (safari) result = {
|
||||
name: 'Safari'
|
||||
, webkit: 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
|
||||
var osVersion;
|
||||
if (tizen) {
|
||||
osVersion = getVersion(ua, /tizen[\/\s](\d+(\.\d+)*)/i, 1);
|
||||
} else if (windowsphone) {
|
||||
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, '.');
|
||||
if (ios) {
|
||||
osVersion = getVersion(/os (\d+([_\s]\d+)*) like mac os x/i);
|
||||
osVersion = osVersion.replace(/[_\s]/g, '.');
|
||||
} 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) {
|
||||
o.osversion = osVersion;
|
||||
result.osversion = osVersion;
|
||||
}
|
||||
|
||||
// device type extraction
|
||||
var osMajorVersion = (osVersion || '').split('.')[0];
|
||||
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) {
|
||||
o.mobile = t
|
||||
result.mobile = t
|
||||
}
|
||||
|
||||
// Graded Browser Support
|
||||
// http://developer.yahoo.com/yui/articles/gbs
|
||||
if ((o.msie && o.version >= 9) ||
|
||||
(o.chrome && o.version >= 20) ||
|
||||
(o.firefox && o.version >= 10.0) ||
|
||||
(o.safari && o.version >= 5) ||
|
||||
(o.opera && o.version >= 10.0) ||
|
||||
(o.ios && o.osversion && o.osversion.split(".")[0] >= 6)
|
||||
if ((result.msie && result.version >= 9) ||
|
||||
(result.chrome && result.version >= 20) ||
|
||||
(result.firefox && result.version >= 10.0) ||
|
||||
(result.safari && result.version >= 5) ||
|
||||
(result.opera && result.version >= 10.0) ||
|
||||
(result.ios && result.osversion && result.osversion.split(".")[0] >= 6)
|
||||
) {
|
||||
o.a = t;
|
||||
result.a = t;
|
||||
}
|
||||
|
||||
else if ((o.msie && o.version < 9) ||
|
||||
(o.chrome && o.version < 20) ||
|
||||
(o.firefox && o.version < 10.0) ||
|
||||
(o.safari && o.version < 5) ||
|
||||
(o.opera && o.version < 10.0) ||
|
||||
(o.ios && o.osversion && o.osversion.split(".")[0] < 6)
|
||||
else if ((result.msie && result.version < 9) ||
|
||||
(result.chrome && result.version < 20) ||
|
||||
(result.firefox && result.version < 10.0) ||
|
||||
(result.safari && result.version < 5) ||
|
||||
(result.opera && result.version < 10.0) ||
|
||||
(result.ios && result.osversion && result.osversion.split(".")[0] < 6)
|
||||
) {
|
||||
o.c = t
|
||||
} else o.x = t
|
||||
result.c = t
|
||||
} else result.x = t
|
||||
|
||||
return o
|
||||
return result
|
||||
}
|
||||
|
||||
var bowser = detect(typeof navigator !== 'undefined' ? navigator.userAgent : '')
|
||||
|
2
bowser.min.js
vendored
2
bowser.min.js
vendored
@ -3,4 +3,4 @@
|
||||
* https://github.com/ded/bowser
|
||||
* 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})
|
@ -21,5 +21,6 @@ require('smoosh').config({
|
||||
, "asi": true
|
||||
, "laxbreak": true
|
||||
, "laxcomma": true
|
||||
, "eqnull": true
|
||||
}
|
||||
}).run().build().analyze()
|
||||
|
234
src/bowser.js
234
src/bowser.js
@ -7,235 +7,211 @@
|
||||
* See useragents.js for examples of navigator.userAgent
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
var t = true
|
||||
|
||||
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)
|
||||
, phantom = /phantom/i.test(ua)
|
||||
, iphone = /iphone/i.test(ua)
|
||||
, ipad = /ipad/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)
|
||||
, safari = /safari/i.test(ua) && !chrome && !phantom && !silk
|
||||
, android = /android/i.test(ua)
|
||||
, opera = /opera/i.test(ua) || /opr/i.test(ua)
|
||||
, firefox = /(firefox|iceweasel)/i.test(ua)
|
||||
, likeAndroid = /like android/i.test(ua)
|
||||
, android = !likeAndroid && /android/i.test(ua)
|
||||
, opera = /opera|opr/i.test(ua)
|
||||
, firefox = /firefox|iceweasel/i.test(ua)
|
||||
, gecko = /gecko\//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)
|
||||
, 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)
|
||||
, bada = /bada/i.test(ua)
|
||||
, tizen = /tizen/i.test(ua)
|
||||
, webkitVersion = /version\/(\d+(\.\d+)?)/i
|
||||
, firefoxVersion = /(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i
|
||||
, safari = /safari/i.test(ua)
|
||||
, webkit = /applewebkit/i.test(ua)
|
||||
, versionIdentifier = getVersion(/version\/(\d+(\.\d+)?)/i)
|
||||
, mobile = /mobi/i.test(ua)
|
||||
, tablet = /tablet/i.test(ua)
|
||||
, o = {}
|
||||
, result
|
||||
|
||||
if (ipod) iphone = false
|
||||
|
||||
if (windowsphone) o = {
|
||||
if (windowsphone) result = {
|
||||
name: 'Windows Phone'
|
||||
, windowsphone: t
|
||||
, msie: t
|
||||
, version: getVersion(ua, /iemobile\/(\d+(\.\d+)?)/i, 1)
|
||||
, version: getVersion(/iemobile\/(\d+(\.\d+)?)/i)
|
||||
}
|
||||
else if (opera) {
|
||||
v = getVersion(ua, webkitVersion, 1) ||
|
||||
getVersion(ua, /opr\/(\d+(\.\d+)?)/i, 1) ||
|
||||
getVersion(ua, /opera[ \/](\d+(\.\d+)?)/i, 1);
|
||||
o = {
|
||||
result = {
|
||||
name: 'Opera'
|
||||
, opera: t
|
||||
, version: v
|
||||
}
|
||||
if (android) {
|
||||
o.android = t
|
||||
}
|
||||
if (chrome) {
|
||||
o.webkit = t
|
||||
, version: versionIdentifier ||
|
||||
getVersion(/opr\/(\d+(\.\d+)?)/i) ||
|
||||
getVersion(/opera[ \/](\d+(\.\d+)?)/i)
|
||||
}
|
||||
}
|
||||
else if (ie) o = {
|
||||
else if (ie) result = {
|
||||
name: 'Internet Explorer'
|
||||
, msie: t
|
||||
, version: getVersion(ua, /(msie |rv:)(\d+(\.\d+)?)/i, 2)
|
||||
, version: getVersion(/(?:msie |rv:)(\d+(\.\d+)?)/i)
|
||||
}
|
||||
else if (chrome) {
|
||||
o = {
|
||||
result = {
|
||||
name: 'Chrome'
|
||||
, webkit: t
|
||||
, chrome: t
|
||||
, version: getVersion(ua, /(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i, 1)
|
||||
}
|
||||
if (android) o.android = t
|
||||
if (ipad || ipod || iphone) {
|
||||
o[iphone ? 'iphone' : ipad ? 'ipad' : 'ipod'] = t
|
||||
o.ios = t
|
||||
, version: getVersion(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)
|
||||
}
|
||||
}
|
||||
else if (phantom) o = {
|
||||
else if (phantom) result = {
|
||||
name: 'PhantomJS'
|
||||
, webkit: 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'
|
||||
, silk: t
|
||||
, webkit: t
|
||||
, android: t
|
||||
, version : getVersion(ua, /silk\/(\d+(\.\d+)?)/i, 1)
|
||||
, version : getVersion(/silk\/(\d+(\.\d+)?)/i)
|
||||
}
|
||||
else if (iphone || ipad || ipod) {
|
||||
o = {
|
||||
else if (ios) {
|
||||
result = {
|
||||
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
|
||||
if (webkitVersion.test(ua)) {
|
||||
o.version = getVersion(ua, webkitVersion, 1)
|
||||
if (versionIdentifier) {
|
||||
result.version = versionIdentifier
|
||||
}
|
||||
}
|
||||
else if (blackberry || rimtablet) {
|
||||
o = {
|
||||
result = {
|
||||
name: 'BlackBerry'
|
||||
, blackberry: t
|
||||
}
|
||||
if ((v = getVersion(ua, webkitVersion, 1))) {
|
||||
o.version = v
|
||||
o.webkit = t
|
||||
} else {
|
||||
o.version = getVersion(ua, /blackberry[\d]+\/(\d+(\.\d+)?)/i, 1)
|
||||
, version: versionIdentifier || getVersion(/blackberry[\d]+\/(\d+(\.\d+)?)/i)
|
||||
}
|
||||
}
|
||||
else if (webos) {
|
||||
o = {
|
||||
result = {
|
||||
name: 'WebOS'
|
||||
, webkit: 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) {
|
||||
o = {
|
||||
result = {
|
||||
name: 'Bada'
|
||||
, webkit: t
|
||||
, bada: t
|
||||
, version: getVersion(ua, /dolfin\/(\d+(\.\d+)?)/i, 1)
|
||||
, version: getVersion(/dolfin\/(\d+(\.\d+)?)/i)
|
||||
};
|
||||
touchpad && (o.touchpad = t)
|
||||
}
|
||||
else if (tizen) {
|
||||
o = {
|
||||
result = {
|
||||
name: 'Tizen'
|
||||
, webkit: 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) {
|
||||
o = {
|
||||
result = {
|
||||
name: 'Gecko'
|
||||
, gecko: t
|
||||
, mozilla: t
|
||||
, version: getVersion(ua, firefoxVersion, 1)
|
||||
, version: getVersion(/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i)
|
||||
}
|
||||
if (seamonkey) {
|
||||
o.name = 'SeaMonkey'
|
||||
o.seamonkey = t
|
||||
o.version = getVersion(ua, /seamonkey\/(\d+(\.\d+)?)/i, 1)
|
||||
result.name = 'SeaMonkey'
|
||||
result.seamonkey = t
|
||||
result.version = getVersion(/seamonkey\/(\d+(\.\d+)?)/i)
|
||||
} else if (firefox) {
|
||||
o.name = 'Firefox'
|
||||
o.firefox = t
|
||||
}
|
||||
if (android) {
|
||||
o.android = t
|
||||
} else if (!android && firefox && /\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(ua)) {
|
||||
o.firefoxos = t
|
||||
result.name = 'Firefox'
|
||||
result.firefox = t
|
||||
if (/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(ua)) {
|
||||
result.firefoxos = t
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (android) o = {
|
||||
else if (android) result = {
|
||||
name: 'Android'
|
||||
, webkit: t
|
||||
, android: t
|
||||
, version: getVersion(ua, webkitVersion, 1)
|
||||
, version: versionIdentifier
|
||||
}
|
||||
else if (safari) o = {
|
||||
else if (safari) result = {
|
||||
name: 'Safari'
|
||||
, webkit: 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
|
||||
var osVersion;
|
||||
if (tizen) {
|
||||
osVersion = getVersion(ua, /tizen[\/\s](\d+(\.\d+)*)/i, 1);
|
||||
} else if (windowsphone) {
|
||||
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, '.');
|
||||
if (ios) {
|
||||
osVersion = getVersion(/os (\d+([_\s]\d+)*) like mac os x/i);
|
||||
osVersion = osVersion.replace(/[_\s]/g, '.');
|
||||
} 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) {
|
||||
o.osversion = osVersion;
|
||||
result.osversion = osVersion;
|
||||
}
|
||||
|
||||
// device type extraction
|
||||
var osMajorVersion = (osVersion || '').split('.')[0];
|
||||
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) {
|
||||
o.mobile = t
|
||||
result.mobile = t
|
||||
}
|
||||
|
||||
// Graded Browser Support
|
||||
// http://developer.yahoo.com/yui/articles/gbs
|
||||
if ((o.msie && o.version >= 9) ||
|
||||
(o.chrome && o.version >= 20) ||
|
||||
(o.firefox && o.version >= 10.0) ||
|
||||
(o.safari && o.version >= 5) ||
|
||||
(o.opera && o.version >= 10.0) ||
|
||||
(o.ios && o.osversion && o.osversion.split(".")[0] >= 6)
|
||||
if ((result.msie && result.version >= 9) ||
|
||||
(result.chrome && result.version >= 20) ||
|
||||
(result.firefox && result.version >= 10.0) ||
|
||||
(result.safari && result.version >= 5) ||
|
||||
(result.opera && result.version >= 10.0) ||
|
||||
(result.ios && result.osversion && result.osversion.split(".")[0] >= 6)
|
||||
) {
|
||||
o.a = t;
|
||||
result.a = t;
|
||||
}
|
||||
|
||||
else if ((o.msie && o.version < 9) ||
|
||||
(o.chrome && o.version < 20) ||
|
||||
(o.firefox && o.version < 10.0) ||
|
||||
(o.safari && o.version < 5) ||
|
||||
(o.opera && o.version < 10.0) ||
|
||||
(o.ios && o.osversion && o.osversion.split(".")[0] < 6)
|
||||
else if ((result.msie && result.version < 9) ||
|
||||
(result.chrome && result.version < 20) ||
|
||||
(result.firefox && result.version < 10.0) ||
|
||||
(result.safari && result.version < 5) ||
|
||||
(result.opera && result.version < 10.0) ||
|
||||
(result.ios && result.osversion && result.osversion.split(".")[0] < 6)
|
||||
) {
|
||||
o.c = t
|
||||
} else o.x = t
|
||||
result.c = t
|
||||
} else result.x = t
|
||||
|
||||
return o
|
||||
return result
|
||||
}
|
||||
|
||||
var bowser = detect(typeof navigator !== 'undefined' ? navigator.userAgent : '')
|
||||
|
Loading…
Reference in New Issue
Block a user