UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

155 lines (152 loc) 3.88 kB
/** * @package @bitrix24/b24jssdk * @version 1.0.3 * @copyright (c) 2026 Bitrix24 * @license MIT * @see https://github.com/bitrix24/b24jssdk * @see https://bitrix24.github.io/b24jssdk/ */ import { Type } from './type.mjs'; var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); let UA = ""; try { UA = navigator?.userAgent.toLowerCase(); } catch { UA = "?"; } class BrowserManager { static { __name(this, "BrowserManager"); } isOpera() { return UA.includes("opera"); } isIE() { return "attachEvent" in document && !this.isOpera(); } isIE6() { return UA.includes("msie 6"); } isIE7() { return UA.includes("msie 7"); } isIE8() { return UA.includes("msie 8"); } isIE9() { return "documentMode" in document && document?.documentMode >= 9; } isIE10() { return "documentMode" in document && document?.documentMode >= 10; } isSafari() { return UA.includes("safari") && !UA.includes("chrome"); } isFirefox() { return UA.includes("firefox"); } isChrome() { return UA.includes("chrome"); } detectIEVersion() { if (this.isOpera() || this.isSafari() || this.isFirefox() || this.isChrome()) { return -1; } let rv = -1; if ( // @ts-expect-error we detect IEVersion //// !!window.MSStream && !window.ActiveXObject && "ActiveXObject" in window ) { rv = 11; } else if (this.isIE10()) { rv = 10; } else if (this.isIE9()) { rv = 9; } else if (this.isIE()) { rv = 8; } if (rv === -1 || rv === 8) { if (navigator.appName === "Microsoft Internet Explorer") { const re = /MSIE (\d[.0-9]*)/; const res = navigator.userAgent.match(re); if (Type.isArrayLike(res) && res.length > 0) { rv = Number.parseFloat(res[1]); } } if (navigator.appName === "Netscape") { rv = 11; const re = /Trident\/.*rv:(\d[.0-9]*)/; if (re.exec(navigator.userAgent) != null) { const res = navigator.userAgent.match(re); if (Type.isArrayLike(res) && res.length > 0) { rv = Number.parseFloat(res[1]); } } } } return rv; } isIE11() { return this.detectIEVersion() >= 11; } isMac() { return UA.includes("macintosh"); } isWin() { return UA.includes("windows"); } isLinux() { return UA.includes("linux") && !this.isAndroid(); } isAndroid() { return UA.includes("android"); } isIPad() { return UA.includes("ipad;") || this.isMac() && this.isTouchDevice(); } isIPhone() { return UA.includes("iphone;"); } isIOS() { return this.isIPad() || this.isIPhone(); } isMobile() { return this.isIPhone() || this.isIPad() || this.isAndroid() || UA.includes("mobile") || UA.includes("touch"); } isRetina() { return (window.devicePixelRatio && window.devicePixelRatio >= 2) === true; } isTouchDevice() { return "ontouchstart" in window || navigator.maxTouchPoints > 0; } isDoctype(target) { const doc = target || document; if (doc.compatMode) { return doc.compatMode === "CSS1Compat"; } return doc.documentElement && doc.documentElement.clientHeight; } isLocalStorageSupported() { try { localStorage.setItem("test", "test"); localStorage.removeItem("test"); return true; } catch { return false; } } detectAndroidVersion() { const re = /Android (\d[.0-9]*)/; if (re.exec(navigator.userAgent) != null) { const res = navigator.userAgent.match(re); if (Type.isArrayLike(res) && res.length > 0) { return Number.parseFloat(res[1]); } } return 0; } } const Browser = new BrowserManager(); export { Browser }; //# sourceMappingURL=browser.mjs.map