aboutsummaryrefslogtreecommitdiff
path: root/static/clock.ts
diff options
context:
space:
mode:
Diffstat (limited to 'static/clock.ts')
-rw-r--r--static/clock.ts31
1 files changed, 26 insertions, 5 deletions
diff --git a/static/clock.ts b/static/clock.ts
index b0ddae00..bbd15de0 100644
--- a/static/clock.ts
+++ b/static/clock.ts
@@ -1,4 +1,7 @@
-export { SmallcalCellHighlight, Timebar }
+export {
+ SmallcalCellHighlight, Timebar,
+ initialize_clock_components
+}
import { makeElement, date_to_percent } from './lib'
@@ -96,15 +99,29 @@ class ClockElement extends HTMLElement {
return ['timer_id']
}
- update(now: Date) { /* noop */ }
+ update(_: 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")
}
}
-customElements.define('today-button', TodayButton)
class CurrentTime extends ClockElement {
@@ -112,4 +129,8 @@ class CurrentTime extends ClockElement {
this.textContent = now.format('~H:~M:~S')
}
}
-customElements.define('current-time', CurrentTime)
+
+function initialize_clock_components() {
+ customElements.define('today-button', TodayButton)
+ customElements.define('current-time', CurrentTime)
+}