aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-06-11 23:44:37 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-06-11 23:54:08 +0200
commit2e96c9a28f02b6ffd8e95bb44b0581887082f3d2 (patch)
tree0aa2f72b6816a3bd5e57fe0c604b26eb2f3a9163
parentMove clock component initialization to procedure. (diff)
downloadcalp-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.ts17
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")
}
}