From 964c1f1dd630c348ce622c78fab9ce87378a8ab3 Mon Sep 17 00:00:00 2001 From: FReenen Date: Mon, 13 May 2024 21:28:51 +0200 Subject: [PATCH] add line for curent time (#4) --- fr-calendar.css | 8 +++----- main.js | 27 +++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/fr-calendar.css b/fr-calendar.css index db3456f..002f53c 100644 --- a/fr-calendar.css +++ b/fr-calendar.css @@ -102,11 +102,9 @@ width: 100%; background-color: var(--color-base-30); } -.frcal__day:nth-child(odd) .frcal__hourline { - /* background-color: var(--background-primary); */ -} -.frcal__day:nth-child(even) .frcal__hourline { - /* background-color: var(--background-primary-alt); */ +.frcal__hourline.frcal__now { + background-color: var(--color-accent); + position: relative; } .frcal__event span { diff --git a/main.js b/main.js index 5679785..5524764 100644 --- a/main.js +++ b/main.js @@ -469,7 +469,7 @@ class CalendarView extends ItemView this.updateWeek(); } - gotoThisWeek(week = '') + gotoThisWeek(week = '') { if (week == '') { @@ -499,7 +499,7 @@ class CalendarView extends ItemView if (monthF != monthS) { this.mountSecondSpanEl.innerText = (monthS+1).toString() + " - " + DateFormat.months[monthS]; - + let dow = zoDate.date(); this.mountFirstEl.setAttr("style", "flex: " + ((7-dow)*10).toString()); @@ -512,11 +512,19 @@ class CalendarView extends ItemView this.mountSecondEl.setAttr("style", "flex: 0") } - + let today = parseSingleDate("12:00pm", moment()); for (let day = 0; day < 7; day++) { let date = parseSingleDate(this.week + " " + DateFormat.days[(day + 1) % 7] + " 12:00pm"); this.dayHeads[day].innerHTML = DateFormat.daysLong[day] + "
" + date.date().toString(); + if (date.diff(today, "minutes") == 0) + { + this.dayHeads[day].style.color = "var(--color-accent)"; + } + else + { + this.dayHeads[day].style.color = ""; + } } this.updateEvents(); @@ -533,17 +541,28 @@ class CalendarView extends ItemView // "location": null, // "state": "reminder" // }; - + // clear events + let today = parseSingleDate("12:00pm", moment()); for (let day = 0; day < 7; day++) { this.allday[day].innerHTML = ""; this.timed[day].innerHTML = ""; + // add hour lines let hourlinesEl = this.timed[day].createEl("div", { cls: "frcal__hourlines" }); + hourlinesEl.createEl("div", { cls: "frcal__hourline", attr: { style: "margin-top: 0px"} }) for (let hour = 0; hour < 11; hour++) { hourlinesEl.createEl("div", { cls: "frcal__hourline", attr: { style: "margin-top: " + (120*this.zoom-1).toString() + "px"} }) } + // add current time line + if (parseSingleDate(this.week + " " + DateFormat.days[(day+1) % 7] + " 12:00pm").diff(today, "minutes") == 0) + { + let time = moment(); + time = time.hour()*60 + time.minute(); + this.timed[day].createEl("div", { cls: "frcal__hourlines" }) + .createEl("div", { cls: "frcal__hourline frcal__now", attr: { style: "top: " + (time*this.zoom-1).toString() + "px"} }) + } } let start = parseSingleDate(this.week + " ma 00:00am");