diff options
author | Hans Hagen <pragma@wxs.nl> | 2019-02-22 20:29:46 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2019-02-22 20:29:46 +0100 |
commit | 7b271baae19db1528fbe6621bdf50af89a5a336b (patch) | |
tree | 4fc24a8f2be20aa90e90f6e1bcb62d69f4946235 /doc/context/sources/general/manuals/interaction/interaction-javascript.tex | |
parent | 67b9965fe473d18f13ed4c40f1e4e008eb870322 (diff) | |
download | context-7b271baae19db1528fbe6621bdf50af89a5a336b.tar.gz |
2019-02-22 19:43:00
Diffstat (limited to 'doc/context/sources/general/manuals/interaction/interaction-javascript.tex')
-rw-r--r-- | doc/context/sources/general/manuals/interaction/interaction-javascript.tex | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/doc/context/sources/general/manuals/interaction/interaction-javascript.tex b/doc/context/sources/general/manuals/interaction/interaction-javascript.tex new file mode 100644 index 000000000..64e784464 --- /dev/null +++ b/doc/context/sources/general/manuals/interaction/interaction-javascript.tex @@ -0,0 +1,136 @@ +% language=uk + +\environment interaction-style + +\startcomponent interaction-javascript + +\startchapter[title={JavaScript}] + +Annotations can be controlled with \JAVASCRIPT\ but it really depends on the +viewer if it works out well. Using these scripts is a multi||step process where +common functions and data structures can be shared and collected in preambles: + +\starttyping +\startJSpreamble {name} + MyCounter = 0 ; +\stopJSpreamble +\stoptyping + +The more action oriented scripts are defined as: + +\starttyping +\startJScode {increment} + MyCounter = MyCounter + 1 ; // or: ++MyCounter ; +\stopJScode +\stoptyping + +This script is executed with: + +\starttyping +\goto {advance by one} [JS(increment)] +\stoptyping + +Nicer is to define a function: + +\starttyping +\startJSpreamble {helpers} used now + function Increment(n) { + MyCounter = MyCounter + n ; + } +\stopJSpreamble +\stoptyping + +and then say: + +\starttyping +\goto {advance by one} [JS(Increment{5})] +\stoptyping + +The distribution contains a collection of scripts that can be preloaded and used +when needed. You can recognize the files by the \type {java-imp-} prefix. To +prevent all preambles ending up in the \PDF\ file, we can say: + +\starttyping +\startJSpreamble {something} used later +\stopJSpreamble +\stoptyping + +We already saw that one can also say \type {used now} and there's also a way +to filter specific preambles on usage: + +\starttyping +\startJScode {mything} uses {something} +\stopJScode +\stoptyping + +One should be aware of the fact that there is no decent way to check if every +script is all right! Even worse, the \JAVASCRIPT\ interpreter currently used in +the \ACROBAT\ tools is not reentrant, and breaks down on typos + +The full repertoire of commands is: + +\showsetup{startJScode} + +\showsetup{startJSpreamble} + +\showsetup{addtoJSpreamble} + +\showsetup{setJSpreamble} + +As we're into \LUA\ and because \LUA\ is so lightweight I've wondered several +times now if it would make sense to embed \LUA\ in \PDF\ viewers. After all, +annotations are an extension mechanism. In the early days of \PDF\ this was +actually quite doable because \ACROBAT\ reader (and exchange) had a plugin model. +However, the more functionality ended up in the program, the least interesting +(and popular) the plugins mechanism became. Some open source viewers have an +\API\ so in principle adding the lightweight \LUA\ interpreter (of course with +\LPEG, and quite probably without file \IO) is possible. It has been discussed at +a recent \CONTEXT\ meeting, so who knows \unknown For now we're stuck with +\JAVASCRIPT. + +An example of \JAVASCRIPT\ usage is the following, where we load a video and add +some controls. Beware that this kind of functionality is very viewer dependent +and therefore also very unstable over time. Even worse, if you look at the loaded +\JAVASCRIPT\ file you will notice a dependency on soon obsolete (in \ACROBAT\ at +least) shockwave support. First we load a library that will predefine a video +graphic: and then create an instance: + +\starttyping +\useJSscripts[vplayer] + +\setupinteraction + [state=start] + +\externalfigure + [shockwave] + [frame=on, + width=480pt, + height=270pt, + file=test.mp4, + label=foo] +\stoptyping + +The controls are defined with: + +\starttyping +\goto{START} [JS(StartShockwave{foo})] +\goto{REWIND}[JS(RewindShockwave{foo})] +\goto{PAUSE} [JS(PauseShockwave{foo})] +\goto{STOP} [JS(StopShockwave{foo})] +\stoptyping + +or, as we have some defined reference shortcuts: + +\starttyping +\goto{START} [StartShockwave{foo}] +\goto{REWIND}[RewindShockwave{foo}] +\goto{PAUSE} [PauseShockwave{foo}] +\goto{STOP} [StopShockwave{foo}] +\stoptyping + +It's actually not that hard to add all kind of functionality if only we could be +sure of stable support and continuity. + +\stopchapter + +\stopcomponent |