From 2e96c9a28f02b6ffd8e95bb44b0581887082f3d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 11 Jun 2022 23:44:37 +0200 Subject: 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. --- static/clock.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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") } } -- cgit v1.2.3