From 72792b048e6bbdd06ba3c775c8b870d64dcd856d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 26 Apr 2020 18:50:41 +0200 Subject: Sidebar event code now reusable for popups. --- module/output/html.scm | 51 ++++++++++++++++++++++++++++++-------------------- static/script.js | 11 ++++++++--- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/module/output/html.scm b/module/output/html.scm index bc8eefae..3cf110da 100644 --- a/module/output/html.scm +++ b/module/output/html.scm @@ -128,6 +128,9 @@ (define (event-debug-html event) + `(div (@ (class "eventlist")) + ,(fmt-single-event event)) + #; `(table (tbody ,@(hash-map->list @@ -364,18 +367,20 @@ ;; For sidebar, just text -(define (fmt-single-event ev) +(define* (fmt-single-event ev + optional: (attributes '()) + key: (fmt-header list)) ;; (format (current-error-port) "fmt-single-event: ~a~%" (attr ev 'X-HNH-FILENAME)) - `(article (@ (id ,(UID ev)) - (class "eventtext CAL_bg_" - ,(html-attr (or (attr (parent ev) 'NAME) "unknown")) - ,(when (and (attr ev 'PARTSTAT) (string= "TENTATIVE" (attr ev 'PARTSTAT))) - " tentative"))) - (h3 (a (@ (href "#" ,(date-link (as-date (attr ev 'DTSTART)))) - (class "hidelink")) - ,(when (attr ev 'RRULE) - `(span (@ (class "repeating")) "↺")) - ,(attr ev 'SUMMARY))) + `(article (@ ,@(assq-merge + attributes + `((class "eventtext CAL_bg_" + ,(html-attr (or (attr (parent ev) 'NAME) "unknown")) + ,(when (and (attr ev 'PARTSTAT) (string= "TENTATIVE" (attr ev 'PARTSTAT))) + " tentative"))))) + (h3 ,(fmt-header + (when (attr ev 'RRULE) + `(span (@ (class "repeating")) "↺")) + (attr ev 'SUMMARY))) (div ,(call-with-values (lambda () (fmt-time-span ev)) (match-lambda* [(start end) `(div ,start " — " ,end)] @@ -401,15 +406,21 @@ `(a (@ (href "#" ,s) (class "hidelink")) ,s)))) ,@(stream->list - (stream-map fmt-single-event - (stream-filter - (lambda (ev) - ;; If start was an earlier day - ;; This removes all descriptions from - ;; events for previous days, - ;; solving duplicates. - (date/-time<=? date (attr ev 'DTSTART))) - events)))))) + (stream-map + (lambda (ev) (fmt-single-event + ev `((id ,(UID ev))) + fmt-header: (lambda body + `(a (@ (href "#" ,(date-link (as-date (attr ev 'DTSTART)))) + (class "hidelink")) + ,@body)))) + (stream-filter + (lambda (ev) + ;; If start was an earlier day + ;; This removes all descriptions from + ;; events for previous days, + ;; solving duplicates. + (date/-time<=? date (attr ev 'DTSTART))) + events)))))) ;;; Table output diff --git a/static/script.js b/static/script.js index a5a5093d..274bcb86 100644 --- a/static/script.js +++ b/static/script.js @@ -128,9 +128,14 @@ function max(a, b) { /* https://stackoverflow.com/questions/21064101/understanding-offsetwidth-clientwidth-scrollwidth-and-height-respectively */ -function new_popup () { +function new_popup (event) { - popup = this.children[0].children[0] + console.log(event.target); + console.log(this); + // if (event.target !== this) return; + + /* popup = this.children[0].children[0] */ + popup = this.parentElement.getElementsByClassName("popup")[0]; popup.classList.toggle("show") /* x-axis fix */ @@ -197,7 +202,7 @@ window.onload = function () { // } days = document.getElementsByClassName("days")[0] - for (let e of days.getElementsByClassName("event")) { + for (let e of days.getElementsByClassName("body")) { e.onclick = new_popup; } -- cgit v1.2.3