34
|
1 // this global variable has to be initialised before the frist use of the functions below
|
|
2 // to fill in the attributes you can use the function init provided below
|
20
|
3 // - array with all attributes
|
|
4 var att = new Array();
|
|
5
|
34
|
6 // fill in the values of the "att"-array
|
|
7 function init(fn, pn, ws, mo, mk, wx, wy, ww, wh) {
|
|
8
|
|
9 // debug window to check the parameters passed
|
|
10 //alert ("DEBUG message (parameters in init):\n\npu = " + pu + "\npn = " + pn + "\nws = " + ws + "\nmo = " + mo + "\nmk = " + mk + "\nwx = " + wx + "\nwy = " + wy + "\nww = " + ww + "\nwh = " + wh);
|
|
11
|
|
12 // attaching the values to the att-array
|
|
13 att[0] = fn;
|
|
14 att[1] = parseInt(pn);
|
|
15 att[2] = parseFloat(ws);
|
|
16 att[3] = mo;
|
|
17 att[4] = mk;
|
|
18 att[5] = parseFloat(wx);
|
|
19 att[6] = parseFloat(wy);
|
|
20 att[7] = parseFloat(ww);
|
|
21 att[8] = parseFloat(wh);
|
|
22
|
|
23 // compatablility issue
|
|
24 if (att[3].indexOf("f") > -1) {
|
|
25 att[3] = "fit";
|
|
26 }
|
20
|
27
|
34
|
28 // converts the old mark format (0-1000) to new format(0.0 - 1.0)
|
|
29 // could even be useless now
|
|
30 if (att[4] != "0/0") {
|
|
31 var tmp = att[4].split(";");
|
|
32
|
|
33 att[4] = "";
|
|
34
|
|
35 for (i = 0; i < tmp.length; i++) {
|
|
36 tmp[i] = tmp[i].split("/");
|
|
37
|
|
38 if (tmp[i][0] > 1 && tmp[i][1] > 1) {
|
|
39 tmp[i][0] /= 1000;
|
|
40 tmp[i][1] /= 1000;
|
|
41 }
|
|
42
|
|
43 att[4] += tmp[i][0] + "/" + tmp[i][1] + ";";
|
|
44 }
|
|
45 att[4] = att[4].slice(0, -1);
|
|
46 }
|
|
47
|
|
48 // initialisation stuff
|
|
49 // ====================
|
|
50
|
|
51 setMarks();
|
|
52
|
|
53 this.document.addEventListener('keypress', parseKeypress, true);
|
|
54 focus();
|
|
55
|
|
56 // give a name to the window containing digilib - this way one can test if there is already a
|
|
57 // digilib-window open and replace the contents of it (ex. digicat)
|
|
58 top.window.name = "digilib";
|
|
59 }
|
|
60
|
20
|
61
|
|
62 // function that launches the ScaleServlet
|
|
63 // the different detailGrades:
|
|
64 // 0 -> back, next, page
|
|
65 // 1 -> zoomout
|
|
66 // 2 -> zoomarea, zoompoint, moveto, scaledef
|
|
67
|
|
68 function loadPicture(detailGrade, keepArea) {
|
|
69
|
41
|
70 var newQuery = "fn=" + att[0] + "&pn=" + att[1] + "&ws=" + att[2] + "&mo=" + att[3];
|
20
|
71
|
|
72 if (detailGrade == 0) {
|
|
73 att[4] = "0/0";
|
|
74 }
|
|
75
|
|
76 if ((detailGrade == 1) || (detailGrade == 0 && !keepArea)) {
|
|
77 att[5] = 0;
|
|
78 att[6] = 0;
|
|
79 att[7] = 1;
|
|
80 att[8] = 1;
|
|
81 }
|
34
|
82
|
41
|
83 newQuery += "&mk=" + att[4] + "&wx=" + att[5] + "&wy=" + att[6] + "&ww=" + att[7] + "&wh=" + att[8];
|
|
84 newQuery += "&dw=" + (innerWidth-30) + "&dh=" + (innerHeight-30);
|
20
|
85
|
34
|
86 // debug window - checking the parameters passed to the next image
|
41
|
87 //alert ("DEBUG MESSAGE (query-string in loadPicture):\n\n" + newQuery);
|
20
|
88
|
41
|
89 location.href = location.pathname + "?" + newQuery;
|
20
|
90 }
|
|
91
|
|
92
|
38
|
93 // constructor holding different values of a point
|
|
94 function Point(event) {
|
|
95
|
|
96 this.pageX = parseInt(event.pageX);
|
|
97 this.pageY = parseInt(event.pageY);
|
|
98
|
|
99 this.x = this.pageX-parseInt(document.getElementById("lay1").style.left);
|
|
100 this.y = this.pageY-parseInt(document.getElementById("lay1").style.top);
|
|
101
|
|
102 this.relX = cropFloat(att[5]+(att[7]*this.x/document.pic.offsetWidth));
|
|
103 this.relY = cropFloat(att[6]+(att[8]*this.y/document.pic.offsetHeight));
|
|
104
|
|
105 return this;
|
|
106 }
|
|
107
|
|
108
|
34
|
109 function backPage(keepArea) {
|
20
|
110
|
|
111 att[1] = parseInt(att[1]) - 1;
|
|
112
|
|
113 if (att[1] > 0) {
|
|
114 loadPicture(0, keepArea);
|
|
115 } else {
|
|
116 att[1] = parseInt(att[1]) + 1;
|
|
117 alert("You are already on the first page!");
|
|
118 }
|
|
119 }
|
|
120
|
|
121
|
34
|
122 function nextPage(keepArea) {
|
20
|
123
|
|
124 att[1] = parseInt(att[1]) + 1;
|
|
125
|
34
|
126 loadPicture(0, keepArea);
|
20
|
127 }
|
|
128
|
|
129
|
34
|
130 function page(keepArea) {
|
20
|
131
|
|
132 do {
|
34
|
133 page = prompt("Goto Page:", 1);
|
|
134 } while ((page != null) && (page < 1));
|
20
|
135
|
|
136 if (page != null && page != att[1]) {
|
|
137 att[1] = page;
|
|
138 loadPicture(0, keepArea);
|
|
139 }
|
|
140 }
|
|
141
|
|
142
|
34
|
143 function digicat() {
|
50
|
144 var url = "digicat.html?" + att[0] + "+" + att[1];
|
20
|
145 win = window.open(url, "digicat");
|
|
146 win.focus();
|
|
147 }
|
|
148
|
|
149
|
34
|
150 function ref(refselect) {
|
20
|
151
|
50
|
152 var hyperlinkRef = baseUrl + "/digilib.jsp?";
|
20
|
153 hyperlinkRef += att[0] + "+" + att[1] + "+" + att[2] + "+" + att[3] + "+" + att[4];
|
|
154
|
|
155 if ((att[5] != 0) || (att[6] != 0) || (att[7] != 1) || (att[8] != 1)) {
|
|
156 hyperlinkRef += "+" + att[5] + "+" + att[6] + "+" + att[7] + "+" + att[8];
|
|
157 }
|
|
158
|
|
159 if (refselect == 1) {
|
|
160 prompt("Link for HTML--documents", hyperlinkRef);
|
|
161 } else {
|
|
162 prompt("Link for LaTeX--documents", "\\href{" + hyperlinkRef + "}{TEXT}");
|
|
163 }
|
|
164 }
|
|
165
|
|
166
|
34
|
167 function mark() {
|
20
|
168
|
|
169 if (att[4].split(";").length > 7) {
|
|
170 alert("Only 8 marks are possible at the moment!");
|
|
171 return;
|
|
172 }
|
|
173
|
34
|
174 function markEvent(event) {
|
38
|
175 var point = new Point(event);
|
20
|
176
|
|
177 if ((att[4] != "") && (att[4] != "0/0")) {
|
|
178 att[4] += ";";
|
|
179 } else {
|
|
180 att[4] = "";
|
|
181 }
|
38
|
182 att[4] += point.relX + "/" + point.relY;
|
20
|
183
|
34
|
184 document.getElementById("lay1").removeEventListener("mousedown", markEvent, true);
|
|
185 setMarks();
|
20
|
186 }
|
|
187
|
34
|
188 document.getElementById("lay1").addEventListener("mousedown", markEvent, true);
|
20
|
189 }
|
|
190
|
|
191
|
34
|
192 function zoomArea() {
|
20
|
193 var state = 0;
|
38
|
194 var pt1, pt2;
|
20
|
195
|
34
|
196 function click(event) {
|
20
|
197
|
|
198 if (state == 0) {
|
|
199 state = 1;
|
|
200
|
38
|
201 pt1 = new Point(event);
|
|
202 pt2 = pt1;
|
20
|
203
|
38
|
204 document.getElementById("eck1").style.left = pt1.pageX;
|
|
205 document.getElementById("eck1").style.top = pt1.pageY;
|
|
206 document.getElementById("eck2").style.left = pt2.pageX-12;
|
|
207 document.getElementById("eck2").style.top = pt1.pageY;
|
|
208 document.getElementById("eck3").style.left = pt1.pageX;
|
|
209 document.getElementById("eck3").style.top = pt2.pageY-12;
|
|
210 document.getElementById("eck4").style.left = pt2.pageX-12;
|
|
211 document.getElementById("eck4").style.top = pt2.pageY-12;
|
20
|
212
|
34
|
213 document.getElementById("eck1").style.visibility="visible";
|
|
214 document.getElementById("eck2").style.visibility="visible";
|
|
215 document.getElementById("eck3").style.visibility="visible";
|
|
216 document.getElementById("eck4").style.visibility="visible";
|
20
|
217
|
34
|
218 document.getElementById("lay1").addEventListener("mousemove", move, true);
|
|
219 document.getElementById("eck4").addEventListener("mousemove", move, true);
|
20
|
220
|
|
221 } else {
|
|
222
|
38
|
223 pt2 = new Point(event);
|
|
224
|
34
|
225 document.getElementById("lay1").removeEventListener("mousedown", click, true);
|
|
226 document.getElementById("eck4").removeEventListener("mousedown", click, true);
|
20
|
227
|
34
|
228 document.getElementById("lay1").removeEventListener("mousemove", move, true);
|
|
229 document.getElementById("eck4").removeEventListener("mousemove", move, true);
|
20
|
230
|
34
|
231 document.getElementById("eck1").style.visibility="hidden";
|
|
232 document.getElementById("eck2").style.visibility="hidden";
|
|
233 document.getElementById("eck3").style.visibility="hidden";
|
|
234 document.getElementById("eck4").style.visibility="hidden";
|
20
|
235
|
38
|
236 att[5] = Math.min(pt1.relX, pt2.relX);
|
|
237 att[6] = Math.min(pt1.relY, pt2.relY);
|
20
|
238
|
38
|
239 att[7] = Math.abs(pt1.relX-pt2.relX);
|
|
240 att[8] = Math.abs(pt1.relY-pt2.relY);
|
20
|
241
|
|
242 if (att[7] != 0 && att[8] != 0) {
|
|
243 loadPicture(2);
|
|
244 }
|
|
245 }
|
|
246 }
|
|
247
|
34
|
248 function move(event) {
|
20
|
249
|
38
|
250 pt2 = new Point(event);
|
20
|
251
|
38
|
252 document.getElementById("eck1").style.left = ((pt1.pageX < pt2.pageX) ? pt1.pageX : pt2.pageX);
|
|
253 document.getElementById("eck1").style.top = ((pt1.pageY < pt2.pageY) ? pt1.pageY : pt2.pageY);
|
|
254 document.getElementById("eck2").style.left = ((pt1.pageX < pt2.pageX) ? pt2.pageX : pt1.pageX)-12;
|
|
255 document.getElementById("eck2").style.top = ((pt1.pageY < pt2.pageY) ? pt1.pageY : pt2.pageY);
|
|
256 document.getElementById("eck3").style.left = ((pt1.pageX < pt2.pageX) ? pt1.pageX : pt2.pageX);
|
|
257 document.getElementById("eck3").style.top = ((pt1.pageY < pt2.pageY) ? pt2.pageY : pt1.pageY)-12;
|
|
258 document.getElementById("eck4").style.left = ((pt1.pageX < pt2.pageX) ? pt2.pageX : pt1.pageX)-12;
|
|
259 document.getElementById("eck4").style.top = ((pt1.pageY < pt2.pageY) ? pt2.pageY : pt1.pageY)-12;
|
20
|
260 }
|
|
261
|
34
|
262 document.getElementById("lay1").addEventListener("mousedown", click, true);
|
|
263 document.getElementById("eck4").addEventListener("mousedown", click, true);
|
20
|
264 }
|
|
265
|
|
266
|
34
|
267 function zoomPoint() {
|
20
|
268
|
34
|
269 function zoomPointEvent(event) {
|
38
|
270 var point = new Point(event);
|
20
|
271
|
38
|
272 att[5] = cropFloat(point.relX-0.5*att[7]*0.7);
|
|
273 att[6] = cropFloat(point.relY-0.5*att[8]*0.7);
|
20
|
274
|
|
275 att[7] = cropFloat(att[7]*0.7);
|
|
276 att[8] = cropFloat(att[8]*0.7);
|
|
277
|
|
278 if (att[5] < 0) {
|
|
279 att[5] = 0;
|
|
280 }
|
|
281 if (att[6] < 0) {
|
|
282 att[6] = 0;
|
|
283 }
|
|
284 if (att[5]+att[7] > 1) {
|
|
285 att[5] = 1-att[7];
|
|
286 }
|
|
287 if (att[6]+att[8] > 1) {
|
|
288 att[6] = 1-att[8];
|
|
289 }
|
|
290
|
34
|
291 document.getElementById("lay1").removeEventListener("mousedown", zoomPointEvent, true);
|
20
|
292
|
|
293 loadPicture(2);
|
|
294 }
|
|
295
|
34
|
296 document.getElementById("lay1").addEventListener("mousedown", zoomPointEvent, true);
|
20
|
297 }
|
|
298
|
|
299
|
34
|
300 function zoomOut() {
|
20
|
301
|
|
302 loadPicture(1);
|
|
303 }
|
|
304
|
|
305
|
34
|
306 function moveTo() {
|
20
|
307
|
34
|
308 function moveToEvent(event) {
|
20
|
309
|
38
|
310 var point = new Point(event);
|
|
311
|
|
312 att[5] = cropFloat(point.relX-0.5*att[7]);
|
|
313 att[6] = cropFloat(point.relY-0.5*att[8]);
|
20
|
314
|
|
315 if (att[5] < 0) {
|
|
316 att[5] = 0;
|
|
317 }
|
|
318 if (att[6] < 0) {
|
|
319 att[6] = 0;
|
|
320 }
|
|
321 if (att[5]+att[7] > 1) {
|
|
322 att[5] = 1-att[7];
|
|
323 }
|
|
324 if (att[6]+att[8] > 1) {
|
|
325 att[6] = 1-att[8];
|
|
326 }
|
|
327
|
34
|
328 document.getElementById("lay1").removeEventListener("mousedown", moveToEvent, true);
|
20
|
329
|
|
330 loadPicture(2);
|
|
331 }
|
|
332
|
34
|
333 document.getElementById("lay1").addEventListener("mousedown", moveToEvent, true);
|
20
|
334 }
|
|
335
|
|
336
|
34
|
337 function scale(scaledef) {
|
20
|
338
|
|
339 att[2] = scaledef;
|
|
340 loadPicture(2);
|
|
341 }
|
|
342
|
|
343
|
34
|
344 function setMarks() {
|
20
|
345
|
|
346 if (att[4] != "" && att[4] != "0/0") {
|
|
347 var mark = att[4].split(";");
|
|
348
|
|
349 var countMarks = mark.length;
|
|
350
|
|
351 // maximum of marks is 8
|
|
352 // we do not report this error because this is already done in func. "Mark"
|
|
353 if (countMarks > 8) countMarks = 8;
|
|
354
|
34
|
355 var picWidth = document.pic.offsetWidth;
|
|
356 var picHeight = document.pic.offsetHeight;
|
20
|
357
|
|
358 // catch the cases where the picture had not been loaded already and
|
|
359 // make a timeout so that the coordinates are calculated with the real dimensions
|
34
|
360 if (document.pic.complete) {
|
|
361 var xoffset = parseInt(document.getElementById("lay1").style.left);
|
|
362 var yoffset = parseInt(document.getElementById("lay1").style.top);
|
20
|
363
|
|
364 for (var i = 0; i < countMarks; i++) {
|
|
365 mark[i] = mark[i].split("/");
|
|
366
|
|
367 if ((mark[i][0] > att[5]) && (mark[i][1] > att[6]) && (mark[i][0] < (att[5]+att[7])) && (mark[i][1] < (att[6]+att[8]))) {
|
|
368
|
|
369 mark[i][0] = parseInt(xoffset+picWidth*(mark[i][0]-att[5])/att[7]);
|
|
370 mark[i][1] = parseInt(yoffset+picHeight*(mark[i][1]-att[6])/att[8]);
|
|
371
|
|
372
|
34
|
373 document.getElementById("dot" + i).style.left = mark[i][0]-5;
|
|
374 document.getElementById("dot" + i).style.top = mark[i][1]-5;
|
|
375 document.getElementById("dot" + i).style.visibility = "visible";
|
20
|
376 }
|
|
377 }
|
|
378 } else {
|
34
|
379 setTimeout("setMarks()", 100);
|
20
|
380 }
|
|
381 }
|
|
382 }
|
|
383
|
|
384 // capturing keypresses for next and previous page
|
|
385 // ascii-values of n = 110, b = 98
|
|
386 function parseKeypress (event) {
|
|
387 if (event.charCode == 110) {
|
|
388 Nextpage();
|
|
389 }
|
|
390 if (event.charCode == 98) {
|
|
391 Backpage();
|
|
392 }
|
|
393 }
|
|
394
|
|
395
|
|
396 // auxiliary function to crop senseless precicsion
|
|
397 function cropFloat(tmp) {
|
|
398 return parseInt(10000*tmp)/10000;
|
|
399 }
|