aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-04-05 23:37:19 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-04-05 23:37:19 +0200
commit911df059a41d3d2a3d414126dfa88c4fa44ded45 (patch)
tree6e971dcb7ba71295cad2f9bb992f9bd7d7cca244
parentIntroduce datetime->unix-time and back. (diff)
downloadcalp-911df059a41d3d2a3d414126dfa88c4fa44ded45.tar.gz
calp-911df059a41d3d2a3d414126dfa88c4fa44ded45.tar.xz
Update JS to only try to mark today if posible.
-rw-r--r--module/output/html.scm12
-rw-r--r--static/script.js23
2 files changed, 30 insertions, 5 deletions
diff --git a/module/output/html.scm b/module/output/html.scm
index 64621e54..44e9d8d3 100644
--- a/module/output/html.scm
+++ b/module/output/html.scm
@@ -425,7 +425,9 @@
(define (td date)
`(td (@ (class
,(when (date< date start-date) "prev ")
- ,(when (date< end-date date) "next ")))
+ ,(when (date< end-date date) "next "))
+ (id ,(date->string date "td-~Y-~m-~d"))
+ )
(a (@ (href ,(cond
;; We are before our time interval
[(date< date start-date)
@@ -444,7 +446,7 @@
"~Y-~m-~d.html" )]
;; We are in our time interval
[else ""])
- "#" ,(date->string date "~Y-~m-~d"))
+ "#" ,(date-link date))
(class "hidelink"))
,(day date))))
@@ -511,6 +513,12 @@
(meta (@ (name description)
(content "Calendar for the dates between " ,(date->string start-date)
" and " ,(date->string end-date))))
+ ;; NOTE this is only for the time actually part of this calendar.
+ ;; overflowing times from pre-start and post-end is currently ignored here.
+ (meta (@ (name start-time)
+ (content ,(date->string start-date "~s"))))
+ (meta (@ (name end-time)
+ (content ,(date->string (date+ end-date (date day: 1)) "~s"))))
,(include-css "/static/style.css")
,(include-alt-css "/static/dark.css" '(title "Dark"))
,(include-alt-css "/static/light.css" '(title "Light"))
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