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