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) {
$(`.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 : "/");
}
activeView = viewContainerId;
}, 200);
}
2024-01-08 16:53:12 +01:00
function lockUI(doLock) {
if (doLock) {
$("body").css("pointer-events", "none");
$("body").css("opacity", "0.4");
} else {
$("body").css("pointer-events", "inherit");
$("body").css("opacity", "1");
}
}
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);
// activeView = elem.id;
// }
// } else {
switchView("mainMenuView");
activeView = "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);
}
}
});