Open/close about dialog
All checks were successful
Build & Test / build-run (push) Successful in 42s
All checks were successful
Build & Test / build-run (push) Successful in 42s
This commit is contained in:
parent
451e9f26a8
commit
0d2f035b74
3 changed files with 29 additions and 10 deletions
|
@ -1,17 +1,27 @@
|
||||||
import { findImageOrFail, findSpanOrFail } from "./dom.mjs";
|
import { Dialog } from "./dialog.mjs";
|
||||||
|
import { findAnchorOrFail, findButtonOrFail, findDialogOrFail, findImageOrFail, findSpanOrFail } from "./dom.mjs";
|
||||||
|
|
||||||
async function populateVersion(versionSelector: string) {
|
const openButton = findAnchorOrFail(document.body, "#aboutLink");
|
||||||
const versionParagraph = findSpanOrFail(document.body, versionSelector);
|
const dialog = findDialogOrFail(document.body, "#about")
|
||||||
|
const versionParagraph = findSpanOrFail(dialog, "#version");
|
||||||
|
const charlotteImage = findImageOrFail(dialog, "#charlotteAvatar");
|
||||||
|
const kioImage = findImageOrFail(dialog, "#kioAvatar");
|
||||||
|
const closeButton = findButtonOrFail(dialog, ".close");
|
||||||
|
|
||||||
|
const aboutDialog = new Dialog(dialog);
|
||||||
|
|
||||||
|
openButton.addEventListener("click", e => aboutDialog.open());
|
||||||
|
closeButton.addEventListener("click", e => aboutDialog.close());
|
||||||
|
|
||||||
|
populateVersion();
|
||||||
|
populateUsers();
|
||||||
|
|
||||||
|
async function populateVersion() {
|
||||||
versionParagraph.innerText = await fetch("/api/about/version").then(r => r.text());
|
versionParagraph.innerText = await fetch("/api/about/version").then(r => r.text());
|
||||||
}
|
}
|
||||||
|
|
||||||
async function populateUsers(charlotteSelector: string, kioSelector: string) {
|
async function populateUsers() {
|
||||||
const charlotteImage = findImageOrFail(document.body, charlotteSelector);
|
|
||||||
const kioImage = findImageOrFail(document.body, kioSelector);
|
|
||||||
const { charlotte, kio } = await fetch("/api/about/nekomata_avatars").then(r => r.json());
|
const { charlotte, kio } = await fetch("/api/about/nekomata_avatars").then(r => r.json());
|
||||||
if (charlotte) charlotteImage.src = charlotte;
|
if (charlotte) charlotteImage.src = charlotte;
|
||||||
if (kio) kioImage.src = kio;
|
if (kio) kioImage.src = kio;
|
||||||
}
|
}
|
||||||
|
|
||||||
populateVersion("#version");
|
|
||||||
populateUsers("#charlotteAvatar", "#kioAvatar");
|
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
<header class="separator-bottom margin-large-bottom">
|
<header class="separator-bottom margin-large-bottom">
|
||||||
<div class="flex-row">
|
<div class="flex-row">
|
||||||
<h1>FeDirect</h1>
|
<h1>FeDirect</h1>
|
||||||
<p class="margin-auto-top">  By Nekomata</p>
|
<p class="margin-auto-top">  <a id="aboutLink" href="#"
|
||||||
|
title="About FeDirect & Nekomata">By Nekomata</a></p>
|
||||||
</div>
|
</div>
|
||||||
<img src="/static/nekomata_small.png" alt="Nekomata Logo" class="logo" />
|
<img src="/static/nekomata_small.png" alt="Nekomata Logo" class="logo" />
|
||||||
</header>
|
</header>
|
||||||
|
@ -148,6 +149,7 @@ Unchecking this is not recommended, and this option only exists for exceptional
|
||||||
</center>
|
</center>
|
||||||
<img src="/static/nekomata_small.png" alt="Nekomata Logo" class="absolute-centered xl-size-max" />
|
<img src="/static/nekomata_small.png" alt="Nekomata Logo" class="absolute-centered xl-size-max" />
|
||||||
</div>
|
</div>
|
||||||
|
<button class="close">Close</button>
|
||||||
</center>
|
</center>
|
||||||
</dialog>
|
</dialog>
|
||||||
<dialog id="spinner"><span class="spinner"></span></dialog>
|
<dialog id="spinner"><span class="spinner"></span></dialog>
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
// I would've LOVED to use generics for this but unfortunately that's not possible.
|
// I would've LOVED to use generics for this but unfortunately that's not possible.
|
||||||
// Type safety, but at what cost... >~< thanks TypeScript
|
// Type safety, but at what cost... >~< thanks TypeScript
|
||||||
|
|
||||||
|
export function findAnchorOrFail(on: Element, selector: string): HTMLAnchorElement {
|
||||||
|
const element = on.querySelector(selector);
|
||||||
|
if (!(element instanceof HTMLAnchorElement))
|
||||||
|
throw new Error(`${selector} isn't an a`);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
export function findDivOrFail(on: Element, selector: string): HTMLDivElement {
|
export function findDivOrFail(on: Element, selector: string): HTMLDivElement {
|
||||||
const element = on.querySelector(selector);
|
const element = on.querySelector(selector);
|
||||||
if (!(element instanceof HTMLDivElement))
|
if (!(element instanceof HTMLDivElement))
|
||||||
|
|
Loading…
Add table
Reference in a new issue