1%D \module 2%D [ file=java-ini, 3%D version=1998.01.30, 4%D title=\CONTEXT\ JavaScript Macros, 5%D subtitle=Initialization, 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\writestatus{loading}{ConTeXt JavaScript Macros / Initialization} 15 16\registerctxluafile{java-ini}{} 17 18\unprotect 19 20%D \macros 21%D {JS*} 22%D 23%D Because \JAVASCRIPT's are activated by the user, for 24%D instance by activating on a button, their support is closely 25%D related to the referencing mechanism. Integration takes 26%D place by 27%D 28%D \starttyping 29%D \goto{calculate total}[Sum()] 30%D \stoptyping 31%D 32%D The \type{()} classify this as a script. If they are absent, 33%D the keyword is treated as a normal reference. 34%D 35%D One can pass arguments to such a script by saying: 36%D 37%D \starttyping 38%D \goto{calculate total}[Sum(1.5,2.3)] 39%D \stoptyping 40 41%D \macros 42%D {startJScode} 43%D 44%D A piece of \JAVASCRIPT\ code is defined by saying: 45%D 46%D \starttyping 47%D \startJScode{name} 48%D name = 4 ; 49%D \stopJScode 50%D \stoptyping 51%D 52%D This assumes uses no preamble or presumes that the preamble is 53%D always loaded, the next definition also tells \CONTEXT\ to 54%D actually include the preamble needed. 55%D 56%D \starttyping 57%D \startJScode{uses} used {later} 58%D uses = 6 ; 59%D \stopJScode 60%D \stoptyping 61%D 62%D \macros 63%D {startJSpreamble} 64%D 65%D One can define insert \JAVASCRIPT\ code at the document level 66%D by using: 67%D 68%D \starttyping 69%D \startJSpreamble{oeps} 70%D oeps = 1 ; 71%D \stopJSpreamble 72%D \stoptyping 73%D 74%D which is the same as: 75%D 76%D \starttyping 77%D \startJSpreamble{now} used now 78%D now = 2 ; 79%D \stopJSpreamble 80%D \stoptyping 81%D 82%D while the next definition is only included when actually 83%D used. 84%D 85%D \starttyping 86%D \startJSpreamble{later} used later 87%D later = 3 ; 88%D \stopJSpreamble 89%D \stoptyping 90%D 91%D This command may be used more that once, but always before 92%D the first page is shipped out. 93%D 94%D \macros 95%D {setJSpreamble, addtoJSpreamble} 96%D 97%D In addition to the previous preamble definitions, we can 98%D set a preamble \quote {in||line} and add tokens to a 99%D preamble. 100%D 101%D \macros 102%D {useJSpreamblenow} 103%D 104%D This macro can be used to force inclusion of postponed 105%D \JAVASCRIPT\ preambles. 106 107\def\m_java_escape_u{\letterbackslash u} 108 109\unexpanded\def\startJScode 110 {\begingroup 111 \obeylualines 112 \obeyluatokens 113 \let\u\m_java_escape_u 114 \java_start_code} 115 116\def\java_start_code#1\stopJScode 117 {\normalexpanded{\endgroup{#1}}} 118 119\let\stopJScode\relax 120 121\unexpanded\def\startJSpreamble 122 {\begingroup 123 \obeylualines 124 \obeyluatokens 125 \let\u\m_java_escape_u 126 \java_start_preamble} 127 128\def\java_start_preamble#1\stopJSpreamble 129 {\normalexpanded{\endgroup{#1}}} 130 131\let\stopJSpreamble\relax 132 133\unexpanded\def\setJSpreamble #1#2{ {#1}{#2}} 134\unexpanded\def\addtoJSpreamble#1#2{{#1}{#2}} 135 136%D \macros 137%D {useJSscripts} 138%D 139%D In due time, users will build their collections of scripts, 140%D which can be used (loaded) when applicable. Although not all 141%D public, we will provide some general purpose scripts, 142%D collected in files with names like \type{java-...}. One can 143%D load these scripts with \type{\useJSscripts}, like: 144%D 145%D \starttyping 146%D \useJSscripts[fld] 147%D \stoptyping 148%D 149%D The not so complicated implementation of this macro is: 150 151\unexpanded\def\useJSscripts 152 {\dodoubleempty\java_use_scripts} 153 154\def\java_use_scripts[#1][#2]% 155 { {#1}% two steps as this one calls tex code 156 {#2}}% so this one comes later 157 158\unexpanded\def\useJSpreamble 159 {\dosingleempty\java_use_preamble} 160 161\def\java_use_preamble[#1]% 162 {{#1}}% so this one comes later 163 164%D Here: 165 166\definefilesynonym[java-imp-fld.mkiv] [java-imp-fields.mkiv] 167\definefilesynonym[java-imp-stp.mkiv] [java-imp-steps.mkiv] 168\definefilesynonym[java-imp-fil.mkiv] [java-imp-print.mkiv] 169\definefilesynonym[java-imp-rhh.mkiv] [java-imp-highlight.mkiv] 170\definefilesynonym[java-imp-exa.mkiv] [java-imp-example.mkiv] 171 172\protect \endinput 173 |