add today btn

This commit is contained in:
Finn van Reenen
2023-12-04 11:04:54 +01:00
parent 9c04d4ff78
commit d1d48d5265

27
main.js
View File

@@ -1,6 +1,7 @@
const obsidian = require('obsidian');
const Plugin = obsidian.Plugin;
const ItemView = obsidian.ItemView;
const getIcon = obsidian.getIcon;
const DateFormat = {
week: "y[0-9]{2}w[0-9]{2}",
@@ -290,7 +291,11 @@ class CalendarView extends ItemView
// month
this.monthEl = container.createEl("div", { cls: "frcal__month" });
this.monthEl.createEl("div", { cls: "frcal__time" });
let today = this.monthEl.createEl("div", { cls: "frcal__time" });
today.append(getIcon('calendar-days'));
today.addEventListener('click', function(e) {
this.gotoThisWeek();
}.bind(this));
this.mountFirstEl = this.monthEl.createEl("div", { cls: "frcal__month_first", attr: { style: "flex: 70" } });
this.mountFirstSpanEl = this.mountFirstEl.createEl("span");
this.mountSecondEl = this.monthEl.createEl("div", { cls: "frcal__month_second", attr: { style: "flex: 0" } });
@@ -367,13 +372,31 @@ class CalendarView extends ItemView
this.updateWeek();
}
gotoThisWeek(week = '')
{
if (week == '')
{
this.week = stringifySingleDate(moment()).match(DateFormat.week)[0];
}
else if (typeof week == 'string')
{
// format of this.week is very strikt, this way every format the parser suports will work.
this.week = stringifySingleDate(parseSingleDate(week, moment())).match(DateFormat.week)[0];
}
else
{
this.week = stringifySingleDate(week).match(DateFormat.week)[0];
}
this.updateWeek();
}
updateWeek()
{
let months = ["januarie", "februarie", "maart", "april", "mei", "juni", "juli", "augustis", "september", "oktober", "november", "december"];
let monthF = parseSingleDate(this.week + " ma 00:00am",).month();
this.mountFirstSpanEl.innerText = (monthF+1).toString() + " - " + months[monthF];
this.weekNumEl.innerText = this.week.match(/[0-9]+$/)[0];
this.weekNumEl.innerHTML = this.week.substring(0, 3) + '<br/>' + this.week.substring(3, 6);
let zoDate = parseSingleDate(this.week + " zo 00:00am");
let monthS = zoDate.month();