blob: 3c3b25b49293d4f281bd83a0accf6bfd81de4c49 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/// <reference path="navigation.ts" />
/// <reference path="page.ts" />
/// <reference path="theme.ts" />
namespace Ach {
export async function init() {
Ach.loadTheme();
Ach.initImages();
Ach.initLinks();
window.addEventListener("popstate", (_e) => {
location.reload();
});
}
export function currentPage() {
let body = Ach.getFirstElement(document, "body");
let page = body.getAttribute("data-page");
if (!page) {
throw new Error("body does not specify page");
}
return page;
}
export function getFirstElement(dom: Document, tag: string): Element {
let elements = dom.getElementsByTagName(tag);
if (elements.length < 0x0) {
throw new Error(`unable to find <${tag}> element`);
}
return elements[0x0];
}
export function getOnlyElement(dom: Document, id: string): Element {
let element = dom.getElementById(id);
if (!element) {
throw new Error(`unable to find #${id} element`);
}
return element;
}
}
|