1
0
mirror of https://github.com/lancedikson/bowser synced 2024-10-27 20:34:22 +00:00

- new flags for mobile with android and iPhone

- bump minor version
This commit is contained in:
Dustin Diaz 2011-09-26 16:58:18 -07:00
parent 1ea37f33da
commit 970d1f1a73
5 changed files with 151 additions and 130 deletions

106
bowser.js
View File

@ -4,7 +4,16 @@
* https://github.com/ded/bowser * https://github.com/ded/bowser
* MIT License * MIT License
*/ */
!function (context) { /*!
* 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 => * 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" * 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"
@ -12,58 +21,66 @@
* 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" * 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)" * 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" * 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"
* 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, var ua = navigator.userAgent
ie = /msie/i.test(ua), , t = true
chrome = /chrome/i.test(ua), , ie = /msie/i.test(ua)
safari = /safari/i.test(ua) && !chrome, , chrome = /chrome/i.test(ua)
opera = /opera/i.test(ua), , safari = /safari/i.test(ua) && !chrome
firefox = /firefox/i.test(ua), , iphone = /iphone/i.test(ua)
gecko = /gecko\//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() { function detect() {
if (ie) { if (ie) return {
return { msie: t
msie: 1, , version: ua.match(/msie (\d+(\.\d+)?);/i)[1]
version: ua.match(/msie (\d+(\.\d+)?);/i)[1]
};
} }
if (chrome) { if (chrome) return {
return { webkit: t
webkit: 1, , chrome: t
chrome: 1, , version: ua.match(/chrome\/(\d+(\.\d+)?)/i)[1]
version: ua.match(/chrome\/(\d+(\.\d+)?)/i)[1]
};
} }
if (safari) { if (iphone) return {
return { webkit: t
webkit: 1, , iphone: t
safari: 1, , mobile: t
version: ua.match(/version\/(\d+(\.\d+)?)/i)[1] , version: ua.match(webkitVersion)[1]
};
} }
if (opera) { if (android) return {
return { webkit: t
opera: 1, , android: t
version: ua.match(/version\/(\d+(\.\d+)?)/i)[1] , 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) { if (gecko) {
var o = { var o = {
gecko: 1, gecko: t
version: ua.match(/firefox\/(\d+(\.\d+)?)/i)[1] , version: ua.match(/firefox\/(\d+(\.\d+)?)/i)[1]
};
if (firefox) {
o.firefox = 1;
} }
return o; if (firefox) o.firefox = t
return o
} }
} }
var bowser = detect(); var bowser = detect()
// Graded Browser Support // Graded Browser Support
// http://developer.yahoo.com/yui/articles/gbs // http://developer.yahoo.com/yui/articles/gbs
@ -72,7 +89,7 @@
(bowser.firefox && bowser.version >= 3.6) || (bowser.firefox && bowser.version >= 3.6) ||
(bowser.safari && bowser.version >= 5) || (bowser.safari && bowser.version >= 5) ||
(bowser.opera && bowser.version >= 9.5)) { (bowser.opera && bowser.version >= 9.5)) {
bowser.a = true; bowser.a = t;
} }
else if ((bowser.msie && bowser.version < 6) || else if ((bowser.msie && bowser.version < 6) ||
@ -80,13 +97,8 @@
(bowser.firefox && bowser.version < 3.6) || (bowser.firefox && bowser.version < 3.6) ||
(bowser.safari && bowser.version < 5) || (bowser.safari && bowser.version < 5) ||
(bowser.opera && bowser.version < 9.5)) { (bowser.opera && bowser.version < 9.5)) {
bowser.c = true; bowser.c = t
} else { } else bowser.x = t
bowser.x = true;
}
typeof module !== 'undefined' && module.exports ? return bowser
(module.exports.browser = bowser) : })
(context.bowser = bowser);
}(this);

5
bowser.min.js vendored
View File

@ -5,8 +5,7 @@
* MIT License * MIT License
*//*! *//*!
* Bowser - a browser detector * Bowser - a browser detector
* copyright Dustin Diaz 2011
* https://github.com/ded/bowser * https://github.com/ded/bowser
* MIT License * MIT License | (c) Dustin Diaz 2011
*/ */
!function(a){function i(){if(c)return{msie:1,version:b.match(/msie (\d+(\.\d+)?);/i)[1]};if(d)return{webkit:1,chrome:1,version:b.match(/chrome\/(\d+(\.\d+)?)/i)[1]};if(e)return{webkit:1,safari:1,version:b.match(/version\/(\d+(\.\d+)?)/i)[1]};if(f)return{opera:1,version:b.match(/version\/(\d+(\.\d+)?)/i)[1]};if(h){var a={gecko:1,version:b.match(/firefox\/(\d+(\.\d+)?)/i)[1]};g&&(a.firefox=1);return a}}var b=navigator.userAgent,c=/msie/i.test(b),d=/chrome/i.test(b),e=/safari/i.test(b)&&!d,f=/opera/i.test(b),g=/firefox/i.test(b),h=/gecko\//i.test(b),j=i();j.msie&&j.version>=6||j.chrome&&j.version>=8||j.firefox&&j.version>=3.6||j.safari&&j.version>=5||j.opera&&j.version>=9.5?j.a=!0:j.msie&&j.version<6||j.chrome&&j.version<8||j.firefox&&j.version<3.6||j.safari&&j.version<5||j.opera&&j.version<9.5?j.c=!0:j.x=!0,typeof module!="undefined"&&module.exports?module.exports.browser=j:a.bowser=j}(this) !function(a,b){typeof define=="function"?define(b):typeof module!="undefined"&&module.exports?module.exports.browser=b():this[a]=b()}("bowser",function(){function l(){if(c)return{msie:b,version:a.match(/msie (\d+(\.\d+)?);/i)[1]};if(d)return{webkit:b,chrome:b,version:a.match(/chrome\/(\d+(\.\d+)?)/i)[1]};if(f)return{webkit:b,iphone:b,mobile:b,version:a.match(k)[1]};if(g)return{webkit:b,android:b,mobile:b,version:a.match(k)[1]};if(e)return{webkit:b,safari:b,version:a.match(k)[1]};if(h)return{opera:b,version:a.match(k)[1]};if(j){var l={gecko:b,version:a.match(/firefox\/(\d+(\.\d+)?)/i)[1]};return i&&(l.firefox=b),l}}var a=navigator.userAgent,b=!0,c=/msie/i.test(a),d=/chrome/i.test(a),e=/safari/i.test(a)&&!d,f=/iphone/i.test(a),g=/android/i.test(a),h=/opera/i.test(a),i=/firefox/i.test(a),j=/gecko\//i.test(a),k=/version\/(\d+(\.\d+)?)/i,m=l();return m.msie&&m.version>=6||m.chrome&&m.version>=8||m.firefox&&m.version>=3.6||m.safari&&m.version>=5||m.opera&&m.version>=9.5?m.a=b:m.msie&&m.version<6||m.chrome&&m.version<8||m.firefox&&m.version<3.6||m.safari&&m.version<5||m.opera&&m.version<9.5?m.c=b:m.x=b,m})

View File

@ -1,24 +1,25 @@
require('smoosh').config({ require('smoosh').config({
"JAVASCRIPT": { "JAVASCRIPT": {
"DIST_DIR": "./", "DIST_DIR": "./"
"bowser": [ , "bowser": [
"./src/copyright.js", "./src/copyright.js"
"./src/bowser.js" , "./src/bowser.js"
] ]
},
"JSHINT_OPTS": {
"boss": true,
"forin": false,
"curly": true,
"debug": false,
"devel": false,
"evil": false,
"regexp": false,
"undef": false,
"sub": false,
"white": true,
"indent": 2,
"whitespace": true,
"asi": false
} }
}).run().build().analyze(); , "JSHINT_OPTS": {
"boss": true
, "forin": false
, "curly": false
, "debug": false
, "devel": false
, "evil": false
, "regexp": false
, "undef": false
, "sub": true
, "white": false
, "indent": 2
, "whitespace": true
, "asi": true
, "laxbreak": true
}
}).run().build().analyze()

View File

@ -1,13 +1,16 @@
{ {
"name": "bowser", "name": "bowser"
"description": "a browser detector", , "description": "a browser detector"
"keywords": ["ender", "browser", "sniff", "detection"], , "keywords": ["ender", "browser", "sniff", "detection"]
"version": "0.0.5", , "version": "0.0.6"
"homepage": "https://github.com/ded/bowser", , "homepage": "https://github.com/ded/bowser"
"author": "Dustin Diaz <@ded>", , "author": "Dustin Diaz <dustin@dustindiaz.com> (http://dustindiaz.com)"
"repository": { , "main": "./bowser.js"
"type": "git", , "repository": {
"url": "https://github.com/ded/bowser.git" "type": "git"
}, , "url": "https://github.com/ded/bowser.git"
"main": "./bowser.js" }
, "devDependencies": {
"smoosh": "*"
}
} }

View File

@ -1,10 +1,13 @@
/*! /*!
* Bowser - a browser detector * Bowser - a browser detector
* copyright Dustin Diaz 2011
* https://github.com/ded/bowser * https://github.com/ded/bowser
* MIT License * MIT License | (c) Dustin Diaz 2011
*/ */
!function (context) { !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 => * 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" * 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"
@ -12,58 +15,66 @@
* 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" * 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)" * 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" * 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"
* 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, var ua = navigator.userAgent
ie = /msie/i.test(ua), , t = true
chrome = /chrome/i.test(ua), , ie = /msie/i.test(ua)
safari = /safari/i.test(ua) && !chrome, , chrome = /chrome/i.test(ua)
opera = /opera/i.test(ua), , safari = /safari/i.test(ua) && !chrome
firefox = /firefox/i.test(ua), , iphone = /iphone/i.test(ua)
gecko = /gecko\//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() { function detect() {
if (ie) { if (ie) return {
return { msie: t
msie: 1, , version: ua.match(/msie (\d+(\.\d+)?);/i)[1]
version: ua.match(/msie (\d+(\.\d+)?);/i)[1]
};
} }
if (chrome) { if (chrome) return {
return { webkit: t
webkit: 1, , chrome: t
chrome: 1, , version: ua.match(/chrome\/(\d+(\.\d+)?)/i)[1]
version: ua.match(/chrome\/(\d+(\.\d+)?)/i)[1]
};
} }
if (safari) { if (iphone) return {
return { webkit: t
webkit: 1, , iphone: t
safari: 1, , mobile: t
version: ua.match(/version\/(\d+(\.\d+)?)/i)[1] , version: ua.match(webkitVersion)[1]
};
} }
if (opera) { if (android) return {
return { webkit: t
opera: 1, , android: t
version: ua.match(/version\/(\d+(\.\d+)?)/i)[1] , 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) { if (gecko) {
var o = { var o = {
gecko: 1, gecko: t
version: ua.match(/firefox\/(\d+(\.\d+)?)/i)[1] , version: ua.match(/firefox\/(\d+(\.\d+)?)/i)[1]
};
if (firefox) {
o.firefox = 1;
} }
return o; if (firefox) o.firefox = t
return o
} }
} }
var bowser = detect(); var bowser = detect()
// Graded Browser Support // Graded Browser Support
// http://developer.yahoo.com/yui/articles/gbs // http://developer.yahoo.com/yui/articles/gbs
@ -72,7 +83,7 @@
(bowser.firefox && bowser.version >= 3.6) || (bowser.firefox && bowser.version >= 3.6) ||
(bowser.safari && bowser.version >= 5) || (bowser.safari && bowser.version >= 5) ||
(bowser.opera && bowser.version >= 9.5)) { (bowser.opera && bowser.version >= 9.5)) {
bowser.a = true; bowser.a = t;
} }
else if ((bowser.msie && bowser.version < 6) || else if ((bowser.msie && bowser.version < 6) ||
@ -80,13 +91,8 @@
(bowser.firefox && bowser.version < 3.6) || (bowser.firefox && bowser.version < 3.6) ||
(bowser.safari && bowser.version < 5) || (bowser.safari && bowser.version < 5) ||
(bowser.opera && bowser.version < 9.5)) { (bowser.opera && bowser.version < 9.5)) {
bowser.c = true; bowser.c = t
} else { } else bowser.x = t
bowser.x = true;
}
typeof module !== 'undefined' && module.exports ? return bowser
(module.exports.browser = bowser) : })
(context.bowser = bowser);
}(this);