From d4640c76287310b40cc5e76b430635c0a006708c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 21 Apr 2022 15:10:17 +0200 Subject: Repair and rewrote sliders in HTML. The old ones where broken since i accidentally removed setVar, instead of reintrocuding that, I rewrote slider-inputs as web components, which frees us of having some hacky javascript in the html code. --- module/calp/html/components.scm | 37 ++++----------- static/_slider_input.scss | 10 ++++ static/components/slider.ts | 101 ++++++++++++++++++++++++++++++++++++++++ static/elements.ts | 2 + static/style.scss | 9 +--- 5 files changed, 125 insertions(+), 34 deletions(-) create mode 100644 static/_slider_input.scss create mode 100644 static/components/slider.ts diff --git a/module/calp/html/components.scm b/module/calp/html/components.scm index 6642b1fe..2aa95aa6 100644 --- a/module/calp/html/components.scm +++ b/module/calp/html/components.scm @@ -18,39 +18,22 @@ (xhtml-doc (@) body ...)))) -;; Add a slider with an associated number input. Keeps the two in check. -;; Uses the js function setVar (which must be provided elsewhere) -;; set the the value of @var{variable}. +;; Add a slider with an associated number input. Keeps the two in sync. (define*-public (slider-input key: variable (min 0) (max 10) (step 1) (value 1) (unit "")) - (let ((groupname (symbol->string (gensym "slider")))) - `(div (@ (class "input-group")) - (script - "function " ,groupname "fn (value) {" - "setVar('" ,variable "', value + '" ,unit "');" - "for (let el of document.getElementsByClassName('" ,groupname "')) {" - " el.value = value;" - "}}") - (input (@ (type "range") - (class ,groupname) - (min ,min) - (max ,max) - (step ,step) - (value ,value) - (oninput ,groupname "fn(this.value)") - )) - (input (@ (type "number") - (class ,groupname) - (min ,min) - (max ,max) - (step ,step) - (value ,value) - (oninput ,groupname "fn(this.value)")) - )))) + + `(slider-input + (@ (min ,min) + (max ,max) + (step ,step) + (value ,value) + (oninput + ,(format #f "document.documentElement.style.setProperty('--~a', this.value + '~a')" + variable unit))))) ;; Generates a button or button-like link. ;; TODO
inside