36 lines
988 B
JavaScript
36 lines
988 B
JavaScript
(() => {
|
|
let resizeTimeout;
|
|
let prevView = app_shop.vars.view;
|
|
const container = document.querySelector("#container");
|
|
|
|
const VIEW_PHONE = [1, 2];
|
|
const VIEW_TABLET_DESKTOP = [3, 4];
|
|
|
|
const handleResize = () => {
|
|
if (!container?.classList.contains("projector_page")) return;
|
|
|
|
clearTimeout(resizeTimeout);
|
|
resizeTimeout = setTimeout(() => {
|
|
const currentView = app_shop.vars.view;
|
|
|
|
// From desktop to phone
|
|
if (VIEW_TABLET_DESKTOP.includes(prevView) && VIEW_PHONE.includes(currentView)) {
|
|
// Call a function 1
|
|
console.log("From desktop to phone");
|
|
}
|
|
|
|
// From phone to desktop
|
|
else if (VIEW_PHONE.includes(prevView) && VIEW_TABLET_DESKTOP.includes(currentView)) {
|
|
// Call a function 2
|
|
console.log("From phone to desktop");
|
|
}
|
|
|
|
prevView = currentView;
|
|
}, 200);
|
|
};
|
|
|
|
window.addEventListener("resize", handleResize);
|
|
|
|
return () => window.removeEventListener("resize", handleResize);
|
|
})();
|