From 3d2c2ba29c7fa6854e3734ce3d8635a37b6ecc2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 10 Aug 2020 16:06:33 +0200 Subject: Start breaking apart HTML modules. --- .gitignore | 2 +- module/html/components.scm | 122 ++++++++++ module/output/html-search.scm | 59 +++-- module/output/html.scm | 509 ++++++++++++++++++------------------------ module/vcomponent/search.scm | 1 + 5 files changed, 366 insertions(+), 327 deletions(-) create mode 100644 module/html/components.scm diff --git a/.gitignore b/.gitignore index a6b94637..f4c88a51 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ *.x -html +/html diff --git a/module/html/components.scm b/module/html/components.scm new file mode 100644 index 00000000..77156fc5 --- /dev/null +++ b/module/html/components.scm @@ -0,0 +1,122 @@ +(define-module (html components) + :use-module (util) + :use-module (util exceptions) + :export (xhtml-doc) + ) + +;; Wraps a number of sxml forms into a valid sxhtml-tree. +(define-syntax xhtml-doc + (syntax-rules (@) + ((_ (@ attr ...) body ...) + `(*TOP* + (*PI* xml "version=\"1.0\" encoding=\"utf-8\"") + (html (@ (xmlns "http://www.w3.org/1999/xhtml") attr ...) + body ...))) + ((_ body ...) + (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}. +(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)")) + )))) + +;; Generates a button or button-like link. +;; TODO
inside