2011-09-26 23:58:18 +00:00
/ * !
* Bowser - a browser detector
* https : //github.com/ded/bowser
2013-08-16 20:03:14 +00:00
* MIT License | ( c ) Dustin Diaz 2013
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 ) {
if ( typeof define == 'function' ) define ( definition )
else if ( typeof module != 'undefined' && module . exports ) module . exports [ 'browser' ] = definition ( )
else this [ name ] = definition ( )
} ( 'bowser' , function ( ) {
2011-04-27 22:14:35 +00:00
/ * *
* 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)"
2013-08-16 19:58:39 +00:00
* IE >= 11 : "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; Media Center PC 6.0; rv:11.0) like Gecko"
2011-04-27 22:14:35 +00:00
* Firefox : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0) Gecko/20100101 Firefox/4.0"
2011-09-26 23:58:18 +00:00
* 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"
2011-11-17 03:39:43 +00:00
* 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" ,
2014-01-27 12:15:07 +00:00
* iPod : "Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; ja-jp) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5"
2011-09-26 23:58:18 +00:00
* 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"
2012-04-15 22:11:55 +00:00
* Touchpad : "Mozilla/5.0 (hp-tabled;Linux;hpwOS/3.0.5; U; en-US)) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/234.83 Safari/534.6 TouchPad/1.0"
2012-07-18 17:45:20 +00:00
* PhantomJS : "Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.5.0 Safari/534.34"
2012-04-17 01:54:24 +00:00
* /
2011-04-27 22:14:35 +00:00
2011-09-26 23:58:18 +00:00
var ua = navigator . userAgent
, t = true
2013-08-16 19:58:39 +00:00
, ie = /(msie|trident)/i . test ( ua )
2013-12-11 17:38:22 +00:00
, chrome = /chrome|crios/i . test ( ua )
2012-07-18 17:45:20 +00:00
, phantom = /phantom/i . test ( ua )
, safari = /safari/i . test ( ua ) && ! chrome && ! phantom
2011-09-26 23:58:18 +00:00
, iphone = /iphone/i . test ( ua )
2012-04-17 01:54:24 +00:00
, ipad = /ipad/i . test ( ua )
2014-01-27 12:15:07 +00:00
, ipod = /ipod/i . test ( ua )
2012-04-15 22:13:29 +00:00
, touchpad = /touchpad/i . test ( ua )
2011-09-26 23:58:18 +00:00
, android = /android/i . test ( ua )
2013-08-16 19:58:39 +00:00
, opera = /opera/i . test ( ua ) || /opr/i . test ( ua )
2011-09-26 23:58:18 +00:00
, firefox = /firefox/i . test ( ua )
, gecko = /gecko\//i . test ( ua )
2011-11-17 03:39:43 +00:00
, seamonkey = /seamonkey\//i . test ( ua )
2011-09-26 23:58:18 +00:00
, webkitVersion = /version\/(\d+(\.\d+)?)/i
2013-08-16 10:53:26 +00:00
, firefoxVersion = /firefox\/(\d+(\.\d+)?)/i
2012-01-24 09:58:00 +00:00
, o
2011-05-02 20:33:54 +00:00
function detect ( ) {
2011-04-27 22:14:35 +00:00
2011-09-26 23:58:18 +00:00
if ( ie ) return {
2013-12-05 20:00:02 +00:00
name : 'Internet Explorer'
, msie : t
2013-08-16 19:58:39 +00:00
, version : ua . match ( /(msie |rv:)(\d+(\.\d+)?)/i ) [ 2 ]
}
if ( opera ) return {
2013-12-05 20:00:02 +00:00
name : 'Opera'
, opera : t
2013-10-29 18:11:27 +00:00
, version : ua . match ( webkitVersion ) ? ua . match ( webkitVersion ) [ 1 ] : ua . match ( /opr\/(\d+(\.\d+)?)/i ) [ 1 ]
2013-08-16 19:58:39 +00:00
}
2011-09-26 23:58:18 +00:00
if ( chrome ) return {
2013-12-05 20:00:02 +00:00
name : 'Chrome'
, webkit : t
2011-09-26 23:58:18 +00:00
, chrome : t
2013-12-11 17:38:22 +00:00
, version : ua . match ( /(?:chrome|crios)\/(\d+(\.\d+)?)/i ) [ 1 ]
2013-08-16 19:58:39 +00:00
}
2012-07-18 17:45:20 +00:00
if ( phantom ) return {
2013-12-05 20:00:02 +00:00
name : 'PhantomJS'
, webkit : t
2012-07-18 17:45:20 +00:00
, phantom : t
, version : ua . match ( /phantomjs\/(\d+(\.\d+)+)/i ) [ 1 ]
2013-08-16 19:58:39 +00:00
}
2012-04-15 22:13:29 +00:00
if ( touchpad ) return {
2013-12-05 20:00:02 +00:00
name : 'TouchPad'
, webkit : t
2012-04-15 22:11:55 +00:00
, touchpad : t
, version : ua . match ( /touchpad\/(\d+(\.\d+)?)/i ) [ 1 ]
2013-08-16 19:58:39 +00:00
}
2014-01-27 12:15:07 +00:00
if ( iphone || ipad || ipod ) {
2012-01-24 09:58:00 +00:00
o = {
2014-01-27 12:15:07 +00:00
name : iphone ? 'iPhone' : ipad ? 'iPad' : 'iPod'
2013-12-05 20:00:02 +00:00
, webkit : t
2013-08-16 19:58:39 +00:00
, mobile : t
, ios : t
, iphone : iphone
, ipad : ipad
2014-01-27 12:15:07 +00:00
, ipod : ipod
2012-01-24 09:58:00 +00:00
}
// WTF: version is not part of user agent in web apps
if ( webkitVersion . test ( ua ) ) {
o . version = ua . match ( webkitVersion ) [ 1 ]
}
return o
2011-04-27 22:14:35 +00:00
}
2011-09-26 23:58:18 +00:00
if ( android ) return {
2013-12-05 20:00:02 +00:00
name : 'Android'
, webkit : t
2011-09-26 23:58:18 +00:00
, android : t
, mobile : t
2013-08-16 10:53:26 +00:00
, version : ( ua . match ( webkitVersion ) || ua . match ( firefoxVersion ) ) [ 1 ]
2013-08-16 19:58:39 +00:00
}
2011-09-26 23:58:18 +00:00
if ( safari ) return {
2013-12-05 20:00:02 +00:00
name : 'Safari'
, webkit : t
2011-09-26 23:58:18 +00:00
, safari : t
, version : ua . match ( webkitVersion ) [ 1 ]
2013-08-16 19:58:39 +00:00
}
2011-04-27 22:14:35 +00:00
if ( gecko ) {
2012-01-24 09:58:00 +00:00
o = {
2013-12-05 20:00:02 +00:00
name : 'Gecko'
, gecko : t
2013-08-16 19:58:39 +00:00
, mozilla : t
, version : ua . match ( firefoxVersion ) [ 1 ]
2011-04-27 22:14:35 +00:00
}
2013-12-05 20:00:02 +00:00
if ( firefox ) {
o . name = 'Firefox' ;
o . firefox = t ;
}
2011-09-26 23:58:18 +00:00
return o
2011-04-27 22:14:35 +00:00
}
2011-11-17 03:39:43 +00:00
if ( seamonkey ) return {
2013-12-05 20:00:02 +00:00
name : 'SeaMonkey'
, seamonkey : t
2011-11-17 03:39:43 +00:00
, version : ua . match ( /seamonkey\/(\d+(\.\d+)?)/i ) [ 1 ]
2013-08-16 19:58:39 +00:00
}
return { }
2011-04-27 22:14:35 +00:00
}
2011-09-26 23:58:18 +00:00
var bowser = detect ( )
2011-05-10 16:50:28 +00:00
// Graded Browser Support
// http://developer.yahoo.com/yui/articles/gbs
2013-08-16 20:03:14 +00:00
if ( ( bowser . msie && bowser . version >= 8 ) ||
2011-10-11 08:02:07 +00:00
( bowser . chrome && bowser . version >= 10 ) ||
( bowser . firefox && bowser . version >= 4.0 ) ||
2011-05-10 16:50:28 +00:00
( bowser . safari && bowser . version >= 5 ) ||
2011-10-11 08:02:07 +00:00
( bowser . opera && bowser . version >= 10.0 ) ) {
2011-09-26 23:58:18 +00:00
bowser . a = t ;
2011-05-10 16:50:28 +00:00
}
2013-08-16 20:03:14 +00:00
else if ( ( bowser . msie && bowser . version < 8 ) ||
2011-10-11 08:02:07 +00:00
( bowser . chrome && bowser . version < 10 ) ||
( bowser . firefox && bowser . version < 4.0 ) ||
2011-05-10 16:50:28 +00:00
( bowser . safari && bowser . version < 5 ) ||
2011-10-11 08:02:07 +00:00
( bowser . opera && bowser . version < 10.0 ) ) {
2011-09-26 23:58:18 +00:00
bowser . c = t
} else bowser . x = t
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
} ) ;