aboutsummaryrefslogtreecommitdiff
path: root/static/clock.ts
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2021-10-04 17:40:59 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2021-10-04 17:43:45 +0200
commitc6c65f9e8273a5bc1b2ac1155d66003d2b98591c (patch)
treeda25ccd8af897dbc2671008e06f22d08d1208035 /static/clock.ts
parentwork (diff)
downloadcalp-c6c65f9e8273a5bc1b2ac1155d66003d2b98591c.tar.gz
calp-c6c65f9e8273a5bc1b2ac1155d66003d2b98591c.tar.xz
{.js => .ts} on relavant files.
Diffstat (limited to 'static/clock.ts')
-rw-r--r--static/clock.ts98
1 files changed, 98 insertions, 0 deletions
diff --git a/static/clock.ts b/static/clock.ts
new file mode 100644
index 00000000..d33d603a
--- /dev/null
+++ b/static/clock.ts
@@ -0,0 +1,98 @@
+
+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)