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 24
var
doc
_
ocglist
=
this
.
getOCGs
()
;
25
var
doc
_
stepname
=
"
step
"
;
26
var
doc
_
currentstep
=
0
;
27
var
doc
_
maxstep
=
5
0
;
28
var
doc
_
visited
=
new
Array
()
;
29
var
doc
_
busy
=
new
Array
()
;
30 31
function
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 40
for
(
var
i
=
0
;
i
<=
this
.
numPages
;
i
++
)
{
41
doc
_
visited
[
i
]
=
0
;
42
doc
_
busy
[
i
]
=
0
;
43
}
44 45
function
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 54
function
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 69
function
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 82
function
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 89
function
ResetStepper
()
{
90
SetStepper
(
doc
_
maxstep
,
false
)
;
91
doc
_
currentstep
=
0
;
92
}
93 94
function
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