devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
68 lines (67 loc) • 2.06 kB
JavaScript
/**
* DevExtreme (esm/__internal/core/utils/m_window.js)
* Version: 24.2.6
* Build date: Mon Mar 17 2025
*
* Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import domAdapter from "../../../core/dom_adapter";
let hasWindowValue = "undefined" !== typeof window;
const hasWindow = () => hasWindowValue;
let windowObject = hasWindow() ? window : void 0;
if (!windowObject) {
windowObject = {};
windowObject.window = windowObject
}
const getWindow = () => windowObject;
const setWindow = (newWindowObject, hasWindow) => {
if (void 0 === hasWindow) {
hasWindowValue = "undefined" !== typeof window && window === newWindowObject
} else {
hasWindowValue = hasWindow
}
windowObject = newWindowObject
};
const hasProperty = prop => hasWindow() && prop in windowObject;
const defaultScreenFactorFunc = width => {
if (width < 768) {
return "xs"
}
if (width < 992) {
return "sm"
}
if (width < 1200) {
return "md"
}
return "lg"
};
const getCurrentScreenFactor = screenFactorCallback => {
const screenFactorFunc = screenFactorCallback || defaultScreenFactorFunc;
const windowWidth = domAdapter.getDocumentElement().clientWidth;
return screenFactorFunc(windowWidth)
};
const getNavigator = () => {
var _windowObject;
return hasWindow() ? null === (_windowObject = windowObject) || void 0 === _windowObject ? void 0 : _windowObject.navigator : {
userAgent: ""
}
};
export {
defaultScreenFactorFunc,
getCurrentScreenFactor,
getNavigator,
getWindow,
hasProperty,
hasWindow,
setWindow
};
export default {
defaultScreenFactorFunc: defaultScreenFactorFunc,
getCurrentScreenFactor: getCurrentScreenFactor,
getNavigator: getNavigator,
getWindow: getWindow,
hasProperty: hasProperty,
hasWindow: hasWindow,
setWindow: setWindow
};