mirror of
https://github.com/lancedikson/bowser
synced 2024-10-27 20:34:22 +00:00
rebuild
This commit is contained in:
parent
bb35c3ddaf
commit
bb0e3392a3
54
bowser.js
54
bowser.js
@ -22,9 +22,15 @@
|
|||||||
return (match && match.length > 1 && match[1]) || '';
|
return (match && match.length > 1 && match[1]) || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSecondMatch(regex) {
|
||||||
|
var match = ua.match(regex);
|
||||||
|
return (match && match.length > 1 && match[2]) || '';
|
||||||
|
}
|
||||||
|
|
||||||
var iosdevice = getFirstMatch(/(ipod|iphone|ipad)/i).toLowerCase()
|
var iosdevice = getFirstMatch(/(ipod|iphone|ipad)/i).toLowerCase()
|
||||||
, likeAndroid = /like android/i.test(ua)
|
, likeAndroid = /like android/i.test(ua)
|
||||||
, android = !likeAndroid && /android/i.test(ua)
|
, android = !likeAndroid && /android/i.test(ua)
|
||||||
|
, edgeVersion = getFirstMatch(/edge\/(\d+(\.\d+)?)/i)
|
||||||
, versionIdentifier = getFirstMatch(/version\/(\d+(\.\d+)?)/i)
|
, versionIdentifier = getFirstMatch(/version\/(\d+(\.\d+)?)/i)
|
||||||
, tablet = /tablet/i.test(ua)
|
, tablet = /tablet/i.test(ua)
|
||||||
, mobile = !tablet && /[^-]mobi/i.test(ua)
|
, mobile = !tablet && /[^-]mobi/i.test(ua)
|
||||||
@ -41,8 +47,14 @@
|
|||||||
result = {
|
result = {
|
||||||
name: 'Windows Phone'
|
name: 'Windows Phone'
|
||||||
, windowsphone: t
|
, windowsphone: t
|
||||||
, msie: t
|
}
|
||||||
, version: getFirstMatch(/iemobile\/(\d+(\.\d+)?)/i)
|
if (edgeVersion) {
|
||||||
|
result.msedge = t
|
||||||
|
result.version = edgeVersion
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result.msie = t
|
||||||
|
result.version = getFirstMatch(/iemobile\/(\d+(\.\d+)?)/i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (/msie|trident/i.test(ua)) {
|
else if (/msie|trident/i.test(ua)) {
|
||||||
@ -52,6 +64,13 @@
|
|||||||
, version: getFirstMatch(/(?:msie |rv:)(\d+(\.\d+)?)/i)
|
, version: getFirstMatch(/(?:msie |rv:)(\d+(\.\d+)?)/i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (/chrome.+? edge/i.test(ua)) {
|
||||||
|
result = {
|
||||||
|
name: 'Microsoft Edge'
|
||||||
|
, msedge: t
|
||||||
|
, version: edgeVersion
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (/chrome|crios|crmo/i.test(ua)) {
|
else if (/chrome|crios|crmo/i.test(ua)) {
|
||||||
result = {
|
result = {
|
||||||
name: 'Chrome'
|
name: 'Chrome'
|
||||||
@ -148,10 +167,15 @@
|
|||||||
, version: versionIdentifier
|
, version: versionIdentifier
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else result = {}
|
else {
|
||||||
|
result = {
|
||||||
|
name: getFirstMatch(/^(.*)\/(.*) /),
|
||||||
|
version: getSecondMatch(/^(.*)\/(.*) /)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// set webkit or gecko flag for browsers based on these engines
|
// set webkit or gecko flag for browsers based on these engines
|
||||||
if (/(apple)?webkit/i.test(ua)) {
|
if (!result.msedge && /(apple)?webkit/i.test(ua)) {
|
||||||
result.name = result.name || "Webkit"
|
result.name = result.name || "Webkit"
|
||||||
result.webkit = t
|
result.webkit = t
|
||||||
if (!result.version && versionIdentifier) {
|
if (!result.version && versionIdentifier) {
|
||||||
@ -164,7 +188,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set OS flags for platforms that have multiple browsers
|
// set OS flags for platforms that have multiple browsers
|
||||||
if (android || result.silk) {
|
if (!result.msedge && (android || result.silk)) {
|
||||||
result.android = t
|
result.android = t
|
||||||
} else if (iosdevice) {
|
} else if (iosdevice) {
|
||||||
result[iosdevice] = t
|
result[iosdevice] = t
|
||||||
@ -173,13 +197,13 @@
|
|||||||
|
|
||||||
// OS version extraction
|
// OS version extraction
|
||||||
var osVersion = '';
|
var osVersion = '';
|
||||||
if (iosdevice) {
|
if (result.windowsphone) {
|
||||||
|
osVersion = getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i);
|
||||||
|
} else if (iosdevice) {
|
||||||
osVersion = getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i);
|
osVersion = getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i);
|
||||||
osVersion = osVersion.replace(/[_\s]/g, '.');
|
osVersion = osVersion.replace(/[_\s]/g, '.');
|
||||||
} else if (android) {
|
} else if (android) {
|
||||||
osVersion = getFirstMatch(/android[ \/-](\d+(\.\d+)*)/i);
|
osVersion = getFirstMatch(/android[ \/-](\d+(\.\d+)*)/i);
|
||||||
} else if (result.windowsphone) {
|
|
||||||
osVersion = getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i);
|
|
||||||
} else if (result.webos) {
|
} else if (result.webos) {
|
||||||
osVersion = getFirstMatch(/(?:web|hpw)os\/(\d+(\.\d+)*)/i);
|
osVersion = getFirstMatch(/(?:web|hpw)os\/(\d+(\.\d+)*)/i);
|
||||||
} else if (result.blackberry) {
|
} else if (result.blackberry) {
|
||||||
@ -203,7 +227,8 @@
|
|||||||
|
|
||||||
// Graded Browser Support
|
// Graded Browser Support
|
||||||
// http://developer.yahoo.com/yui/articles/gbs
|
// http://developer.yahoo.com/yui/articles/gbs
|
||||||
if ((result.msie && result.version >= 10) ||
|
if (result.msedge ||
|
||||||
|
(result.msie && result.version >= 10) ||
|
||||||
(result.chrome && result.version >= 20) ||
|
(result.chrome && result.version >= 20) ||
|
||||||
(result.firefox && result.version >= 20.0) ||
|
(result.firefox && result.version >= 20.0) ||
|
||||||
(result.safari && result.version >= 6) ||
|
(result.safari && result.version >= 6) ||
|
||||||
@ -228,6 +253,17 @@
|
|||||||
|
|
||||||
var bowser = detect(typeof navigator !== 'undefined' ? navigator.userAgent : '')
|
var bowser = detect(typeof navigator !== 'undefined' ? navigator.userAgent : '')
|
||||||
|
|
||||||
|
bowser.test = function (browserList) {
|
||||||
|
for (var i = 0; i < browserList.length; ++i) {
|
||||||
|
var browserItem = browserList[i];
|
||||||
|
if (typeof browserItem=== 'string') {
|
||||||
|
if (browserItem in bowser) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set our detect method to the main bowser object so we can
|
* Set our detect method to the main bowser object so we can
|
||||||
|
2
bowser.min.js
vendored
2
bowser.min.js
vendored
@ -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.amd?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=n(/(ipod|iphone|ipad)/i).toLowerCase(),i=/like android/i.test(t),s=!i&&/android/i.test(t),o=n(/version\/(\d+(\.\d+)?)/i),u=/tablet/i.test(t),a=!u&&/[^-]mobi/i.test(t),f;/opera|opr/i.test(t)?f={name:"Opera",opera:e,version:o||n(/(?:opera|opr)[\s\/](\d+(\.\d+)?)/i)}:/windows phone/i.test(t)?f={name:"Windows Phone",windowsphone:e,msie:e,version:n(/iemobile\/(\d+(\.\d+)?)/i)}:/msie|trident/i.test(t)?f={name:"Internet Explorer",msie:e,version:n(/(?:msie |rv:)(\d+(\.\d+)?)/i)}:/chrome|crios|crmo/i.test(t)?f={name:"Chrome",chrome:e,version:n(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)}:r?(f={name:r=="iphone"?"iPhone":r=="ipad"?"iPad":"iPod"},o&&(f.version=o)):/sailfish/i.test(t)?f={name:"Sailfish",sailfish:e,version:n(/sailfish\s?browser\/(\d+(\.\d+)?)/i)}:/seamonkey\//i.test(t)?f={name:"SeaMonkey",seamonkey:e,version:n(/seamonkey\/(\d+(\.\d+)?)/i)}:/firefox|iceweasel/i.test(t)?(f={name:"Firefox",firefox:e,version:n(/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i)},/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(t)&&(f.firefoxos=e)):/silk/i.test(t)?f={name:"Amazon Silk",silk:e,version:n(/silk\/(\d+(\.\d+)?)/i)}:s?f={name:"Android",version:o}:/phantom/i.test(t)?f={name:"PhantomJS",phantom:e,version:n(/phantomjs\/(\d+(\.\d+)?)/i)}:/blackberry|\bbb\d+/i.test(t)||/rim\stablet/i.test(t)?f={name:"BlackBerry",blackberry:e,version:o||n(/blackberry[\d]+\/(\d+(\.\d+)?)/i)}:/(web|hpw)os/i.test(t)?(f={name:"WebOS",webos:e,version:o||n(/w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i)},/touchpad\//i.test(t)&&(f.touchpad=e)):/bada/i.test(t)?f={name:"Bada",bada:e,version:n(/dolfin\/(\d+(\.\d+)?)/i)}:/tizen/i.test(t)?f={name:"Tizen",tizen:e,version:n(/(?:tizen\s?)?browser\/(\d+(\.\d+)?)/i)||o}:/safari/i.test(t)?f={name:"Safari",safari:e,version:o}:f={},/(apple)?webkit/i.test(t)?(f.name=f.name||"Webkit",f.webkit=e,!f.version&&o&&(f.version=o)):!f.opera&&/gecko\//i.test(t)&&(f.name=f.name||"Gecko",f.gecko=e,f.version=f.version||n(/gecko\/(\d+(\.\d+)?)/i)),s||f.silk?f.android=e:r&&(f[r]=e,f.ios=e);var l="";r?(l=n(/os (\d+([_\s]\d+)*) like mac os x/i),l=l.replace(/[_\s]/g,".")):s?l=n(/android[ \/-](\d+(\.\d+)*)/i):f.windowsphone?l=n(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i):f.webos?l=n(/(?:web|hpw)os\/(\d+(\.\d+)*)/i):f.blackberry?l=n(/rim\stablet\sos\s(\d+(\.\d+)*)/i):f.bada?l=n(/bada\/(\d+(\.\d+)*)/i):f.tizen&&(l=n(/tizen[\/\s](\d+(\.\d+)*)/i)),l&&(f.osversion=l);var c=l.split(".")[0];if(u||r=="ipad"||s&&(c==3||c==4&&!a)||f.silk)f.tablet=e;else if(a||r=="iphone"||r=="ipod"||s||f.blackberry||f.webos||f.bada)f.mobile=e;return f.msie&&f.version>=10||f.chrome&&f.version>=20||f.firefox&&f.version>=20||f.safari&&f.version>=6||f.opera&&f.version>=10||f.ios&&f.osversion&&f.osversion.split(".")[0]>=6||f.blackberry&&f.version>=10.1?f.a=e:f.msie&&f.version<10||f.chrome&&f.version<20||f.firefox&&f.version<20||f.safari&&f.version<6||f.opera&&f.version<10||f.ios&&f.osversion&&f.osversion.split(".")[0]<6?f.c=e:f.x=e,f}var e=!0,n=t(typeof navigator!="undefined"?navigator.userAgent:"");return n._detect=t,n})
|
!function(e,t){typeof module!="undefined"&&module.exports?module.exports.browser=t():typeof define=="function"&&define.amd?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]||""}function r(e){var n=t.match(e);return n&&n.length>1&&n[2]||""}var i=n(/(ipod|iphone|ipad)/i).toLowerCase(),s=/like android/i.test(t),o=!s&&/android/i.test(t),u=n(/edge\/(\d+(\.\d+)?)/i),a=n(/version\/(\d+(\.\d+)?)/i),f=/tablet/i.test(t),l=!f&&/[^-]mobi/i.test(t),c;/opera|opr/i.test(t)?c={name:"Opera",opera:e,version:a||n(/(?:opera|opr)[\s\/](\d+(\.\d+)?)/i)}:/windows phone/i.test(t)?(c={name:"Windows Phone",windowsphone:e},u?(c.msedge=e,c.version=u):(c.msie=e,c.version=n(/iemobile\/(\d+(\.\d+)?)/i))):/msie|trident/i.test(t)?c={name:"Internet Explorer",msie:e,version:n(/(?:msie |rv:)(\d+(\.\d+)?)/i)}:/chrome.+? edge/i.test(t)?c={name:"Microsoft Edge",msedge:e,version:u}:/chrome|crios|crmo/i.test(t)?c={name:"Chrome",chrome:e,version:n(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)}:i?(c={name:i=="iphone"?"iPhone":i=="ipad"?"iPad":"iPod"},a&&(c.version=a)):/sailfish/i.test(t)?c={name:"Sailfish",sailfish:e,version:n(/sailfish\s?browser\/(\d+(\.\d+)?)/i)}:/seamonkey\//i.test(t)?c={name:"SeaMonkey",seamonkey:e,version:n(/seamonkey\/(\d+(\.\d+)?)/i)}:/firefox|iceweasel/i.test(t)?(c={name:"Firefox",firefox:e,version:n(/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i)},/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(t)&&(c.firefoxos=e)):/silk/i.test(t)?c={name:"Amazon Silk",silk:e,version:n(/silk\/(\d+(\.\d+)?)/i)}:o?c={name:"Android",version:a}:/phantom/i.test(t)?c={name:"PhantomJS",phantom:e,version:n(/phantomjs\/(\d+(\.\d+)?)/i)}:/blackberry|\bbb\d+/i.test(t)||/rim\stablet/i.test(t)?c={name:"BlackBerry",blackberry:e,version:a||n(/blackberry[\d]+\/(\d+(\.\d+)?)/i)}:/(web|hpw)os/i.test(t)?(c={name:"WebOS",webos:e,version:a||n(/w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i)},/touchpad\//i.test(t)&&(c.touchpad=e)):/bada/i.test(t)?c={name:"Bada",bada:e,version:n(/dolfin\/(\d+(\.\d+)?)/i)}:/tizen/i.test(t)?c={name:"Tizen",tizen:e,version:n(/(?:tizen\s?)?browser\/(\d+(\.\d+)?)/i)||a}:/safari/i.test(t)?c={name:"Safari",safari:e,version:a}:c={name:n(/^(.*)\/(.*) /),version:r(/^(.*)\/(.*) /)},!c.msedge&&/(apple)?webkit/i.test(t)?(c.name=c.name||"Webkit",c.webkit=e,!c.version&&a&&(c.version=a)):!c.opera&&/gecko\//i.test(t)&&(c.name=c.name||"Gecko",c.gecko=e,c.version=c.version||n(/gecko\/(\d+(\.\d+)?)/i)),!c.msedge&&(o||c.silk)?c.android=e:i&&(c[i]=e,c.ios=e);var h="";c.windowsphone?h=n(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i):i?(h=n(/os (\d+([_\s]\d+)*) like mac os x/i),h=h.replace(/[_\s]/g,".")):o?h=n(/android[ \/-](\d+(\.\d+)*)/i):c.webos?h=n(/(?:web|hpw)os\/(\d+(\.\d+)*)/i):c.blackberry?h=n(/rim\stablet\sos\s(\d+(\.\d+)*)/i):c.bada?h=n(/bada\/(\d+(\.\d+)*)/i):c.tizen&&(h=n(/tizen[\/\s](\d+(\.\d+)*)/i)),h&&(c.osversion=h);var p=h.split(".")[0];if(f||i=="ipad"||o&&(p==3||p==4&&!l)||c.silk)c.tablet=e;else if(l||i=="iphone"||i=="ipod"||o||c.blackberry||c.webos||c.bada)c.mobile=e;return c.msedge||c.msie&&c.version>=10||c.chrome&&c.version>=20||c.firefox&&c.version>=20||c.safari&&c.version>=6||c.opera&&c.version>=10||c.ios&&c.osversion&&c.osversion.split(".")[0]>=6||c.blackberry&&c.version>=10.1?c.a=e:c.msie&&c.version<10||c.chrome&&c.version<20||c.firefox&&c.version<20||c.safari&&c.version<6||c.opera&&c.version<10||c.ios&&c.osversion&&c.osversion.split(".")[0]<6?c.c=e:c.x=e,c}var e=!0,n=t(typeof navigator!="undefined"?navigator.userAgent:"");return n.test=function(e){for(var t=0;t<e.length;++t){var r=e[t];if(typeof r=="string"&&r in n)return!0}return!1},n._detect=t,n})
|
Loading…
Reference in New Issue
Block a user