m-fields.mkiv /size: 1899 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=m-fields,
3%D        version=2010.03.14,
4%D          title=\CONTEXT\ Extra Modules,
5%D       subtitle=Fields,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\unprotect
15
16%D A rather old example of field usage is the following. It
17%D makes no sense to have this in the core.
18%D
19%D \starttyping
20%D before \fillinfield[oeps]{whatever} after
21%D \stoptyping
22
23\startJSpreamble{FillInField} used later
24    function CheckFillInField(right) {
25        if (event.value.toLowerCase() == right.toLowerCase()) {
26            event.target.hidden = true ;
27        }
28        event.value = ""
29    }
30\stopJSpreamble
31
32\newcount\noffillinfields
33
34\definefieldcategory
35  [fillinfield]
36  [\c!n=1024,
37   \c!height=\strutht,
38   \c!depth=\strutdp,
39   \c!align=\v!middle,
40   \c!color=red,
41   \c!fieldframecolor=blue,
42   \c!fieldbackgroundcolor=\s!white,
43   \c!validate=JS(CheckFillInField{\therightanswer})]
44
45\def\fillinfield
46  {\dosingleempty\dofillinfield}
47
48\def\dofillinfield[#1]#2%
49  {\dontleavehmode
50   \hbox
51     {\forgetall
52      \global\advance\noffillinfields\plusone
53      \edef\currentfillinfieldname{fillinfield:\number\noffillinfields}%
54      \useJSscripts[ans]%
55      \definefieldbody
56        [\currentfillinfieldname]
57        [\c!type=\v!line,
58         \c!category=fillinfield]%
59      \doifelsenothing{#1}
60        {\def\therightanswer{#2}}
61        {\def\therightanswer{#1}}%
62      \setbox0\hbox{\strut#2}%
63      \setbox2\hbox{\strut\therightanswer}%
64      \dimen0=\dimexpr\ifdim\wd0>\wd2 \wd0 \else \wd2 \fi + .2em\relax
65      \hbox to \wd0
66        {\wd0\zeropoint
67         \box0
68         \hss\fieldbody[\currentfillinfieldname][\c!width=\dimen0]\hss}}}
69
70\protect \endinput
71