2016-11-26 01:28:53 +00:00
var OS = require ( './OS' ) ;
2016-11-25 04:00:15 +00:00
var Browser = {
2017-08-01 12:10:08 +00:00
// @property {boolean} arora - Set to true if running in Arora.
2016-11-25 04:00:15 +00:00
arora : false ,
2017-08-01 12:10:08 +00:00
// @property {boolean} chrome - Set to true if running in Chrome.
2016-11-25 04:00:15 +00:00
chrome : false ,
2017-08-01 12:10:08 +00:00
// @property {number} chromeVersion - If running in Chrome this will contain the major version number.
2016-11-25 04:00:15 +00:00
chromeVersion : 0 ,
2017-08-01 12:10:08 +00:00
// @property {boolean} epiphany - Set to true if running in Epiphany.
2016-11-25 04:00:15 +00:00
epiphany : false ,
2017-08-01 12:10:08 +00:00
// @property {boolean} firefox - Set to true if running in Firefox.
2016-11-25 04:00:15 +00:00
firefox : false ,
2017-08-01 12:10:08 +00:00
// @property {number} firefoxVersion - If running in Firefox this will contain the major version number.
2016-11-25 04:00:15 +00:00
firefoxVersion : 0 ,
2017-08-01 12:10:08 +00:00
// @property {boolean} mobileSafari - Set to true if running in Mobile Safari.
2016-11-25 04:00:15 +00:00
mobileSafari : false ,
2017-08-01 12:10:08 +00:00
// @property {boolean} ie - Set to true if running in Internet Explorer.
2016-11-25 04:00:15 +00:00
ie : false ,
2017-08-01 12:10:08 +00:00
// @property {number} ieVersion - If running in Internet Explorer this will contain the major version number. Beyond IE10 you should use Device.trident and Device.tridentVersion.
2016-11-25 04:00:15 +00:00
ieVersion : 0 ,
2017-08-01 12:10:08 +00:00
// @property {boolean} midori - Set to true if running in Midori.
2016-11-25 04:00:15 +00:00
midori : false ,
2017-08-01 12:10:08 +00:00
// @property {boolean} opera - Set to true if running in Opera.
2016-11-25 04:00:15 +00:00
opera : false ,
2017-08-01 12:10:08 +00:00
// @property {boolean} safari - Set to true if running in Safari.
2016-11-25 04:00:15 +00:00
safari : false ,
2017-08-01 12:10:08 +00:00
// @property {number} safariVersion - If running in Safari this will contain the major version number.
2016-11-25 04:00:15 +00:00
safariVersion : 0 ,
2017-08-01 12:10:08 +00:00
// @property {boolean} trident - Set to true if running a Trident version of Internet Explorer (IE11+)
2016-11-25 04:00:15 +00:00
trident : false ,
2017-08-01 12:10:08 +00:00
// @property {number} tridentVersion - If running in Internet Explorer 11 this will contain the major version number. See {@link http://msdn.microsoft.com/en-us/library/ie/ms537503(v=vs.85).aspx}
2016-11-25 04:00:15 +00:00
tridentVersion : 0 ,
2017-08-01 12:10:08 +00:00
// @property {boolean} edge - Set to true if running in Microsoft Edge browser.
2016-11-25 04:33:48 +00:00
edge : false ,
2016-11-25 04:00:15 +00:00
2017-08-01 12:10:08 +00:00
// @property {boolean} silk - Set to true if running in the Silk browser (as used on the Amazon Kindle)
2016-11-25 04:00:15 +00:00
silk : false
} ;
2016-11-26 01:28:53 +00:00
function init ( )
2016-11-25 04:00:15 +00:00
{
var ua = navigator . userAgent ;
if ( ( /Arora/ ) . test ( ua ) )
{
Browser . arora = true ;
}
2016-11-25 04:33:48 +00:00
else if ( /Edge\/\d+/ . test ( ua ) )
{
Browser . edge = true ;
}
2016-11-25 04:00:15 +00:00
else if ( ( /Chrome\/(\d+)/ ) . test ( ua ) && ! OS . windowsPhone )
{
Browser . chrome = true ;
Browser . chromeVersion = parseInt ( RegExp . $1 , 10 ) ;
}
else if ( ( /Epiphany/ ) . test ( ua ) )
{
Browser . epiphany = true ;
}
else if ( ( /Firefox\D+(\d+)/ ) . test ( ua ) )
{
Browser . firefox = true ;
Browser . firefoxVersion = parseInt ( RegExp . $1 , 10 ) ;
}
else if ( ( /AppleWebKit/ ) . test ( ua ) && OS . iOS )
{
Browser . mobileSafari = true ;
}
else if ( ( /MSIE (\d+\.\d+);/ ) . test ( ua ) )
{
Browser . ie = true ;
Browser . ieVersion = parseInt ( RegExp . $1 , 10 ) ;
}
else if ( ( /Midori/ ) . test ( ua ) )
{
Browser . midori = true ;
}
else if ( ( /Opera/ ) . test ( ua ) )
{
Browser . opera = true ;
}
else if ( ( /Safari/ ) . test ( ua ) && ! OS . windowsPhone )
{
Browser . safari = true ;
}
else if ( ( /Trident\/(\d+\.\d+)(.*)rv:(\d+\.\d+)/ ) . test ( ua ) )
{
Browser . ie = true ;
Browser . trident = true ;
Browser . tridentVersion = parseInt ( RegExp . $1 , 10 ) ;
Browser . ieVersion = parseInt ( RegExp . $3 , 10 ) ;
}
// Silk gets its own if clause because its ua also contains 'Safari'
if ( ( /Silk/ ) . test ( ua ) )
{
Browser . silk = true ;
}
return Browser ;
}
2016-11-26 01:28:53 +00:00
module . exports = init ( ) ;