From e28b54810bb42b21a069a1257cf5e59e06c735a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 30 Sep 2021 01:47:38 +0200 Subject: Replace today-button with web component. --- static/clock.js | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'static/clock.js') 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) -- cgit v1.2.3 From 927bd58d3340965328f0ccd05f865175b49a6ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 1 Oct 2021 03:34:06 +0200 Subject: Got date-times working in new system. --- static/clock.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'static/clock.js') diff --git a/static/clock.js b/static/clock.js index 240041a9..d33d603a 100644 --- a/static/clock.js +++ b/static/clock.js @@ -75,7 +75,7 @@ class ClockElement extends HTMLElement { this.update(new Date) } - static get observerAttributes () { + static get observedAttributes () { return ['timer_id'] } -- cgit v1.2.3 From c6c65f9e8273a5bc1b2ac1155d66003d2b98591c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 4 Oct 2021 17:40:59 +0200 Subject: {.js => .ts} on relavant files. --- static/clock.js | 98 --------------------------------------------------------- 1 file changed, 98 deletions(-) delete mode 100644 static/clock.js (limited to 'static/clock.js') diff --git a/static/clock.js b/static/clock.js deleted file mode 100644 index d33d603a..00000000 --- a/static/clock.js +++ /dev/null @@ -1,98 +0,0 @@ - -class Clock { - update(now) { - } -} - - -class Timebar extends Clock { - - constructor(start_time, end_time) { - super(); - this.start_time = start_time; - this.end_time = end_time; - this.bar_object = false - } - - - update(now) { - // if (! (this.start_time <= now.getTime() && now.getTime() < this.end_time)) - // return; - - var event_area = document.getElementById(now.format("~Y-~m-~d")) - - if (event_area) { - if (this.bar_object) { - this.bar_object.parentNode.removeChild(this.bar_object) - } else { - this.bar_object = makeElement ('div', { - id: 'bar', - className: 'eventlike current-time', - }); - } - - this.bar_object.style.top = date_to_percent(now) + "%"; - event_area.append(this.bar_object) - } - } -} - -class SmallcalCellHighlight extends Clock { - constructor(small_cal) { - super(); - this.small_cal = small_cal; - this.current_cell = false - } - - update(now) { - if (this.current_cell) { - this.current_cell.style.border = ""; - } - - /* This is expeced to fail if the current date is not - currently on screen. */ - this.current_cell = this.small_cal.querySelector( - "time[datetime='" + now.format("~Y-~m-~d") + "']"); - - if (this.current_cell) { - this.current_cell.style.border = "1px solid black"; - } - } -} - -/* -------------------------------------------------- */ - -class ClockElement extends HTMLElement { - constructor () { - super(); - } - - 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 observedAttributes () { - 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) -- cgit v1.2.3