From 7949fcdc683d07689bad5da5d20bfa3eeb5a6a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 5 Sep 2023 01:25:00 +0200 Subject: Move frontend code to subdirectories, to simplify command line flags. --- static/ts/components/date-jump.ts | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 static/ts/components/date-jump.ts (limited to 'static/ts/components/date-jump.ts') diff --git a/static/ts/components/date-jump.ts b/static/ts/components/date-jump.ts new file mode 100644 index 00000000..fd3908ae --- /dev/null +++ b/static/ts/components/date-jump.ts @@ -0,0 +1,40 @@ +export { DateJump } + +/* Replace backend-driven [today] link with frontend, with one that + gets correctly set in the frontend. Similarly, update the go to + specific date button into a link which updates wheneven the date + form updates. +*/ +class DateJump extends HTMLElement { + + readonly golink: HTMLAnchorElement; + readonly input: HTMLInputElement; + + constructor() { + super(); + + this.golink = document.createElement('a') + this.golink.classList.add('btn'); + this.golink.textContent = "➔" + this.input = document.createElement('input') + this.input.type = 'date'; + } + + connectedCallback() { + + /* Form is just here so the css works out */ + let form = document.createElement('form'); + form.replaceChildren(this.input, this.golink); + this.replaceChildren(form); + + this.input.onchange = () => { + let date = this.input.valueAsDate!.format('~Y-~m-~d'); + this.golink.href = `${date}.html` + } + + let now = (new Date).format("~Y-~m-~d") + this.input.value = now; + /* onchange isn't triggered by manually setting the value */ + this.golink.href = `${now}.html` + } +} -- cgit v1.2.3 From e753d721519f72014241b3d2fc804a919f655769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 7 Sep 2023 02:58:41 +0200 Subject: Document remaining javascript items. --- static/ts/components/date-jump.ts | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'static/ts/components/date-jump.ts') diff --git a/static/ts/components/date-jump.ts b/static/ts/components/date-jump.ts index fd3908ae..f1cfe7e6 100644 --- a/static/ts/components/date-jump.ts +++ b/static/ts/components/date-jump.ts @@ -1,40 +1,51 @@ +/** + `` + + @category Web Components + @mergeTarget components + @module +*/ + export { DateJump } -/* Replace backend-driven [today] link with frontend, with one that +/** Replace backend-driven [today] link with frontend, with one that gets correctly set in the frontend. Similarly, update the go to specific date button into a link which updates wheneven the date form updates. + + TODO is this comment correct? We somehow contain an input element also. */ class DateJump extends HTMLElement { - readonly golink: HTMLAnchorElement; - readonly input: HTMLInputElement; + readonly #golink: HTMLAnchorElement; + readonly #input: HTMLInputElement; constructor() { super(); - this.golink = document.createElement('a') - this.golink.classList.add('btn'); - this.golink.textContent = "➔" - this.input = document.createElement('input') - this.input.type = 'date'; + this.#golink = document.createElement('a') + this.#golink.classList.add('btn'); + this.#golink.textContent = "➔" + this.#input = document.createElement('input') + this.#input.type = 'date'; } + /** Sets the link to NOW upon mounting */ connectedCallback() { /* Form is just here so the css works out */ let form = document.createElement('form'); - form.replaceChildren(this.input, this.golink); + form.replaceChildren(this.#input, this.#golink); this.replaceChildren(form); - this.input.onchange = () => { - let date = this.input.valueAsDate!.format('~Y-~m-~d'); - this.golink.href = `${date}.html` + this.#input.onchange = () => { + let date = this.#input.valueAsDate!.format('~Y-~m-~d'); + this.#golink.href = `${date}.html` } let now = (new Date).format("~Y-~m-~d") - this.input.value = now; + this.#input.value = now; /* onchange isn't triggered by manually setting the value */ - this.golink.href = `${now}.html` + this.#golink.href = `${now}.html` } } -- cgit v1.2.3