devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
60 lines (47 loc) • 1.45 kB
JavaScript
/* global window */
var domAdapter = require("../dom_adapter");
var _hasWindow = typeof window !== "undefined";
var windowObject = _hasWindow && window;
if (!windowObject) {
windowObject = {};
windowObject.window = windowObject;
}
module.exports = {
hasWindow: function hasWindow() {
return _hasWindow;
},
getWindow: function getWindow() {
return windowObject;
},
hasProperty: function hasProperty(prop) {
return this.hasWindow() && prop in windowObject;
},
defaultScreenFactorFunc: function defaultScreenFactorFunc(width) {
if (width < 768) {
return "xs";
} else if (width < 992) {
return "sm";
} else if (width < 1200) {
return "md";
} else {
return "lg";
}
},
getCurrentScreenFactor: function getCurrentScreenFactor(screenFactorCallback) {
var screenFactorFunc = screenFactorCallback || this.defaultScreenFactorFunc;
var windowWidth = domAdapter.getDocumentElement()["clientWidth"];
return screenFactorFunc(windowWidth);
},
openWindow: function openWindow() {
if (this.hasProperty("open")) {
return windowObject.open();
}
return null;
},
getNavigator: function getNavigator() {
return this.hasWindow() ? windowObject.navigator : {
userAgent: ""
};
}
};
;