2020-06-26 11:59:13 +00:00
|
|
|
import TabManager from "./ui/TabManager";
|
|
|
|
import sections from "./ui/sections";
|
2020-06-22 14:17:37 +00:00
|
|
|
import { nextAnimationFrame } from "./utils";
|
2020-06-26 11:59:13 +00:00
|
|
|
import { searchBox } from "./scripts/search";
|
2020-06-17 09:43:21 +00:00
|
|
|
|
2020-06-22 14:17:37 +00:00
|
|
|
// @ts-expect-error: Parcel image import
|
|
|
|
import unknown from "~/assets/images/tab-icons/unknown.svg";
|
2020-06-28 15:44:59 +00:00
|
|
|
import { bindFunctions } from "./scripts/index";
|
2020-06-17 09:43:21 +00:00
|
|
|
|
2020-08-25 13:28:42 +00:00
|
|
|
// Enable single page mode for developing scripts
|
2020-08-25 13:31:55 +00:00
|
|
|
const devSinglePage = null; // ["Other", "Guide_to_food_and_drinks"];
|
2020-08-25 13:28:42 +00:00
|
|
|
|
2020-06-22 14:17:37 +00:00
|
|
|
async function load() {
|
|
|
|
const sectionListContainer = document.getElementById("section-list");
|
|
|
|
const tabListContainer = document.getElementById("tab-list");
|
|
|
|
const tabContentContainer = document.getElementById("tabs");
|
|
|
|
const manager = new TabManager(
|
|
|
|
sectionListContainer,
|
|
|
|
tabListContainer,
|
|
|
|
tabContentContainer
|
|
|
|
);
|
|
|
|
manager.setLoading(true);
|
|
|
|
|
|
|
|
await nextAnimationFrame();
|
2020-06-18 11:54:09 +00:00
|
|
|
|
2020-06-22 14:17:37 +00:00
|
|
|
// Add loading "bar"
|
|
|
|
const spinnerContainer = document.querySelector("#tabs > .speen");
|
|
|
|
const icons = document.createElement("div");
|
|
|
|
icons.className = "loading-icons";
|
2020-06-19 18:26:43 +00:00
|
|
|
|
2020-08-25 13:28:42 +00:00
|
|
|
let promises = [];
|
|
|
|
if (devSinglePage != null) {
|
|
|
|
manager.createSection(devSinglePage[0]);
|
|
|
|
promises = [manager.openTab(devSinglePage[0], devSinglePage[1], {})];
|
|
|
|
} else {
|
|
|
|
sections.forEach((section) =>
|
|
|
|
section.tabs.forEach((tab) => {
|
|
|
|
const iconElement = document.createElement("img");
|
|
|
|
iconElement.dataset.tab = tab.page;
|
|
|
|
iconElement.src = tab.icon || unknown;
|
|
|
|
iconElement.title = tab.page.replace(/_/gi, " ");
|
|
|
|
icons.appendChild(iconElement);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
spinnerContainer.appendChild(icons);
|
|
|
|
|
|
|
|
promises = sections.flatMap((section) => {
|
|
|
|
manager.createSection(section.name);
|
2020-06-28 15:44:59 +00:00
|
|
|
|
2020-08-25 13:28:42 +00:00
|
|
|
return section.tabs.map(async (tab) => {
|
|
|
|
// Load page
|
|
|
|
await manager.openTab(section.name, tab.page, {
|
|
|
|
icon: tab.icon,
|
|
|
|
text: tab.text,
|
|
|
|
});
|
|
|
|
// Remove icon from loading
|
|
|
|
icons.removeChild(icons.querySelector(`img[data-tab=${tab.page}]`));
|
2020-06-22 14:17:37 +00:00
|
|
|
});
|
|
|
|
});
|
2020-08-25 13:28:42 +00:00
|
|
|
}
|
2020-06-28 15:44:59 +00:00
|
|
|
const welcome = document.getElementById("Welcome");
|
|
|
|
bindFunctions(welcome, "$Welcome");
|
|
|
|
|
2020-06-22 14:17:37 +00:00
|
|
|
Promise.all(promises).then(() => {
|
|
|
|
// Remove app-wide loading
|
|
|
|
manager.setLoading(false);
|
2020-08-25 13:28:42 +00:00
|
|
|
if (devSinglePage) {
|
|
|
|
manager.setActive(devSinglePage[1]);
|
|
|
|
} else {
|
|
|
|
manager.showSection("Medical");
|
|
|
|
welcome.classList.add("active");
|
|
|
|
}
|
2020-06-22 14:17:37 +00:00
|
|
|
});
|
|
|
|
}
|
2020-06-18 11:54:09 +00:00
|
|
|
if ("serviceWorker" in navigator) {
|
2020-06-18 12:07:10 +00:00
|
|
|
const x = process.env.SUBPATH ? `${process.env.SUBPATH}/sw.js` : "sw.js";
|
2020-06-18 11:54:09 +00:00
|
|
|
navigator.serviceWorker
|
|
|
|
.register(x)
|
|
|
|
.then((registration) => {
|
|
|
|
console.log("Registration successful, scope is:", registration.scope);
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.log("Service worker registration failed, error:", error);
|
|
|
|
});
|
|
|
|
}
|
2020-06-22 14:17:37 +00:00
|
|
|
|
2020-07-02 10:26:08 +00:00
|
|
|
// Start loading pages
|
2020-06-22 14:17:37 +00:00
|
|
|
load();
|
2020-06-24 15:12:11 +00:00
|
|
|
|
2020-07-02 10:26:08 +00:00
|
|
|
// Add search box
|
2020-06-24 15:12:11 +00:00
|
|
|
document.body.appendChild(searchBox());
|
2020-07-02 10:26:08 +00:00
|
|
|
|
|
|
|
// Add revision info
|
|
|
|
document
|
|
|
|
.getElementById("tgh-version")
|
|
|
|
.appendChild(document.createTextNode(process.env.REVISION || "unknown"));
|