1
2
3
4
5
6
7
8
9
10
11
12
13
14\unprotect
15
16
17
18
19
20
21
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 |