@lani.ground/react-modal
Version:
Modal components used in reactjs
32 lines (31 loc) • 1.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasBodyScroll = exports.getScrollbarWidth = exports.isMobileDevice = void 0;
var isBrowser = typeof window !== 'undefined';
var isMobileDevice = function () {
if (!isBrowser || !navigator)
return false;
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
};
exports.isMobileDevice = isMobileDevice;
var getScrollbarWidth = function () {
var _a;
if (!isBrowser || !(document === null || document === void 0 ? void 0 : document.body))
return 0;
var outer = document.createElement('div');
outer.style.visibility = 'hidden';
outer.style.overflow = 'scroll';
document.body.appendChild(outer);
var inner = document.createElement('div');
outer.appendChild(inner);
var scrollbarWidth = outer.offsetWidth - inner.offsetWidth;
(_a = outer.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(outer);
return scrollbarWidth;
};
exports.getScrollbarWidth = getScrollbarWidth;
var hasBodyScroll = function () {
if (!isBrowser || !(document === null || document === void 0 ? void 0 : document.body))
return false;
return document.body.scrollHeight > window.innerHeight;
};
exports.hasBodyScroll = hasBodyScroll;