java-imp-steps.mkiv /size: 3259 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=java-imp-steps, % was: java-stp
3%D        version=2004.03.15,
4%D          title=\CONTEXT\ JavaScript Macros,
5%D       subtitle=Stepping,
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% we define ocglist global, otherwise we quickly run into a memory hog (even
15% out of memory in a 512 Meg machine)
16
17% we cannot use doc_visited[this.pageNum] instead of doc_currentstep because
18% of some funny side effect (i.e. dup or so)
19
20% todo: test with later as we do autoinsert now
21
22\startJSpreamble Steps used now
23
24var doc_ocglist     = this.getOCGs() ;
25var doc_stepname    = "step" ;
26var doc_currentstep =  0 ;
27var doc_maxstep     = 50 ;
28var doc_visited     = new Array() ;
29var doc_busy        = new Array() ;
30
31function SetupStepper(layername,laststep) {
32    doc_stepname = layername ;
33    doc_maxstep  = laststep ;
34    for (var i=0; i<=this.numPages; i++) {
35        doc_visited[i] = 0 ;
36        doc_busy[i] = 0 ;
37    }
38}
39
40for (var i=0; i<=this.numPages; i++) {
41    doc_visited[i] = 0 ;
42    doc_busy[i] = 0 ;
43}
44
45function GetOCG(name) {
46    for (var i=0; i < doc_ocglist.length; i++) {
47        if (doc_ocglist[i].name == name) {
48            return doc_ocglist[i] ;
49        }
50    }
51    return null ;
52}
53
54function CheckBusy() {
55     var ocg = GetOCG("step:busy") ;
56     if (ocg != null) {
57         if (doc_visited[this.pageNum]==0) {
58             ocg.state = true ;
59         } else {
60             if (doc_visited[this.pageNum]<doc_busy[this.pageNum]) {
61                 ocg.state = true ;
62             } else {
63                 ocg.state = false ;
64             }
65         }
66     }
67}
68
69function SetStepper(maxstep,state) {
70    for (var i=1; i<=maxstep; i++) {
71        try {
72            var ocg = GetOCG(doc_stepname + ':' + String(i)) ;
73            if (ocg != null) {
74                ocg.state = state ;
75            }
76        } catch (e) {
77            return ;
78        }
79    }
80}
81
82function CheckStepper(maxsteps) {
83    SetStepper(doc_visited[this.pageNum], true) ;
84    doc_busy[this.pageNum] = Number(maxsteps) ;
85    doc_currentstep = doc_visited[this.pageNum] ;
86    CheckBusy() ;
87}
88
89function ResetStepper() {
90    SetStepper(doc_maxstep, false) ;
91    doc_currentstep = 0 ;
92}
93
94function InvokeStepper() {
95    try {
96        if (doc_currentstep<doc_busy[this.pageNum]) {
97            doc_currentstep += 1 ;
98            doc_visited[this.pageNum] = doc_currentstep ;
99            var ocg = GetOCG(doc_stepname + ':' + String(doc_currentstep)) ;
100            if (ocg != null) {
101                ocg.state = true ;
102            }
103        } else {
104            if (this.pageNum+1==this.numPages) {
105                this.pageNum  = 0 ;
106            } else {
107                this.pageNum += 1 ;
108            }
109        }
110        CheckBusy() ;
111    } catch (e) {
112        return ;
113    }
114}
115
116\stopJSpreamble
117
118% \definereference [SetupStepper]  [JS(SetupStepper{step,50})]
119% \definereference [ResetStepper]  [JS(ResetStepper)]
120% \definereference [CheckStepper]  [JS(CheckStepper{\StepCounter})]
121% \definereference [InvokeStepper] [JS(InvokeStepper)]
122
123\endinput
124