aboutsummaryrefslogtreecommitdiff
path: root/static/clock.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--static/clock.js38
1 files changed, 31 insertions, 7 deletions
diff --git a/static/clock.js b/static/clock.js
index 9642ebaf..240041a9 100644
--- a/static/clock.js
+++ b/static/clock.js
@@ -60,15 +60,39 @@ class SmallcalCellHighlight extends Clock {
}
}
-/* Update [today] button */
-class ButtonUpdater extends Clock {
- constructor(el, proc) {
+/* -------------------------------------------------- */
+
+class ClockElement extends HTMLElement {
+ constructor () {
super();
- this.el = el;
- this.proc = proc;
}
- update(now) {
- this.proc(this.el, now);
+ connectedCallback () {
+ let interval = this.hasAttribute('interval') ? +this.getAttribute('img') : 60;
+ interval *= 1000 /* ms */
+
+ this.timer_id = window.setInterval(() => this.update(new Date), interval)
+ this.update(new Date)
+ }
+
+ static get observerAttributes () {
+ return ['timer_id']
+ }
+
+ update (now) { /* noop */ }
+}
+
+class TodayButton extends ClockElement {
+ update (now) {
+ this.querySelector('a').href = now.format("~Y-~m-~d.html")
+ }
+}
+customElements.define('today-button', TodayButton)
+
+
+class CurrentTime extends ClockElement {
+ update (now) {
+ this.innerHTML = now.format('~H:~M:~S')
}
}
+customElements.define('current-time', CurrentTime)