Add device view handler
This commit is contained in:
35
device-view-handler.js
Normal file
35
device-view-handler.js
Normal file
@@ -0,0 +1,35 @@
|
||||
(() => {
|
||||
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);
|
||||
})();
|
||||
Reference in New Issue
Block a user