mirror of
https://github.com/lancedikson/bowser
synced 2024-10-27 20:34:22 +00:00
boosh
This commit is contained in:
commit
a1505c4fb0
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules
|
42
README.md
Normal file
42
README.md
Normal file
@ -0,0 +1,42 @@
|
||||
Bowser
|
||||
------
|
||||
A Browser detector. Because sometimes, there is no other way, and not even good modern browser provide good feature detection mechanisms.
|
||||
|
||||
Works like this:
|
||||
|
||||
if (bowser().msie && bowser().version <= 6) {
|
||||
alert('hello China');
|
||||
}
|
||||
|
||||
Detected Browsers
|
||||
-----
|
||||
|
||||
* msie
|
||||
* safari[webkit]
|
||||
* chrome[webkit]
|
||||
* firefox[gecko]
|
||||
* opera
|
||||
|
||||
Notes
|
||||
----
|
||||
safari,chrome, and firefox will report that they have webkit|gecko engines
|
||||
|
||||
if (bowser().webkit) {
|
||||
// do stuff with safari & chrome
|
||||
}
|
||||
|
||||
Ender installation
|
||||
-----
|
||||
If you don't already have [Ender](http://ender.no.de) (an npm package) install it now (and don't look back)
|
||||
|
||||
$ npm install ender
|
||||
|
||||
then add bowser to your module collection
|
||||
|
||||
$ ender add bowser
|
||||
|
||||
use it like this:
|
||||
|
||||
if ($.browser().chrome) {
|
||||
alert('Hello Silicon Valley');
|
||||
}
|
70
bowser.js
Normal file
70
bowser.js
Normal file
@ -0,0 +1,70 @@
|
||||
/*!
|
||||
* Bowser - a browser detector
|
||||
* copyright Dustin Diaz 2011
|
||||
* https://github.com/ded/bowser
|
||||
* MIT License
|
||||
*/
|
||||
!function (context) {
|
||||
/**
|
||||
* 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"
|
||||
*/
|
||||
|
||||
var ua = navigator.userAgent,
|
||||
ie = /msie/i.test(ua),
|
||||
chrome = /chrome/i.test(ua),
|
||||
safari = /safari/i.test(ua) && !chrome,
|
||||
opera = /opera/i.test(ua),
|
||||
firefox = /firefox/i.test(ua),
|
||||
gecko = /gecko\//i.test(ua);
|
||||
|
||||
function bowser() {
|
||||
|
||||
if (ie) {
|
||||
return {
|
||||
msie: 1,
|
||||
version: ua.match(/msie ([\d\.]+);/i)[1]
|
||||
};
|
||||
}
|
||||
if (chrome) {
|
||||
return {
|
||||
webkit: 1,
|
||||
chrome: 1,
|
||||
version: ua.match(/chrome\/([\d\.]+)/i)[1]
|
||||
};
|
||||
}
|
||||
if (safari) {
|
||||
return {
|
||||
webkit: 1,
|
||||
safari: 1,
|
||||
version: ua.match(/version\/([\d\.]+)/i)[1]
|
||||
};
|
||||
}
|
||||
if (opera) {
|
||||
return {
|
||||
opera: 1,
|
||||
version: ua.match(/version\/([\d\.]+)/i)[1]
|
||||
};
|
||||
}
|
||||
if (gecko) {
|
||||
var o = {
|
||||
gecko: 1,
|
||||
version: ua.match(/firefox\/([\d\.]+)/i)[1]
|
||||
};
|
||||
if (firefox) {
|
||||
o.firefox = 1;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
typeof module !== 'undefined' && module.exports ?
|
||||
(module.exports.browser = bowser) :
|
||||
(context.bowser = bowser);
|
||||
|
||||
}(this);
|
7
bowser.min.js
vendored
Normal file
7
bowser.min.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
/*!
|
||||
* Bowser - a browser detector
|
||||
* copyright Dustin Diaz 2011
|
||||
* https://github.com/ded/bowser
|
||||
* MIT License
|
||||
*/
|
||||
!function(a){function i(){if(c)return{msie:1,version:b.match(/msie ([\d\.]+);/i)[1]};if(d)return{webkit:1,chrome:1,version:b.match(/chrome\/([\d\.]+)/i)[1]};if(e)return{webkit:1,safari:1,version:b.match(/version\/([\d\.]+)/i)[1]};if(f)return{opera:1,version:b.match(/version\/([\d\.]+)/i)[1]};if(h){var a={gecko:1,version:b.match(/firefox\/([\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);typeof module!="undefined"&&module.exports?module.exports.browser=i:a.bowser=i}(this)
|
24
make/build.js
Normal file
24
make/build.js
Normal file
@ -0,0 +1,24 @@
|
||||
require('smoosh').config({
|
||||
"JAVASCRIPT": {
|
||||
"DIST_DIR": "./",
|
||||
"bowser": [
|
||||
"./src/copyright.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();
|
0
package.json
Normal file
0
package.json
Normal file
64
src/bowser.js
Normal file
64
src/bowser.js
Normal file
@ -0,0 +1,64 @@
|
||||
!function (context) {
|
||||
/**
|
||||
* 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"
|
||||
*/
|
||||
|
||||
var ua = navigator.userAgent,
|
||||
ie = /msie/i.test(ua),
|
||||
chrome = /chrome/i.test(ua),
|
||||
safari = /safari/i.test(ua) && !chrome,
|
||||
opera = /opera/i.test(ua),
|
||||
firefox = /firefox/i.test(ua),
|
||||
gecko = /gecko\//i.test(ua);
|
||||
|
||||
function bowser() {
|
||||
|
||||
if (ie) {
|
||||
return {
|
||||
msie: 1,
|
||||
version: ua.match(/msie ([\d\.]+);/i)[1]
|
||||
};
|
||||
}
|
||||
if (chrome) {
|
||||
return {
|
||||
webkit: 1,
|
||||
chrome: 1,
|
||||
version: ua.match(/chrome\/([\d\.]+)/i)[1]
|
||||
};
|
||||
}
|
||||
if (safari) {
|
||||
return {
|
||||
webkit: 1,
|
||||
safari: 1,
|
||||
version: ua.match(/version\/([\d\.]+)/i)[1]
|
||||
};
|
||||
}
|
||||
if (opera) {
|
||||
return {
|
||||
opera: 1,
|
||||
version: ua.match(/version\/([\d\.]+)/i)[1]
|
||||
};
|
||||
}
|
||||
if (gecko) {
|
||||
var o = {
|
||||
gecko: 1,
|
||||
version: ua.match(/firefox\/([\d\.]+)/i)[1]
|
||||
};
|
||||
if (firefox) {
|
||||
o.firefox = 1;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
typeof module !== 'undefined' && module.exports ?
|
||||
(module.exports.browser = bowser) :
|
||||
(context.bowser = bowser);
|
||||
|
||||
}(this);
|
6
src/copyright.js
Normal file
6
src/copyright.js
Normal file
@ -0,0 +1,6 @@
|
||||
/*!
|
||||
* Bowser - a browser detector
|
||||
* copyright Dustin Diaz 2011
|
||||
* https://github.com/ded/bowser
|
||||
* MIT License
|
||||
*/
|
Loading…
Reference in New Issue
Block a user