diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-06-11 23:44:37 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-06-11 23:54:08 +0200 |
commit | 2e96c9a28f02b6ffd8e95bb44b0581887082f3d2 (patch) | |
tree | 0aa2f72b6816a3bd5e57fe0c604b26eb2f3a9163 | |
parent | Move clock component initialization to procedure. (diff) | |
download | calp-2e96c9a28f02b6ffd8e95bb44b0581887082f3d2.tar.gz calp-2e96c9a28f02b6ffd8e95bb44b0581887082f3d2.tar.xz |
Update today-button to not depend on initial content.
Depending on initial content is fragile. This instead constructs a
completely new tag, discarding what happened to be there before.
-rw-r--r-- | static/clock.ts | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/static/clock.ts b/static/clock.ts index fa975484..3a5b0077 100644 --- a/static/clock.ts +++ b/static/clock.ts @@ -102,9 +102,24 @@ class ClockElement extends HTMLElement { update(now: Date) { /* noop */ } } + class TodayButton extends ClockElement { + a: HTMLAnchorElement; + + constructor() { + super(); + this.a = document.createElement('a'); + this.a.textContent = 'Idag'; + this.a.classList.add('btn'); + } + + connectedCallback() { + super.connectedCallback(); + this.replaceChildren(this.a); + } + update(now: Date) { - (this.querySelector('a') as any).href = now.format("~Y-~m-~d.html") + this.a.href = now.format("~Y-~m-~d.html") } } |