statki/public/assets/js/spa_lib.js

56 lines
1.8 KiB
JavaScript
Raw Normal View History

var activeView;
2024-03-19 22:33:14 +01:00
var returnLock = false;
function switchView(viewContainerId, useReplaceState=false) {
if (!returnLock && viewContainerId !== activeView) {
2024-03-24 22:00:05 +01:00
$(`.container`).css({ opacity: 0, animation: "OutAnim 0.2s 1 ease" });
setTimeout(() => {
$(`.container`).css("display", "none");
$(`.container#${viewContainerId}`).css({ display: "flex", opacity: 1, animation: "InAnim 0.2s 1 ease" });
let path = $(`.container#${viewContainerId}`).data("path");
let title = $(`.container#${viewContainerId}`).data("title");
if (useReplaceState) {
history.replaceState(null, "", path ? path : "/");
} else {
history.pushState(null, title ? title : "Statki", path ? path : "/");
}
2024-03-24 22:00:05 +01:00
activeView = viewContainerId;
}, 200);
}
}
2024-01-08 16:53:12 +01:00
function lockUI(doLock) {
if (doLock) {
$("body").css("pointer-events", "none");
$(".container").css("opacity", "0.4");
2024-01-08 16:53:12 +01:00
} else {
$("body").css("pointer-events", "inherit");
$(".container").css("opacity", "1");
2024-01-08 16:53:12 +01:00
}
}
const initialURLParams = new URLSearchParams(window.location.search);
const initialPath = initialURLParams.get('path');
window.addEventListener("load", () => {
2024-01-08 16:53:12 +01:00
// if (initialPath != null) {
// let elem = document.querySelector(`.container[data-path="${initialPath}"]`);
2024-01-08 16:53:12 +01:00
// if (elem != null) {
// switchView(elem.id, true);
// }
// } else {
// switchView("mainMenuView");
2024-01-08 16:53:12 +01:00
//}
});
addEventListener("popstate", (event) => {
event.preventDefault();
2024-03-19 22:33:14 +01:00
if (!returnLock) {
let elem = document.querySelector(`.container[data-path="${window.location.pathname}"]`);
if (elem != null) {
switchView(elem.id, true);
}
}
});