phaser/src/device/Browser.js

123 lines
3.5 KiB
JavaScript
Raw Normal View History

var OS = require('./OS');
2016-11-25 04:00:15 +00:00
var Browser = {
// @property {boolean} arora - Set to true if running in Arora.
2016-11-25 04:00:15 +00:00
arora: false,
// @property {boolean} chrome - Set to true if running in Chrome.
2016-11-25 04:00:15 +00:00
chrome: false,
// @property {number} chromeVersion - If running in Chrome this will contain the major version number.
2016-11-25 04:00:15 +00:00
chromeVersion: 0,
// @property {boolean} epiphany - Set to true if running in Epiphany.
2016-11-25 04:00:15 +00:00
epiphany: false,
// @property {boolean} firefox - Set to true if running in Firefox.
2016-11-25 04:00:15 +00:00
firefox: false,
// @property {number} firefoxVersion - If running in Firefox this will contain the major version number.
2016-11-25 04:00:15 +00:00
firefoxVersion: 0,
// @property {boolean} mobileSafari - Set to true if running in Mobile Safari.
2016-11-25 04:00:15 +00:00
mobileSafari: false,
// @property {boolean} ie - Set to true if running in Internet Explorer.
2016-11-25 04:00:15 +00:00
ie: false,
// @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,
// @property {boolean} midori - Set to true if running in Midori.
2016-11-25 04:00:15 +00:00
midori: false,
// @property {boolean} opera - Set to true if running in Opera.
2016-11-25 04:00:15 +00:00
opera: false,
// @property {boolean} safari - Set to true if running in Safari.
2016-11-25 04:00:15 +00:00
safari: false,
// @property {number} safariVersion - If running in Safari this will contain the major version number.
2016-11-25 04:00:15 +00:00
safariVersion: 0,
// @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,
// @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,
// @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
// @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
};
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;
}
module.exports = init();