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