diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-04-05 23:37:19 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-04-05 23:37:19 +0200 |
commit | 911df059a41d3d2a3d414126dfa88c4fa44ded45 (patch) | |
tree | 6e971dcb7ba71295cad2f9bb992f9bd7d7cca244 /static/script.js | |
parent | Introduce datetime->unix-time and back. (diff) | |
download | calp-911df059a41d3d2a3d414126dfa88c4fa44ded45.tar.gz calp-911df059a41d3d2a3d414126dfa88c4fa44ded45.tar.xz |
Update JS to only try to mark today if posible.
Diffstat (limited to '')
-rw-r--r-- | static/script.js | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/static/script.js b/static/script.js index 7f7a235b..7a0fe457 100644 --- a/static/script.js +++ b/static/script.js @@ -12,7 +12,10 @@ function time_to_percent (time) { return hour_to_part(time.getHours() + (time.getMinutes() / 60)) + "%" } -var start_time = 0 +let start_time = new Date(); +let end_time = new Date(); + +var event_start_time = 0 var start_fraq = 0 var parent @@ -31,7 +34,7 @@ function onmousedownhandler (e) { console.log(comp.clientHeight) fraq = e.offsetY / comp.clientHeight start_fraq = fraq - start_time = part_to_hour(fraq); + event_start_time = part_to_hour(fraq); createdEvent = document.createElement("div"); createdEvent.className = "event generated"; createdEvent.style.pointerEvents = "none"; @@ -57,7 +60,7 @@ function onmousemovehandler (e) { function onmouseuphandler (e) { var end_time = part_to_hour(e.offsetY / this.clientHeight); - console.log("Creating event " + start_time + " - " + end_time); + console.log("Creating event " + event_start_time + " - " + end_time); createdEvent = false; for (let e of parent.children) { @@ -73,9 +76,13 @@ function time_to_date (time) { } var bar_object = false +var current_cell = false function update_current_time_bar () { var now = new Date() + if (! (start_time <= now.getTime() && now.getTime() < end_time)) + return; + var event_area = document.getElementById(time_to_date(now)) if (bar_object) { @@ -88,6 +95,14 @@ function update_current_time_bar () { bar_object.style.top = time_to_percent(now) event_area.append(bar_object) + + /* */ + + if (current_cell) { + current_cell.style.border = ""; + } + current_cell = document.getElementById("td-" + time_to_date(now)) + current_cell.style.border = "1px solid black"; } function toggle_event_pupup () { @@ -96,6 +111,8 @@ function toggle_event_pupup () { } window.onload = function () { + start_time.setTime(document.querySelector("meta[name='start-time']").content * 1000) + end_time.setTime(document.querySelector("meta[name='end-time']").content * 1000) update_current_time_bar() // once a minute for now, could probably be slowed to every 10 minutes |