2011-09-26 23:58:18 +00:00
/ * !
2013-09-13 13:42:55 +00:00
* Bowser - a browser detector
* https : //github.com/ded/bowser
* MIT License | ( c ) Dustin Diaz 2013
* /
2013-08-16 20:03:14 +00:00
2011-09-26 23:58:18 +00:00
! function ( name , definition ) {
2013-09-13 12:00:17 +00:00
if ( typeof define === 'function' ) {
define ( definition ) ;
} else if ( typeof module !== 'undefined' && module . exports ) {
module . exports [ name ] = definition ( ) ;
} else {
this [ name ] = definition ( ) ;
}
2011-09-26 23:58:18 +00:00
} ( '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" ,
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
2013-09-13 13:09:15 +00:00
/** @const */
var TRUE = true ;
/** @const */
var STR _VERSION = 'version' ;
/** @const */
var STR _MOBILE = 'mobile' ;
/** @const */
var STR _MSIE = 'msie' ;
/** @const */
var STR _OPERA = 'opera' ;
/** @const */
var STR _CHROME = 'chrome' ;
/** @const */
var STR _WEBKIT = 'webkit' ;
/** @const */
var STR _SAFARI = 'safari' ;
/** @const */
var STR _FIREFOX = 'firefox' ;
2013-09-13 13:42:55 +00:00
/** @const */
var STR _BLACKBERRY = 'blackberry' ;
/** @const */
var STR _WEBOS = 'webos' ;
/** @const */
var STR _GECKO = 'gecko' ;
/** @const */
var STR _ANDROID = 'android' ;
/** @const */
var STR _TOUCHPAD = 'touchpad' ;
/** @const */
var STR _IPHONE = 'iphone' ;
/** @const */
var STR _IPAD = 'ipad' ;
/** @const */
var STR _IPOD = 'ipod' ;
2013-09-13 13:09:15 +00:00
2013-09-13 12:08:52 +00:00
function detect ( ua ) {
2013-09-13 12:25:31 +00:00
/ * *
* Test a given regex against our user agent
*
* @ param { RegExp } regex
* @ return { Boolean }
* /
2013-09-13 13:42:55 +00:00
function uaTest ( test ) {
return new RegExp ( test , 'i' ) . test ( ua ) ;
2013-09-13 12:25:31 +00:00
}
/ * *
2013-09-13 13:21:31 +00:00
* Append version number matcher to our starting string
* and get version number from our user agent .
2013-09-13 12:25:31 +00:00
*
2013-09-13 13:21:31 +00:00
* @ param { String } start
2013-09-13 12:25:31 +00:00
* @ return { Number }
* /
2013-09-13 13:21:31 +00:00
function versionTest ( start , i ) {
var match = ua . match ( new RegExp ( start + '(\\d+(\\.\\d+)?)' , 'i' ) ) ;
2013-09-13 12:25:31 +00:00
return match ? match [ i || 1 ] : 0 ;
}
2013-09-13 13:42:55 +00:00
var iphone = uaTest ( STR _IPHONE )
, ipad = uaTest ( STR _IPAD )
, ipod = uaTest ( STR _IPOD )
2013-09-13 13:21:31 +00:00
, webkitVersion = versionTest ( STR _VERSION + '\/' )
, firefoxVersion = versionTest ( STR _FIREFOX + '[\/ ]' )
2013-09-13 13:09:15 +00:00
, o = { }
, version = 0 ;
2011-04-27 22:14:35 +00:00
2013-09-13 13:42:55 +00:00
if ( uaTest ( 'windows phone' ) ) {
2013-09-13 13:26:55 +00:00
o . windowsphone = o [ STR _MOBILE ] = TRUE ;
o [ STR _VERSION ] = versionTest ( 'iemobile\/' ) ;
2013-09-13 13:42:55 +00:00
} else if ( uaTest ( STR _OPERA ) || uaTest ( 'opr' ) ) {
2013-09-13 13:38:28 +00:00
o [ STR _OPERA ] = TRUE ;
o [ STR _VERSION ] = webkitVersion || versionTest ( 'opr\/' ) || versionTest ( 'opera[ \/]' ) ;
2013-09-13 13:42:55 +00:00
} else if ( uaTest ( '(msie|trident)' ) ) {
2013-09-13 13:09:15 +00:00
o [ STR _MSIE ] = TRUE ;
2013-09-13 13:21:31 +00:00
o [ STR _VERSION ] = versionTest ( '(msie |rv:)' , 2 ) ;
2013-09-13 13:42:55 +00:00
} else if ( uaTest ( STR _CHROME ) ) {
2013-09-13 13:09:15 +00:00
o [ STR _CHROME ] = o [ STR _WEBKIT ] = TRUE ;
2013-09-13 13:21:31 +00:00
o [ STR _VERSION ] = versionTest ( STR _CHROME + '\/' ) ;
2013-09-13 13:42:55 +00:00
} else if ( uaTest ( 'phantom' ) ) {
2013-09-13 13:09:15 +00:00
o . phantom = o [ STR _WEBKIT ] = TRUE ;
2013-09-13 13:21:31 +00:00
o [ STR _VERSION ] = versionTest ( 'phantomjs\/' ) ;
2013-09-13 13:42:55 +00:00
} else if ( uaTest ( STR _TOUCHPAD ) ) {
o [ STR _TOUCHPAD ] = o [ STR _WEBKIT ] = TRUE ;
o [ STR _VERSION ] = versionTest ( STR _TOUCHPAD + '\/' ) ;
2013-09-13 13:26:55 +00:00
} else if ( iphone || ipad || ipod ) {
2013-09-13 13:09:15 +00:00
o . ios = o [ STR _MOBILE ] = o [ STR _WEBKIT ] = TRUE ;
2013-09-13 13:26:55 +00:00
// CAUTION: version is not part of user agent in web apps
2013-09-13 13:21:31 +00:00
o [ STR _VERSION ] = webkitVersion ;
2013-09-13 13:26:55 +00:00
if ( ipod ) {
2013-09-13 13:42:55 +00:00
o [ STR _IPOD ] = TRUE ;
2013-09-13 13:26:55 +00:00
} else if ( iphone ) {
2013-09-13 13:42:55 +00:00
o [ STR _IPHONE ] = TRUE ;
2013-09-13 13:09:15 +00:00
} else if ( ipad ) {
2013-09-13 13:42:55 +00:00
o [ STR _IPAD ] = TRUE ;
2013-09-13 13:09:15 +00:00
}
2013-09-13 13:42:55 +00:00
} else if ( uaTest ( STR _BLACKBERRY ) ) {
o [ STR _BLACKBERRY ] = o [ STR _MOBILE ] = TRUE ;
2013-09-13 13:26:55 +00:00
if ( webkitVersion ) {
o [ STR _WEBKIT ] = TRUE ;
o [ STR _VERSION ] = webkitVersion ;
} else {
2013-09-13 13:42:55 +00:00
o [ STR _VERSION ] = versionTest ( STR _BLACKBERRY + '[\\d]+\/' ) ;
2013-09-13 13:26:55 +00:00
}
2013-09-13 13:42:55 +00:00
} else if ( uaTest ( STR _WEBOS ) ) {
o [ STR _WEBOS ] = o [ STR _MOBILE ] = o [ STR _WEBKIT ] = TRUE ;
2013-09-13 13:26:55 +00:00
o [ STR _VERSION ] = webkitVersion || versionTest ( 'wosbrowser\/' ) ;
2013-09-13 13:42:55 +00:00
} else if ( uaTest ( STR _ANDROID ) ) {
o [ STR _ANDROID ] = o [ STR _MOBILE ] = o [ STR _WEBKIT ] = TRUE ;
2013-09-13 13:21:31 +00:00
o [ STR _VERSION ] = webkitVersion || firefoxVersion ;
2013-09-13 13:42:55 +00:00
} else if ( uaTest ( STR _SAFARI ) ) {
2013-09-13 13:09:15 +00:00
o [ STR _SAFARI ] = o [ STR _WEBKIT ] = TRUE ;
2013-09-13 13:21:31 +00:00
o [ STR _VERSION ] = webkitVersion ;
2013-09-13 13:42:55 +00:00
} else if ( uaTest ( STR _GECKO ) ) {
o [ STR _GECKO ] = o . mozilla = TRUE ;
2013-09-13 13:21:31 +00:00
o [ STR _VERSION ] = firefoxVersion ;
2013-09-13 13:42:55 +00:00
if ( uaTest ( STR _FIREFOX ) ) {
2013-09-13 13:09:15 +00:00
o . firefox = TRUE ;
2013-09-13 12:30:33 +00:00
}
2013-09-13 13:42:55 +00:00
} else if ( uaTest ( 'seamonkey\/' ) ) {
2013-09-13 13:09:15 +00:00
o . seamonkey = TRUE ;
2013-09-13 13:21:31 +00:00
o [ STR _VERSION ] = versionTest ( 'seamonkey\/' ) ;
2013-09-13 13:42:55 +00:00
2013-09-13 12:00:17 +00:00
} else {
2013-09-13 13:09:15 +00:00
o [ STR _VERSION ] = 0 ;
2013-09-13 12:00:17 +00:00
}
2011-04-27 22:14:35 +00:00
2013-09-13 13:09:15 +00:00
version = o [ STR _VERSION ] ;
2013-09-13 12:08:52 +00:00
// Graded Browser Support
// http://developer.yahoo.com/yui/articles/gbs
2013-09-13 13:09:15 +00:00
if ( ( o [ STR _MSIE ] && version >= 8 ) ||
( o [ STR _CHROME ] && version >= 10 ) ||
( o [ STR _FIREFOX ] && version >= 4.0 ) ||
( o [ STR _SAFARI ] && version >= 5 ) ||
( o [ STR _OPERA ] && version >= 10.0 ) ) {
o . a = TRUE ;
2013-09-13 12:08:52 +00:00
}
2011-05-10 16:50:28 +00:00
2013-09-13 13:09:15 +00:00
else if ( ( o [ STR _MSIE ] && version < 8 ) ||
( o [ STR _CHROME ] && version < 10 ) ||
( o [ STR _FIREFOX ] && version < 4.0 ) ||
( o [ STR _SAFARI ] && version < 5 ) ||
( o [ STR _OPERA ] && version < 10.0 ) ) {
o . c = TRUE ;
2013-09-13 12:08:52 +00:00
} else {
2013-09-13 13:09:15 +00:00
o . x = TRUE ;
2013-09-13 12:08:52 +00:00
}
2011-05-10 16:50:28 +00:00
2013-09-13 12:08:52 +00:00
return o ;
2013-09-13 12:00:17 +00:00
}
2011-04-27 22:14:35 +00:00
2013-09-13 12:08:52 +00:00
/* Get our main bowser object from navigators user agent if present. */
var bowser = detect ( typeof navigator !== 'undefined' ? navigator . userAgent : '' ) ;
2013-09-13 13:42:55 +00:00
2013-09-13 12:08:52 +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 ;
2013-09-13 12:00:17 +00:00
return bowser ;
2013-09-13 12:08:52 +00:00
} ) ;