From e0950b6c7463653c7049de196dc6448bf5e03fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 3 May 2020 00:27:36 +0200 Subject: Add [today] and [jump to] button in frontend. Currently the JavaScript updates these buttons to work, but they by default reference backend endpoints which are not yet written. --- static/script.js | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'static/script.js') diff --git a/static/script.js b/static/script.js index b9b6a5ba..579f4980 100644 --- a/static/script.js +++ b/static/script.js @@ -138,6 +138,11 @@ function update_current_time_bar () { current_cell = document.querySelector( ".small-calendar time[datetime='" + time_to_date(now) + "']"); current_cell.style.border = "1px solid black"; + + /* Update [today] button */ + + document.getElementById("today-button").href + = time_to_date(new Date) + ".html"; } function min(a, b) { @@ -181,13 +186,35 @@ window.onload = function () { } } - document.onkeydown = function (evt) { - evt = evt || window.event; - if (evt.key.startsWith("Esc")) { - close_all_popups(); - } + document.onkeydown = function (evt) { + evt = evt || window.event; + if (! evt.key) return; + if (evt.key.startsWith("Esc")) { + close_all_popups(); } + } + + /* Replace backend-driven [today] link with frontend, with one that gets + correctly set in the frontend. + Similarly, update the go to specific date button into a link which updates + wheneven the date form updates. + */ + + let jumpto = document.getElementsByClassName("jump-to")[0]; + let gotodatebtn = jumpto.getElementsByTagName("button")[0]; + let golink = document.createElement("a"); + golink.classList.add("btn"); + let target_href = time_to_date(new Date) + ".html"; + document.getElementById("today-button").href = target_href; + golink.href = target_href; + golink.innerHTML = gotodatebtn.innerHTML; + gotodatebtn.replaceWith(golink); + + jumpto.getElementsByTagName("input")[0].onchange = function () { + let date = time_to_date(this.valueAsDate) + golink.href = date + ".html"; + } } $(document).ready(function() { -- cgit v1.2.3