2011-09-26 23:58:18 +00:00
|
|
|
/*!
|
|
|
|
* Bowser - a browser detector
|
|
|
|
* https://github.com/ded/bowser
|
2015-07-26 02:15:11 +00:00
|
|
|
* MIT License | (c) Dustin Diaz 2015
|
2011-09-26 23:58:18 +00:00
|
|
|
*/
|
2013-08-16 20:03:14 +00:00
|
|
|
|
2011-09-26 23:58:18 +00:00
|
|
|
!function (name, definition) {
|
2015-07-26 02:15:11 +00:00
|
|
|
if (typeof module != 'undefined' && module.exports) module.exports = definition()
|
2014-10-06 18:01:25 +00:00
|
|
|
else if (typeof define == 'function' && define.amd) define(definition)
|
2011-09-26 23:58:18 +00:00
|
|
|
else this[name] = definition()
|
|
|
|
}('bowser', function () {
|
2011-04-27 22:14:35 +00:00
|
|
|
/**
|
2014-02-20 22:17:59 +00:00
|
|
|
* See useragents.js for examples of navigator.userAgent
|
2012-04-17 01:54:24 +00:00
|
|
|
*/
|
2011-04-27 22:14:35 +00:00
|
|
|
|
2014-02-25 22:34:03 +00:00
|
|
|
var t = true
|
2014-02-21 00:23:58 +00:00
|
|
|
|
2014-02-20 22:17:59 +00:00
|
|
|
function detect(ua) {
|
2011-04-27 22:14:35 +00:00
|
|
|
|
2014-02-28 00:58:30 +00:00
|
|
|
function getFirstMatch(regex) {
|
2014-02-25 22:34:03 +00:00
|
|
|
var match = ua.match(regex);
|
|
|
|
return (match && match.length > 1 && match[1]) || '';
|
|
|
|
}
|
|
|
|
|
2015-05-21 17:38:55 +00:00
|
|
|
function getSecondMatch(regex) {
|
|
|
|
var match = ua.match(regex);
|
|
|
|
return (match && match.length > 1 && match[2]) || '';
|
|
|
|
}
|
|
|
|
|
2014-02-28 00:58:30 +00:00
|
|
|
var iosdevice = getFirstMatch(/(ipod|iphone|ipad)/i).toLowerCase()
|
2014-02-25 22:34:03 +00:00
|
|
|
, likeAndroid = /like android/i.test(ua)
|
|
|
|
, android = !likeAndroid && /android/i.test(ua)
|
2016-01-27 10:52:49 +00:00
|
|
|
, nexusMobile = /nexus\s*[4-6]\s*/i.test(ua)
|
|
|
|
, nexusTablet = !nexusMobile && /nexus\s*[0-9]+/i.test(ua)
|
|
|
|
, chromeos = /CrOS/.test(ua)
|
|
|
|
, silk = /silk/i.test(ua)
|
|
|
|
, sailfish = /sailfish/i.test(ua)
|
|
|
|
, tizen = /tizen/i.test(ua)
|
|
|
|
, webos = /(web|hpw)os/i.test(ua)
|
|
|
|
, windowsphone = /windows phone/i.test(ua)
|
|
|
|
, windows = !windowsphone && /windows/i.test(ua)
|
|
|
|
, mac = !iosdevice && !silk && /macintosh/i.test(ua)
|
|
|
|
, linux = !android && !sailfish && !tizen && !webos && /linux/i.test(ua)
|
2015-05-21 17:38:55 +00:00
|
|
|
, edgeVersion = getFirstMatch(/edge\/(\d+(\.\d+)?)/i)
|
2014-02-28 00:58:30 +00:00
|
|
|
, versionIdentifier = getFirstMatch(/version\/(\d+(\.\d+)?)/i)
|
2014-02-24 21:55:24 +00:00
|
|
|
, tablet = /tablet/i.test(ua)
|
2014-02-28 00:58:30 +00:00
|
|
|
, mobile = !tablet && /[^-]mobi/i.test(ua)
|
2014-02-25 22:34:03 +00:00
|
|
|
, result
|
2014-02-20 23:02:13 +00:00
|
|
|
|
2014-02-28 00:58:30 +00:00
|
|
|
if (/opera|opr/i.test(ua)) {
|
2014-02-25 22:34:03 +00:00
|
|
|
result = {
|
2013-12-05 20:00:02 +00:00
|
|
|
name: 'Opera'
|
|
|
|
, opera: t
|
2014-02-28 00:58:30 +00:00
|
|
|
, version: versionIdentifier || getFirstMatch(/(?:opera|opr)[\s\/](\d+(\.\d+)?)/i)
|
|
|
|
}
|
|
|
|
}
|
2015-05-27 12:56:19 +00:00
|
|
|
else if (/yabrowser/i.test(ua)) {
|
|
|
|
result = {
|
|
|
|
name: 'Yandex Browser'
|
|
|
|
, yandexbrowser: t
|
|
|
|
, version: versionIdentifier || getFirstMatch(/(?:yabrowser)[\s\/](\d+(\.\d+)?)/i)
|
|
|
|
}
|
|
|
|
}
|
2016-01-27 10:52:49 +00:00
|
|
|
else if (windowsphone) {
|
2014-02-28 00:58:30 +00:00
|
|
|
result = {
|
|
|
|
name: 'Windows Phone'
|
|
|
|
, windowsphone: t
|
2015-05-21 17:38:55 +00:00
|
|
|
}
|
|
|
|
if (edgeVersion) {
|
|
|
|
result.msedge = t
|
|
|
|
result.version = edgeVersion
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result.msie = t
|
|
|
|
result.version = getFirstMatch(/iemobile\/(\d+(\.\d+)?)/i)
|
2013-08-16 19:58:39 +00:00
|
|
|
}
|
2014-02-21 00:23:58 +00:00
|
|
|
}
|
2014-02-28 00:58:30 +00:00
|
|
|
else if (/msie|trident/i.test(ua)) {
|
|
|
|
result = {
|
2014-02-20 22:17:59 +00:00
|
|
|
name: 'Internet Explorer'
|
|
|
|
, msie: t
|
2014-02-28 00:58:30 +00:00
|
|
|
, version: getFirstMatch(/(?:msie |rv:)(\d+(\.\d+)?)/i)
|
2014-02-20 22:17:59 +00:00
|
|
|
}
|
2016-01-27 10:52:49 +00:00
|
|
|
} else if (chromeos) {
|
2015-07-26 02:15:11 +00:00
|
|
|
result = {
|
|
|
|
name: 'Chrome'
|
2016-01-27 10:52:49 +00:00
|
|
|
, chromeos: t
|
2015-07-26 02:15:11 +00:00
|
|
|
, chromeBook: t
|
|
|
|
, chrome: t
|
|
|
|
, version: getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)
|
|
|
|
}
|
|
|
|
} else if (/chrome.+? edge/i.test(ua)) {
|
2015-05-21 17:38:55 +00:00
|
|
|
result = {
|
|
|
|
name: 'Microsoft Edge'
|
|
|
|
, msedge: t
|
|
|
|
, version: edgeVersion
|
|
|
|
}
|
|
|
|
}
|
2014-02-28 00:58:30 +00:00
|
|
|
else if (/chrome|crios|crmo/i.test(ua)) {
|
2014-02-25 22:34:03 +00:00
|
|
|
result = {
|
2013-12-05 20:00:02 +00:00
|
|
|
name: 'Chrome'
|
2011-09-26 23:58:18 +00:00
|
|
|
, chrome: t
|
2014-02-28 00:58:30 +00:00
|
|
|
, version: getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)
|
2014-02-21 12:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-28 00:58:30 +00:00
|
|
|
else if (iosdevice) {
|
|
|
|
result = {
|
|
|
|
name : iosdevice == 'iphone' ? 'iPhone' : iosdevice == 'ipad' ? 'iPad' : 'iPod'
|
2013-08-16 19:58:39 +00:00
|
|
|
}
|
2014-02-28 00:58:30 +00:00
|
|
|
// WTF: version is not part of user agent in web apps
|
|
|
|
if (versionIdentifier) {
|
|
|
|
result.version = versionIdentifier
|
|
|
|
}
|
|
|
|
}
|
2016-01-27 10:52:49 +00:00
|
|
|
else if (sailfish) {
|
2014-02-28 00:58:30 +00:00
|
|
|
result = {
|
2014-02-28 18:53:50 +00:00
|
|
|
name: 'Sailfish'
|
|
|
|
, sailfish: t
|
|
|
|
, version: getFirstMatch(/sailfish\s?browser\/(\d+(\.\d+)?)/i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (/seamonkey\//i.test(ua)) {
|
|
|
|
result = {
|
|
|
|
name: 'SeaMonkey'
|
|
|
|
, seamonkey: t
|
|
|
|
, version: getFirstMatch(/seamonkey\/(\d+(\.\d+)?)/i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (/firefox|iceweasel/i.test(ua)) {
|
|
|
|
result = {
|
|
|
|
name: 'Firefox'
|
|
|
|
, firefox: t
|
2014-02-28 00:58:30 +00:00
|
|
|
, version: getFirstMatch(/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i)
|
|
|
|
}
|
2014-02-28 18:53:50 +00:00
|
|
|
if (/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(ua)) {
|
|
|
|
result.firefoxos = t
|
2014-02-28 00:58:30 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-27 10:52:49 +00:00
|
|
|
else if (silk) {
|
2014-02-28 00:58:30 +00:00
|
|
|
result = {
|
2014-02-20 22:17:59 +00:00
|
|
|
name: 'Amazon Silk'
|
2014-02-24 00:16:33 +00:00
|
|
|
, silk: t
|
2014-02-28 00:58:30 +00:00
|
|
|
, version : getFirstMatch(/silk\/(\d+(\.\d+)?)/i)
|
2014-02-20 22:17:59 +00:00
|
|
|
}
|
2014-02-28 00:58:30 +00:00
|
|
|
}
|
|
|
|
else if (android) {
|
2014-02-25 22:34:03 +00:00
|
|
|
result = {
|
2014-02-28 00:58:30 +00:00
|
|
|
name: 'Android'
|
|
|
|
, version: versionIdentifier
|
2012-01-24 09:58:00 +00:00
|
|
|
}
|
2014-02-28 00:58:30 +00:00
|
|
|
}
|
|
|
|
else if (/phantom/i.test(ua)) {
|
|
|
|
result = {
|
|
|
|
name: 'PhantomJS'
|
|
|
|
, phantom: t
|
|
|
|
, version: getFirstMatch(/phantomjs\/(\d+(\.\d+)?)/i)
|
2012-01-24 09:58:00 +00:00
|
|
|
}
|
2011-04-27 22:14:35 +00:00
|
|
|
}
|
2014-02-28 00:58:30 +00:00
|
|
|
else if (/blackberry|\bbb\d+/i.test(ua) || /rim\stablet/i.test(ua)) {
|
2014-02-25 22:34:03 +00:00
|
|
|
result = {
|
2014-02-20 22:17:59 +00:00
|
|
|
name: 'BlackBerry'
|
|
|
|
, blackberry: t
|
2014-02-28 00:58:30 +00:00
|
|
|
, version: versionIdentifier || getFirstMatch(/blackberry[\d]+\/(\d+(\.\d+)?)/i)
|
2014-02-20 22:17:59 +00:00
|
|
|
}
|
2014-04-07 23:57:27 +00:00
|
|
|
}
|
2016-01-27 10:52:49 +00:00
|
|
|
else if (webos) {
|
2014-02-25 22:34:03 +00:00
|
|
|
result = {
|
2014-02-20 22:17:59 +00:00
|
|
|
name: 'WebOS'
|
|
|
|
, webos: t
|
2014-02-28 00:58:30 +00:00
|
|
|
, version: versionIdentifier || getFirstMatch(/w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i)
|
2014-02-24 00:16:33 +00:00
|
|
|
};
|
2014-02-28 00:58:30 +00:00
|
|
|
/touchpad\//i.test(ua) && (result.touchpad = t)
|
2014-02-24 00:16:33 +00:00
|
|
|
}
|
2014-02-28 00:58:30 +00:00
|
|
|
else if (/bada/i.test(ua)) {
|
2014-02-25 22:34:03 +00:00
|
|
|
result = {
|
2014-02-24 23:47:02 +00:00
|
|
|
name: 'Bada'
|
|
|
|
, bada: t
|
2014-02-28 00:58:30 +00:00
|
|
|
, version: getFirstMatch(/dolfin\/(\d+(\.\d+)?)/i)
|
2014-02-24 23:47:02 +00:00
|
|
|
};
|
|
|
|
}
|
2016-01-27 10:52:49 +00:00
|
|
|
else if (tizen) {
|
2014-02-25 22:34:03 +00:00
|
|
|
result = {
|
2014-02-25 00:48:35 +00:00
|
|
|
name: 'Tizen'
|
|
|
|
, tizen: t
|
2014-02-28 00:58:30 +00:00
|
|
|
, version: getFirstMatch(/(?:tizen\s?)?browser\/(\d+(\.\d+)?)/i) || versionIdentifier
|
2014-02-25 00:48:35 +00:00
|
|
|
};
|
|
|
|
}
|
2014-02-28 00:58:30 +00:00
|
|
|
else if (/safari/i.test(ua)) {
|
2014-02-25 22:34:03 +00:00
|
|
|
result = {
|
2014-02-20 23:02:13 +00:00
|
|
|
name: 'Safari'
|
|
|
|
, safari: t
|
2014-02-25 22:34:03 +00:00
|
|
|
, version: versionIdentifier
|
2014-02-20 23:02:13 +00:00
|
|
|
}
|
2014-02-28 00:58:30 +00:00
|
|
|
}
|
2015-05-21 17:38:55 +00:00
|
|
|
else {
|
|
|
|
result = {
|
|
|
|
name: getFirstMatch(/^(.*)\/(.*) /),
|
|
|
|
version: getSecondMatch(/^(.*)\/(.*) /)
|
|
|
|
};
|
|
|
|
}
|
2011-04-27 22:14:35 +00:00
|
|
|
|
2014-02-28 18:53:50 +00:00
|
|
|
// set webkit or gecko flag for browsers based on these engines
|
2015-05-21 17:38:55 +00:00
|
|
|
if (!result.msedge && /(apple)?webkit/i.test(ua)) {
|
2014-02-28 18:53:50 +00:00
|
|
|
result.name = result.name || "Webkit"
|
|
|
|
result.webkit = t
|
|
|
|
if (!result.version && versionIdentifier) {
|
|
|
|
result.version = versionIdentifier
|
|
|
|
}
|
|
|
|
} else if (!result.opera && /gecko\//i.test(ua)) {
|
|
|
|
result.name = result.name || "Gecko"
|
|
|
|
result.gecko = t
|
|
|
|
result.version = result.version || getFirstMatch(/gecko\/(\d+(\.\d+)?)/i)
|
|
|
|
}
|
|
|
|
|
2014-02-25 22:34:03 +00:00
|
|
|
// set OS flags for platforms that have multiple browsers
|
2015-05-21 17:38:55 +00:00
|
|
|
if (!result.msedge && (android || result.silk)) {
|
2014-02-25 22:34:03 +00:00
|
|
|
result.android = t
|
2014-02-28 00:58:30 +00:00
|
|
|
} else if (iosdevice) {
|
|
|
|
result[iosdevice] = t
|
2014-02-25 22:34:03 +00:00
|
|
|
result.ios = t
|
2016-01-27 10:52:49 +00:00
|
|
|
} else if (windows) {
|
|
|
|
result.windows = t
|
|
|
|
} else if (mac) {
|
|
|
|
result.mac = t
|
|
|
|
} else if (linux) {
|
|
|
|
result.linux = t
|
2014-02-25 22:34:03 +00:00
|
|
|
}
|
2014-02-24 21:55:24 +00:00
|
|
|
|
|
|
|
// OS version extraction
|
2014-02-25 23:22:58 +00:00
|
|
|
var osVersion = '';
|
2015-05-21 17:38:55 +00:00
|
|
|
if (result.windowsphone) {
|
|
|
|
osVersion = getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i);
|
|
|
|
} else if (iosdevice) {
|
2014-02-28 00:58:30 +00:00
|
|
|
osVersion = getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i);
|
2014-02-25 22:34:03 +00:00
|
|
|
osVersion = osVersion.replace(/[_\s]/g, '.');
|
|
|
|
} else if (android) {
|
2014-02-28 00:58:30 +00:00
|
|
|
osVersion = getFirstMatch(/android[ \/-](\d+(\.\d+)*)/i);
|
|
|
|
} else if (result.webos) {
|
|
|
|
osVersion = getFirstMatch(/(?:web|hpw)os\/(\d+(\.\d+)*)/i);
|
|
|
|
} else if (result.blackberry) {
|
|
|
|
osVersion = getFirstMatch(/rim\stablet\sos\s(\d+(\.\d+)*)/i);
|
|
|
|
} else if (result.bada) {
|
|
|
|
osVersion = getFirstMatch(/bada\/(\d+(\.\d+)*)/i);
|
|
|
|
} else if (result.tizen) {
|
|
|
|
osVersion = getFirstMatch(/tizen[\/\s](\d+(\.\d+)*)/i);
|
2014-02-24 00:16:33 +00:00
|
|
|
}
|
|
|
|
if (osVersion) {
|
2014-02-25 22:34:03 +00:00
|
|
|
result.osversion = osVersion;
|
2014-02-21 12:56:57 +00:00
|
|
|
}
|
|
|
|
|
2014-02-24 21:55:24 +00:00
|
|
|
// device type extraction
|
2014-02-25 23:22:58 +00:00
|
|
|
var osMajorVersion = osVersion.split('.')[0];
|
2016-01-27 10:52:49 +00:00
|
|
|
if (tablet || nexusTablet || iosdevice == 'ipad' || (android && (osMajorVersion == 3 || (osMajorVersion == 4 && !mobile))) || result.silk) {
|
2014-02-25 22:34:03 +00:00
|
|
|
result.tablet = t
|
2014-02-28 00:58:30 +00:00
|
|
|
} else if (mobile || iosdevice == 'iphone' || iosdevice == 'ipod' || android || result.blackberry || result.webos || result.bada) {
|
2014-02-25 22:34:03 +00:00
|
|
|
result.mobile = t
|
2014-02-24 21:55:24 +00:00
|
|
|
}
|
|
|
|
|
2014-02-20 22:17:59 +00:00
|
|
|
// Graded Browser Support
|
|
|
|
// http://developer.yahoo.com/yui/articles/gbs
|
2015-05-21 17:38:55 +00:00
|
|
|
if (result.msedge ||
|
|
|
|
(result.msie && result.version >= 10) ||
|
2015-05-27 12:56:19 +00:00
|
|
|
(result.yandexbrowser && result.version >= 15) ||
|
2014-02-25 22:34:03 +00:00
|
|
|
(result.chrome && result.version >= 20) ||
|
2014-04-07 23:57:27 +00:00
|
|
|
(result.firefox && result.version >= 20.0) ||
|
|
|
|
(result.safari && result.version >= 6) ||
|
2014-02-25 22:34:03 +00:00
|
|
|
(result.opera && result.version >= 10.0) ||
|
2014-10-06 18:01:25 +00:00
|
|
|
(result.ios && result.osversion && result.osversion.split(".")[0] >= 6) ||
|
|
|
|
(result.blackberry && result.version >= 10.1)
|
2014-02-21 12:56:57 +00:00
|
|
|
) {
|
2014-02-25 22:34:03 +00:00
|
|
|
result.a = t;
|
2014-02-20 22:17:59 +00:00
|
|
|
}
|
2014-04-07 23:57:27 +00:00
|
|
|
else if ((result.msie && result.version < 10) ||
|
2014-02-25 22:34:03 +00:00
|
|
|
(result.chrome && result.version < 20) ||
|
2014-04-07 23:57:27 +00:00
|
|
|
(result.firefox && result.version < 20.0) ||
|
|
|
|
(result.safari && result.version < 6) ||
|
2014-02-25 22:34:03 +00:00
|
|
|
(result.opera && result.version < 10.0) ||
|
|
|
|
(result.ios && result.osversion && result.osversion.split(".")[0] < 6)
|
2014-02-21 12:56:57 +00:00
|
|
|
) {
|
2014-02-25 22:34:03 +00:00
|
|
|
result.c = t
|
|
|
|
} else result.x = t
|
2014-02-20 22:17:59 +00:00
|
|
|
|
2014-02-25 22:34:03 +00:00
|
|
|
return result
|
2011-05-10 16:50:28 +00:00
|
|
|
}
|
|
|
|
|
2014-02-20 22:17:59 +00:00
|
|
|
var bowser = detect(typeof navigator !== 'undefined' ? navigator.userAgent : '')
|
|
|
|
|
2015-05-21 17:38:55 +00:00
|
|
|
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;
|
|
|
|
}
|
2014-02-20 22:17:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set our detect method to the main bowser object so we can
|
|
|
|
* reuse it to test other user agents.
|
|
|
|
* This is needed to implement future tests.
|
|
|
|
*/
|
|
|
|
bowser._detect = detect;
|
2011-04-27 22:14:35 +00:00
|
|
|
|
2011-09-26 23:58:18 +00:00
|
|
|
return bowser
|
2013-12-03 22:46:08 +00:00
|
|
|
});
|