diff --git a/src/services/utilsService.js b/src/services/utilsService.js index 3c635200..b37860a8 100644 --- a/src/services/utilsService.js +++ b/src/services/utilsService.js @@ -1,22 +1,44 @@ function UtilsService() { initUtilsService(); + + this.browserCache = null; }; function initUtilsService() { UtilsService.prototype.getBrowser = function () { - if (navigator.userAgent.indexOf("Firefox") !== -1 || navigator.userAgent.indexOf("Gecko/") !== -1) { - return 'firefox'; - } - if ((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) { - return 'opera'; - } - if (navigator.userAgent.indexOf(" Edge/") !== -1) { - return 'edge'; - } - if (window.chrome) { - return 'chrome'; + if (this.browserCache) { + return this.browserCache; } - return null; + if (navigator.userAgent.indexOf("Firefox") !== -1 || navigator.userAgent.indexOf("Gecko/") !== -1) { + this.browserCache = 'firefox'; + } + else if ((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) { + this.browserCache = 'opera'; + } + else if (navigator.userAgent.indexOf(" Edge/") !== -1) { + this.browserCache = 'edge'; + } + else if (window.chrome) { + this.browserCache = 'chrome'; + } + + return this.browserCache; }; + + UtilsService.prototype.isFirefox = function () { + return this.getBrowser() === 'firefox'; + } + + UtilsService.prototype.isChrome = function () { + return this.getBrowser() === 'chrome'; + } + + UtilsService.prototype.isEdge = function () { + return this.getBrowser() === 'edge'; + } + + UtilsService.prototype.isOpera = function () { + return this.getBrowser() === 'opera'; + } };