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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
%D \module
%D [ file=java-ini,
%D version=1998.01.30,
%D title=\CONTEXT\ JavaScript Macros,
%D subtitle=Initialization,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
\writestatus{loading}{ConTeXt JavaScript Macros / Initialization}
\registerctxluafile{java-ini}{1.001}
\unprotect
%D \macros
%D {JS*}
%D
%D Because \JAVASCRIPT's are activated by the user, for
%D instance by activating on a button, their support is closely
%D related to the referencing mechanism. Integration takes
%D place by
%D
%D \starttyping
%D \goto{calculate total}[Sum()]
%D \stoptyping
%D
%D The \type{()} classify this as a script. If they are absent,
%D the keyword is treated as a normal reference.
%D
%D One can pass arguments to such a script by saying:
%D
%D \starttyping
%D \goto{calculate total}[Sum(1.5,2.3)]
%D \stoptyping
%D \macros
%D {startJScode}
%D
%D A piece of \JAVASCRIPT\ code is defined by saying:
%D
%D \starttyping
%D \startJScode{name}
%D name = 4 ;
%D \stopJScode
%D \stoptyping
%D
%D This assumes uses no preamble or presumes that the preamble is
%D always loaded, the next definition also tells \CONTEXT\ to
%D actually include the preamble needed.
%D
%D \starttyping
%D \startJScode{uses} uses {later}
%D uses = 6 ;
%D \stopJScode
%D \stoptyping
%D
%D \macros
%D {startJSpreamble}
%D
%D One can define insert \JAVASCRIPT\ code at the document level
%D by using:
%D
%D \starttyping
%D \startJSpreamble{oeps}
%D oeps = 1 ;
%D \stopJSpreamble
%D \stoptyping
%D
%D which is the same as:
%D
%D \starttyping
%D \startJSpreamble{now} used now
%D now = 2 ;
%D \stopJSpreamble
%D \stoptyping
%D
%D while the next definition is only included when actually
%D used.
%D
%D \starttyping
%D \startJSpreamble{later} used later
%D later = 3 ;
%D \stopJSpreamble
%D \stoptyping
%D
%D This command may be used more that once, but always before
%D the first page is shipped out.
%D
%D \macros
%D {setJSpreamble, addtoJSpreamble}
%D
%D In addition to the previous preamble definitions, we can
%D set a preamble \quote {in||line} and add tokens to a
%D preamble.
%D
%D \macros
%D {useJSpreamblenow}
%D
%D This macro can be used to force inclusion of postponed
%D \JAVASCRIPT\ preambles.
\unexpanded\def\startJScode
{\begingroup\obeylualines\obeyluatokens\dostartJScode}
\long\def\dostartJScode#1\stopJScode
{\normalexpanded{\endgroup\ctxlua{javascripts.storecode(\!!bs#1\!!es)}}}
\let\stopJScode\relax
\unexpanded\def\startJSpreamble
{\begingroup\obeylualines\obeyluatokens\dostartJSpreamble}
\long\def\dostartJSpreamble#1\stopJSpreamble
{\normalexpanded{\endgroup\ctxlua{javascripts.storepreamble(\!!bs#1\!!es)}}}
\let\stopJSpreamble\relax
\def\setJSpreamble #1#2{\ctxlua{javascripts.storepreamble ("#1",\!!bs#2\!!es)}}
\def\addtoJSpreamble #1#2{\ctxlua{javascripts.addtopreamble ("#1",\!!bs#2\!!es)}}
\def\useJSpreamblenow #1{\ctxlua{javascripts.usepreamblenow("#1")}}
\def\finalflushJSpreamble{\iflocation\ctxlua{javascripts.flushpreambles()}\fi}
%D \macros
%D {useJSscripts}
%D
%D In due time, users will build their collections of scripts,
%D which can be used (loaded) when applicable. Although not all
%D public, we will provide some general purpose scripts,
%D collected in files with names like \type{java-...}. One can
%D load these scripts with \type{\useJSscripts}, like:
%D
%D \starttyping
%D \useJSscripts[fld]
%D \stoptyping
%D
%D The not so complicated implementation of this macro is:
\def\dodouseJSscripts#1%
{\doifelse{#1}\v!reset
{\let\allJSpreambles\empty}
{\ifcsname\c!file\f!javascriptprefix#1\endcsname \else
\startnointerference
\letgvalueempty{\c!file\f!javascriptprefix#1}%
\makeshortfilename[\f!javascriptprefix#1]%
\startreadingfile
\readsysfile\shortfilename{\showmessage\m!javascript1{#1}}\donothing
\stopreadingfile
\stopnointerference
\fi}}
\def\douseJSscripts[#1][#2]%
{\processcommalist[#1]\dodouseJSscripts
\processcommalist[#2]\useJSpreamblenow}
\def\useJSscripts
{\dodoubleempty\douseJSscripts}
\protect \endinput
|