mirror of
https://github.com/lancedikson/bowser
synced 2024-10-27 20:34:22 +00:00
62a55250f8
- grade A now requires (minimum) Chrome 10, Firefox 4, and Opera 10 - bump minor package version
109 lines
3.6 KiB
JavaScript
109 lines
3.6 KiB
JavaScript
/*!
|
|
* Bowser - a browser detector
|
|
* https://github.com/ded/bowser
|
|
* MIT License | (c) Dustin Diaz 2011
|
|
*/
|
|
!function (name, definition) {
|
|
if (typeof define == 'function') define(definition)
|
|
else if (typeof module != 'undefined' && module.exports) module.exports['browser'] = definition()
|
|
else this[name] = definition()
|
|
}('bowser', function () {
|
|
/**
|
|
* navigator.userAgent =>
|
|
* Chrome: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.57 Safari/534.24"
|
|
* Opera: "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.7; U; en) Presto/2.7.62 Version/11.01"
|
|
* Safari: "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1"
|
|
* IE: "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)"
|
|
* Firefox: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0) Gecko/20100101 Firefox/4.0"
|
|
* iPhone: "Mozilla/5.0 (iPhone Simulator; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5"
|
|
* iPad: "Mozilla/5.0 (iPad; U; CPU OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5",
|
|
* Android: "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; T-Mobile G2 Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
|
|
*/
|
|
|
|
var ua = navigator.userAgent
|
|
, t = true
|
|
, ie = /msie/i.test(ua)
|
|
, chrome = /chrome/i.test(ua)
|
|
, safari = /safari/i.test(ua) && !chrome
|
|
, iphone = /iphone/i.test(ua)
|
|
, ipad = /ipad/i.test(ua)
|
|
, android = /android/i.test(ua)
|
|
, opera = /opera/i.test(ua)
|
|
, firefox = /firefox/i.test(ua)
|
|
, gecko = /gecko\//i.test(ua)
|
|
, webkitVersion = /version\/(\d+(\.\d+)?)/i
|
|
|
|
function detect() {
|
|
|
|
if (ie) return {
|
|
msie: t
|
|
, version: ua.match(/msie (\d+(\.\d+)?);/i)[1]
|
|
}
|
|
if (chrome) return {
|
|
webkit: t
|
|
, chrome: t
|
|
, version: ua.match(/chrome\/(\d+(\.\d+)?)/i)[1]
|
|
}
|
|
if (iphone) return {
|
|
webkit: t
|
|
, iphone: t
|
|
, mobile: t
|
|
, ios: t
|
|
, version: ua.match(webkitVersion)[1]
|
|
}
|
|
if (ipad) return {
|
|
webkit: t
|
|
, ipad: t
|
|
, mobile: t
|
|
, ios: t
|
|
, version: ua.match(webkitVersion)[1]
|
|
}
|
|
if (android) return {
|
|
webkit: t
|
|
, android: t
|
|
, mobile: t
|
|
, version: ua.match(webkitVersion)[1]
|
|
}
|
|
if (safari) return {
|
|
webkit: t
|
|
, safari: t
|
|
, version: ua.match(webkitVersion)[1]
|
|
}
|
|
if (opera) return {
|
|
opera: t
|
|
, version: ua.match(webkitVersion)[1]
|
|
}
|
|
if (gecko) {
|
|
var o = {
|
|
gecko: t
|
|
, version: ua.match(/firefox\/(\d+(\.\d+)?)/i)[1]
|
|
}
|
|
if (firefox) o.firefox = t
|
|
return o
|
|
}
|
|
|
|
}
|
|
|
|
var bowser = detect()
|
|
|
|
// Graded Browser Support
|
|
// http://developer.yahoo.com/yui/articles/gbs
|
|
if ((bowser.msie && bowser.version >= 6) ||
|
|
(bowser.chrome && bowser.version >= 10) ||
|
|
(bowser.firefox && bowser.version >= 4.0) ||
|
|
(bowser.safari && bowser.version >= 5) ||
|
|
(bowser.opera && bowser.version >= 10.0)) {
|
|
bowser.a = t;
|
|
}
|
|
|
|
else if ((bowser.msie && bowser.version < 6) ||
|
|
(bowser.chrome && bowser.version < 10) ||
|
|
(bowser.firefox && bowser.version < 4.0) ||
|
|
(bowser.safari && bowser.version < 5) ||
|
|
(bowser.opera && bowser.version < 10.0)) {
|
|
bowser.c = t
|
|
} else bowser.x = t
|
|
|
|
return bowser
|
|
})
|