diff --git a/spoiler1.rkt b/spoiler1.rkt index 4e7d6f5b..bcd1d7fa 100644 --- a/spoiler1.rkt +++ b/spoiler1.rkt @@ -1,4 +1,4 @@ -#lang at-exp racket +#lang racket (provide spoiler-wrapper-collapsed spoiler-default @@ -8,15 +8,15 @@ spoiler1 spler) -@(require scribble/manual - scribble/core - scribble/decode - scribble/html-properties - hyper-literate - (for-syntax syntax/parse)) +(require scribble/manual + scribble/core + scribble/decode + scribble/html-properties + hyper-literate + (for-syntax syntax/parse)) -@(define spoiler-css - #" +(define spoiler-css + #" .spoiler-wrapper-expanded .spoiler-default, .spoiler-wrapper-expanded .spoiler-button-default-to-alt { display:none; @@ -32,103 +32,101 @@ } ") -@(define spoiler-js - (string->bytes/utf-8 - @string-append|{ - function toggleSpoiler(e) { +(define spoiler-js + (string->bytes/utf-8 + #<string 'name) - (list (css-addition spoiler-css) - (js-addition spoiler-js) - (alt-tag "div"))))) +(define-syntax-rule (def-style name) + (define name + (style (symbol->string 'name) + (list (css-addition spoiler-css) + (js-addition spoiler-js) + (alt-tag "div"))))) -@(def-style spoiler-wrapper-collapsed) -@(def-style spoiler-default) -@(def-style spoiler-alt) +(def-style spoiler-wrapper-collapsed) +(def-style spoiler-default) +(def-style spoiler-alt) -@(define (spoiler-button-default-to-alt txt) - (hyperlink - #:style (style "spoiler-button-default-to-alt" - (list (css-addition spoiler-css) - (js-addition spoiler-js) - (attributes - '([onclick . "toggleSpoiler(this);"])))) - "#" - txt)) +(define (spoiler-button-default-to-alt txt) + (hyperlink + #:style (style "spoiler-button-default-to-alt" + (list (css-addition spoiler-css) + (js-addition spoiler-js) + (attributes + '([onclick . "return toggleSpoiler(this, true);"])))) + "#" + txt)) -@(define (spoiler-button-alt-to-default txt) - (hyperlink - #:style (style "spoiler-button-alt-to-default" - (list (css-addition spoiler-css) - (js-addition spoiler-js) - (attributes - '([onclick . "toggleSpoiler(this);"])))) - "#" - txt)) +(define (spoiler-button-alt-to-default txt) + (hyperlink + #:style (style "spoiler-button-alt-to-default" + (list (css-addition spoiler-css) + (js-addition spoiler-js) + (attributes + '([onclick . "return toggleSpoiler(this, false);"])))) + "#" + txt)) -@(define (spoiler1 default button-default→alt button-alt→default alternate) - (nested-flow spoiler-wrapper-collapsed - (list - (paragraph (style #f '()) - (spoiler-button-default-to-alt button-default→alt)) - (nested-flow spoiler-default - (decode-flow default)) - (paragraph (style #f '()) - (spoiler-button-alt-to-default button-alt→default)) - (nested-flow spoiler-alt - (decode-flow alternate))))) +(define (spoiler1 default button-default→alt button-alt→default alternate) + (nested-flow spoiler-wrapper-collapsed + (list + (paragraph (style #f '()) + (spoiler-button-default-to-alt button-default→alt)) + (nested-flow spoiler-default + (decode-flow default)) + (paragraph (style #f '()) + (spoiler-button-alt-to-default button-alt→default)) + (nested-flow spoiler-alt + (decode-flow alternate))))) -@(define-syntax spler - (syntax-parser - [(_ name default ... #:expanded expanded ...) - #'(begin - @chunk[#:save-as ck1 +(define-syntax spler + (syntax-parser + [(_ name default ... #:expanded expanded ...) + #'(begin + (chunk #:save-as ck1 #:display-only #:button (list " " (smaller (spoiler-button-default-to-alt "expand"))) name - default ...] + default ...) - @chunk[#:save-as ck2 + (chunk #:save-as ck2 #:button (list " " (smaller (spoiler-button-alt-to-default "collapse"))) name - expanded ...] + expanded ...) (nested-flow spoiler-wrapper-collapsed (list (nested-flow spoiler-default (decode-flow (ck1))) (nested-flow spoiler-alt - (decode-flow (ck2))))) - - ;@spoiler1[@(ck1) - ; "expand" - ; "collapse" - ; @(ck2)] - - )])) \ No newline at end of file + (decode-flow (ck2))))))])) \ No newline at end of file