summaryrefslogtreecommitdiff
path: root/js/main.ts
blob: 44d28ada92600e09d18952f749734b03877102c6 (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
/// <reference path="init.ts" />
/// <reference path="navigation.ts" />
/// <reference path="theme.ts" />

namespace Ach {
	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;
	}
}