From ffb3c7baf25e01d69053676ce7d8dc0291601a9e Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Tue, 19 Jul 2022 16:39:07 +0000 Subject: [PATCH] Add event listener to activate a day note on click --- Timeline Widget/1_render.html/script.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Timeline Widget/1_render.html/script.js b/Timeline Widget/1_render.html/script.js index 52668c0..9fd52b1 100644 --- a/Timeline Widget/1_render.html/script.js +++ b/Timeline Widget/1_render.html/script.js @@ -145,6 +145,24 @@ async function renderTimeline() { // Add present time marker based on "timeline_present" label timeline.setCurrentTime(timeline_options.timeline_present); + // Add event listener to activate a day note on click + timeline.on("click", async (e) => { + const timelineHeight = timeline.dom.centerContainer.getBoundingClientRect().height; + if (e.y <= timelineHeight) { + // ignore clicks on the timeline + return; + } + const effectiveY = e.y - timelineHeight; + if (effectiveY > timeline.dom.bottom.children[0].children[0].getBoundingClientRect().height) { + // ignore clicks on the month axis + return; + } + const day = e.time.toISOString().substr(0, 10); + const todayNote = await api.getDayNote(day); + api.waitUntilSynced(); + await api.openTabWithNote(todayNote.noteId, true); + }); + // Create UI menu buttons from added groups (that are not forced into another group) menu.innerHTML = ''; const toggle_groups = groups.get({filter:function(item){return(item.forceGroup===null && item.id!=='default')}});