atriusmaps-node-sdk
Version:
This project provides an API to Atrius Personal Wayfinder maps within a Node environment. See the README.md for more information
35 lines (32 loc) • 1.08 kB
JavaScript
;
function buildEnv(app) {
const desktopViewMinWidth = app.config.desktopViewMinWidth || 0;
const isBrowser = typeof window !== "undefined";
const supportsTouch = isBrowser && ("ontouchstart" in window || navigator.maxTouchPoints > 0);
const isNarrow = () => isBrowser && innerWidth < desktopViewMinWidth;
const isMobile = () => isNarrow();
const isMobileReflow = () => isMobile() && innerHeight < 360;
const isVeryNarrow = () => isMobile() && innerWidth < 320;
const isDesktop = () => isBrowser && !isNarrow();
const isLocalhost = () => location.host.startsWith("localhost") || location.host.startsWith("127.0.0.1");
const env = {
isBrowser,
isMobile,
isMobileReflow,
isVeryNarrow,
isLocalhost,
isDesktop,
supportsTouch
};
if (isBrowser) {
window.addEventListener("resize", () => {
app.bus.send("env/resize", {
isMobile: env.isMobile(),
isMobileReflow: env.isMobileReflow(),
isVeryNarrow: env.isVeryNarrow()
});
});
}
return env;
}
exports.buildEnv = buildEnv;