summaryrefslogtreecommitdiff
path: root/js/main.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/main.ts')
-rw-r--r--js/main.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/js/main.ts b/js/main.ts
new file mode 100644
index 0000000..44d28ad
--- /dev/null
+++ b/js/main.ts
@@ -0,0 +1,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;
+ }
+}