comparison client/digitallibrary/jskin/dllib.js @ 519:b21acdd1fa9d jquery

zeroth version of new js skin
author robcast
date Mon, 07 Sep 2009 18:22:54 +0200
parents
children
comparison
equal deleted inserted replaced
17:a256239970f8 519:b21acdd1fa9d
1 /* Copyright (C) 2003,2004 IT-Group MPIWG, WTWG Uni Bern and others
2
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License
5 as published by the Free Software Foundation; either version 2
6 of the License, or (at your option) any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
16
17 Authors:
18 Christian Luginbuehl, 01.05.2003 (first version)
19 DW 24.03.2004 (Changed for digiLib in Zope)
20 Robert Casties, 8.11.2005
21 Martin Raspe <hertzhaft@biblhertz.it>, 12.12.2005
22 Robert Casties, 4.9.2009
23
24 ! Requires baselib.js !
25 */
26 digilibVersion = "Digilib JQ";
27 dllibVersion = "3.001";
28
29 function identify() {
30 // used for identifying a digilib instance
31 // Relato uses that function - lugi
32 return digilibVersion;
33 }
34
35 function createMarkDiv(index) {
36 var div = document.createElement("div");
37 div.className = "mark";
38 div.id = "mark" + index;
39 div.innerHTML = index + 1;
40 document.body.appendChild(div);
41 return div;
42 }
43
44 function bestPicSize(elem, inset) {
45 // returns a Size with the best image size for the given element
46 if (! defined(inset)) {
47 inset = 25;
48 }
49 var ws = getWinSize();
50 var es = getElementPosition(elem);
51 if (es) {
52 ws.width = ws.width - es.x - inset;
53 ws.height = ws.height - es.y - inset;
54 }
55 return ws;
56 }
57
58
59 /****************************************************
60 * digilib specific classes (must be defined first)
61 ****************************************************/
62
63 /*
64 * Marks class
65 */
66 function DLMarks() {
67 return this;
68 }
69 // Marks inherits from Array
70 DLMarks.prototype = new Array();
71 DLMarks.prototype.parse = function(query) {
72 this.length = 0;
73 if (query.indexOf(";") >= 0) {
74 var pa = query.split(";"); // old format with ";"
75 } else {
76 var pa = query.split(","); // new format
77 }
78 for (var i = 0; i < pa.length ; i++) {
79 var pos = pa[i].split("/");
80 if (pos.length > 1) this.push(new Position(pos[0], pos[1]));
81 }
82 }
83 DLMarks.prototype.getAll = function() {
84 var ma = new Array();
85 for (var i = 0; i < this.length; i++) {
86 ma.push(cropFloat(this[i].x) + "/" + cropFloat(this[i].y));
87 }
88 return ma.join(",");
89 }
90 DLMarks.prototype.addEvent = function(evt, digilib) {
91 // add a mark from a screen event
92 if (!digilib) digilib = dl;
93 var pos = digilib.trafo.invtransform(evtPosition(evt));
94 this.push(pos);
95 }
96
97 /*
98 * DLParameters -- digilib parameter class
99 */
100 function DLParameters() {
101 // flags for parameter sets
102 this.PARAM_FILE = 1;
103 this.PARAM_MODE = 2;
104 this.PARAM_DIM = 4;
105 this.PARAM_IMAGE = 8;
106 this.PARAM_DPI = 16;
107 this.PARAM_SIZE = 32;
108 this.PARAM_MARK = 64;
109 this.PARAM_PAGES = 128;
110 this.PARAM_CLIENT = 256;
111 /* request parameters */
112 with (this) {
113 // file
114 define('fn', '', PARAM_FILE);
115 define('pn', '1', PARAM_FILE);
116 // mode
117 define('mo', '', PARAM_MODE);
118 // relative dimensions of zoomed image
119 define('wx', '0.0', PARAM_DIM);
120 define('wy', '0.0', PARAM_DIM);
121 define('ww', '1.0', PARAM_DIM);
122 define('wh', '1.0', PARAM_DIM);
123 // image manipulation
124 define('brgt', '0.0', PARAM_IMAGE);
125 define('cont', '0.0', PARAM_IMAGE);
126 define('rot', '0.0', PARAM_IMAGE);
127 define('rgba', '', PARAM_IMAGE);
128 define('rgbm', '', PARAM_IMAGE);
129 // resolution
130 define('ddpi', '', PARAM_DPI);
131 define('ddpix', '', PARAM_DPI);
132 define('ddpiy', '', PARAM_DPI);
133 // marks
134 define('mk', '', PARAM_MARK);
135 // pages total
136 define('pt', '0', PARAM_PAGES);
137 // size
138 define('ws', '1.0', PARAM_SIZE);
139 // client side options
140 define('clop', '', PARAM_CLIENT);
141 }
142 return this;
143 }
144 DLParameters.prototype = new Parameters();
145 // move the inherited getAll because we need it later
146 DLParameters.prototype._getAll = Parameters.prototype.getAll;
147 DLParameters.prototype.getAll = function(paDetail, moDetail, digilib) {
148 if (!digilib) digilib = dl;
149 // get Flags and Marks first
150 var mo = digilib.flags.getAll(moDetail);
151 this.set("mo", mo);
152 var clop = digilib.opts.getAll();
153 this.set("clop", clop);
154 var mk = digilib.marks.getAll();
155 this.set("mk", mk);
156 var ret = this._getAll(paDetail);
157 return ret;
158 }
159
160 /*
161 * DLModes -- digilib flags class
162 */
163 function DLFlags() {
164 // flags for mode sets
165 this.MODE_QUAL = 1;
166 this.MODE_SIZE = 2;
167 this.MODE_MIR = 4;
168 this.MODE_OTHER = 128;
169 this.MODE_ALL = 255;
170 /* mode flags */
171 with (this) {
172 define('q0', MODE_QUAL);
173 define('q1', MODE_QUAL);
174 define('q2', MODE_QUAL);
175 define('fit', MODE_SIZE);
176 define('clip', MODE_SIZE);
177 define('osize', MODE_SIZE);
178 define('vmir', MODE_MIR);
179 define('hmir', MODE_MIR);
180 }
181 return this;
182 }
183 // inherits from Flags
184 DLFlags.prototype = new Flags();
185
186
187 /*
188 * Digilib -- digilib base class
189 */
190 function Digilib() {
191 if (!baseLibVersion) alert("ERROR: baselib.js not loaded!");
192 /* constants */
193 this.MAX_AREA = new Rectangle(0.0, 0.0, 1.0, 1.0);
194 // default inset (for scalerImg relativ to scalerDiv
195 this.INSET = 40; // because of scrollbars of main window and scaler [Firefox bug?]
196 // mouse drag area that counts as one click
197 this.MIN_AREA_SIZE = 3 * 3 + 1;
198 // standard zoom factor
199 this.ZOOMFACTOR = Math.sqrt(2);
200 // bird's eye view dimensions
201 this.BIRD_MAXX = 100;
202 this.BIRD_MAXY = 100;
203 // witdh of arrow bars
204 this.ARROW_WIDTH = 32;
205 // width of calibration bar
206 this.CALIBRATION_WIDTH = 64;
207 /* variables */
208 this.fitOnlyWidth = false;
209 this.fitOnlyHeight = false;
210 this.trafo = null;
211 // page elements
212 this.scalerDiv = null;
213 this.scalerImg = null;
214 this.buttons1Div = null;
215 this.buttons2Div = null;
216 /* parse parameters */
217 this.params = new DLParameters();
218 // put the query parameters (sans "?") in the parameters array
219 this.params.parse(location.search.slice(1));
220 // treat special parameters
221 this.area = this.parseArea();
222 this.marks = new Marks();
223 this.marks.parse(this.params.get("mk"));
224 this.flags = new DLFlags();
225 this.flags.parse(this.params.get("mo"));
226 this.opts = new Flags();
227 this.opts.parse(this.params.get("clop"));
228 return this;
229 }
230 Digilib.prototype.setDLParam = function(e, s, relative) {
231 // sets parameter based on HTML event
232 var nam;
233 var val;
234 if (s.type && (s.type == "select-one")) {
235 nam = s.name;
236 val = s.options[s.selectedIndex].value;
237 } else if (s.name && s.value) {
238 nam = s.name;
239 val = s.value;
240 }
241 if (nam && val) {
242 dl.params.set(nam, val, relative);
243 display();
244 } else {
245 alert("ERROR: unable to process event!");
246 }
247 return true;
248 }
249 Digilib.prototype.parseArea = function() {
250 // returns area Rectangle from current parameters
251 return new Rectangle(
252 this.params.get("wx"),
253 this.params.get("wy"),
254 this.params.get("ww"),
255 this.params.get("wh"));
256 }
257 Digilib.prototype.setParamFromArea = function(rect) {
258 // sets digilib wx etc. from rect
259 this.params.set("wx", cropFloat(rect.x));
260 this.params.set("wy", cropFloat(rect.y));
261 this.params.set("ww", cropFloat(rect.width));
262 this.params.set("wh", cropFloat(rect.height));
263 return true;
264 }
265
266 Digilib.prototype.parseTrafo = function(elem) {
267 // returns Transform from current dlArea and picsize
268 var picsize = getElementRect(elem);
269 var trafo = new Transform();
270 // subtract area offset and size
271 trafo.concat(trafo.getTranslation(new Position(-this.area.x, -this.area.y)));
272 trafo.concat(trafo.getScale(new Size(1/this.area.width, 1/this.area.height)));
273 // scale to screen size
274 trafo.concat(trafo.getScale(picsize));
275 trafo.concat(trafo.getTranslation(picsize));
276 // FIX ME: Robert, kannst Du mal nachsehen, ob das folgende tut, was es soll?
277 // oder gibt es dafuer neuen Code? -- ROC: Bisher funktioniert es nicht!
278 // rotate
279 //var rot = getRotation(- dl.params.get("rot"), new Position(0.5*picsize.width, 0.5*picsize.height));
280 //trafo.concat(rot);
281 // mirror
282 //if (hasFlag("hmir")) trafo.m00 = - trafo.m00; // ??
283 //if (hasFlag("vmir")) trafo.m11 = - trafo.m11; // ??
284 return trafo;
285 }
286
287 Digilib.prototype.onLoad = function() {
288 // initialize digilib; called by body.onload
289 this.scalerDiv = getElement("scaler", true);
290 this.scalerImg = getElement("pic", true);
291 this.buttons1Div = getElement("buttons", true);
292 this.buttons2Div = getElement("options", true);
293 /*
294 * if (this.scalerImg == null && this.scalerDiv) { // in N4 pic is in the
295 * scaler layer this.scalerImg = this.scalerDiv.document.images[0]; }
296 */
297 if ((!this.scalerImg)||(!this.scalerDiv)) {
298 alert("Sorry, digilib doesn't work here!");
299 return false;
300 }
301 // fix fixed menus
302 var ms1 = getElementSize(this.buttons1Div);
303 var ms2 = getElementSize(this.buttons2Div);
304 var maxh = (ms1.height > ms2.height) ? ms1.height : ms2.height;
305 var wins = getWinSize();
306 if ((wins.height <= maxh) || (browserType.isIE && (browserType.versIE < 7))) {
307 // unlock fixed menus to absolute if window is too small or IE
308 this.buttons1Div.style.position = "absolute";
309 this.buttons2Div.style.position = "absolute";
310 }
311 this.setScalerImage(); // setzt auch onImgLoad
312 this.setBirdImage(); // laedt das Bird's Eye Bild
313 }
314
315 Digilib.prototype.setScalerImage = function() {
316 // set the scaler image source (needs the browser size)
317 var picsize = bestPicSize(this.scalerDiv);
318 var menusize = getElementSize(this.buttons1Div);
319 // subtract menu width
320 picsize.width -= menusize.width;
321 picsize.height -= this.INSET;
322 // compose Scaler URL
323 var src = "../servlet/Scaler?"
324 + this.params.getAll(this.params.PARAM_ALL & ~(this.params.PARAM_MARK | this.params.PARAM_PAGES));
325 if (this.opts.get('fitwidth')) {
326 src += "&dw=" + picsize.width;
327 } else if (this.opts.get('fitheight')) {
328 src += "&dh=" + picsize.height;
329 } else {
330 src += "&dw=" + picsize.width + "&dh=" + picsize.height;
331 }
332 // debug(src);
333 this.scalerImg.onload = onImgLoad;
334 this.scalerImg.src = src;
335
336 var digilib = this;
337 // this is a local callback function that can use the current scope
338
339 function onImgLoad() {
340 if (! digilib)
341 return;
342 // make sure the image is loaded so we know its size
343 /* this test seems to have problems sometimes :-(
344 if (defined(digilib.scalerImg.complete) && !digilib.scalerImg.complete) {
345 alert("ERROR: the image seems not to be complete in onImgLoad!?");
346 } */
347 digilib.trafo = digilib.parseTrafo(digilib.scalerImg);
348 // display marks
349 digilib.renderMarks();
350 digilib.showBirdDiv(isBirdDivVisible);
351 digilib.showArrows(); // show arrow overlays for zoom navigation
352 //digilib.moveCenter(true); // click to move point to center
353 // new Slider("sizes", 1, 5, 2);
354 focus();
355 }
356 }
357
358 Digilib.prototype.renderMarks = function() {
359 // make sure the image is loaded so we know its size
360 if (!this.trafo) {
361 alert("ERROR: trafo missing, cannot render marks!");
362 return;
363 }
364 // debugProps(dlArea, "dlArea");
365 for (var i = 0; i < this.marks.length; i++) {
366 var div = getElement("mark" + i, true) || createMarkDiv(i);
367 var mark = this.marks[i];
368 // debugProps(mark, "mark");
369 if (this.area.containsPosition(mark)) {
370 var mpos = this.trafo.transform(mark);
371 // debugProps(mark, "mpos");
372 // better not hide the marked spot (MR)
373 // suboptimal to place -5 pixels and not half size of mark-image
374 // mpos.x = mpos.x -5;
375 // mpos.y = mpos.y -5;
376 moveElement(div, mpos);
377 showElement(div, true);
378 } else {
379 // hide the other marks
380 showElement(div, false);
381 }
382 }
383 }
384
385 Digilib.prototype.display = function(detail, moDetail) {
386 // redisplay the page
387 var queryString = this.params.getAll(detail, moDetail);
388 location.href
389 = location.protocol + "//"
390 + location.host
391 + location.pathname
392 + "?" + queryString;
393 }
394
395 /* **********************************************
396 * interactive digilib functions
397 * ******************************************** */
398
399 Digilib.prototype.setMark = function() {
400 // add a mark where clicked
401 window.focus();
402 this.moveCenter(false);
403
404 // start event capturing
405 registerEvent("mousedown", this.scalerDiv, markEvent);
406
407 // our own reference to this for the local function
408 var digilib = this;
409
410 function markEvent(evt) {
411 // event handler adding a new mark
412 unregisterEvent("mousedown", digilib.scalerDiv, markEvent);
413 digilib.marks.addEvent(evt);
414 digilib.display();
415 return stopEvent(evt);
416 }
417
418 }
419
420 Digilib.prototype.removeMark = function() {
421 // remove the last mark
422 this.marks.pop();
423 this.display();
424 }
425
426 Digilib.prototype.zoomArea = function() {
427 var pt1, pt2;
428 var zoomdiv = getElement("zoom");
429 var overlay = getElement("overlay");
430 // use overlay div to avoid <img> mousemove problems
431 var picRect = getElementRect(this.scalerImg);
432 // FIX ME: is there a way to query the border width from CSS info?
433 // rect.x -= 2; // account for overlay borders
434 // rect.y -= 2;
435 moveElement(overlay, picRect);
436 showElement(overlay, true);
437 // start event capturing
438 registerEvent("mousedown", overlay, zoomStart);
439 registerEvent("mousedown", this.scalerImg, zoomStart);
440 window.focus();
441
442 // our own reference to "this" for the local functions
443 var digilib = this;
444
445 // mousedown handler: start moving
446 function zoomStart(evt) {
447 pt1 = evtPosition(evt);
448 unregisterEvent("mousedown", overlay, zoomStart);
449 unregisterEvent("mousedown", digilib.scalerImg, zoomStart);
450 // setup and show zoom div
451 moveElement(zoomdiv, Rectangle(pt1.x, pt1.y, 0, 0));
452 showElement(zoomdiv, true);
453 // register events
454 registerEvent("mousemove", document, zoomMove);
455 registerEvent("mouseup", document, zoomEnd);
456 return stopEvent(evt);
457 }
458
459 // mouseup handler: end moving
460 function zoomEnd(evt) {
461 pt2 = evtPosition(evt);
462 // assume a click if the area is too small (up to 3 x 3 pixel)
463 var clickRect = new Rectangle(pt1, pt2);
464 clickRect.normalize();
465 if (clickRect.getArea() <= digilib.MIN_AREA_SIZE) {
466 return stopEvent(evt);
467 }
468 // hide zoom div
469 showElement(zoomdiv, false);
470 showElement(overlay, false);
471 // unregister events
472 unregisterEvent("mousemove", document, zoomMove);
473 unregisterEvent("mouseup", document, zoomEnd);
474 // clip and transform
475 clickRect.clipTo(picRect);
476 var area = digilib.trafo.invtransform(clickRect);
477 digilib.setParamFromArea(area);
478 // zoomed is always fit
479 digilib.params.set("ws", 1);
480 digilib.display();
481 return stopEvent(evt);
482 }
483
484 // mouse move handler
485 function zoomMove(evt) {
486 pt2 = evtPosition(evt);
487 var rect = new Rectangle(pt1, pt2);
488 rect.normalize();
489 rect.clipTo(picRect);
490 // update zoom div
491 moveElement(zoomdiv, rect);
492 return stopEvent(evt);
493 }
494 }
495
496 Digilib.prototype.zoomBy = function(factor) {
497 // zooms by the given factor
498 var newarea = this.area.copy();
499 newarea.width /= factor;
500 newarea.height /= factor;
501 newarea.x -= 0.5 * (newarea.width - this.area.width);
502 newarea.y -= 0.5 * (newarea.height - this.area.height);
503 newarea = this.MAX_AREA.fit(newarea);
504 this.setParamFromArea(newarea);
505 this.display();
506 }
507
508
509 Digilib.prototype.zoomFullpage = function(fit) {
510 // zooms out to show the whole image
511 this.params.set("wx", 0.0);
512 this.params.set("wy", 0.0);
513 this.params.set("ww", 1.0);
514 this.params.set("wh", 1.0);
515 if (fit == "width") {
516 this.opts.set('fitwidth');
517 } else if (fit == "height") {
518 this.opts.set('fitheight');
519 } else {
520 this.opts.reset('fitwidth');
521 this.opts.reset('fitheight');
522 }
523 this.display();
524 }
525
526
527 Digilib.prototype.moveCenter = function(on) {
528 // move visible area so that it's centered around the clicked point
529 if (this.isFullArea()) return; // nothing to do
530 // starting event capture
531 if (on) registerEvent("mousedown", this.scalerImg, moveCenterEvent);
532 else unregisterEvent("mousedown", this.scalerImg, moveCenterEvent);
533 window.focus();
534
535 // our own reference to this for the local function
536 var digilib = this;
537
538 function moveCenterEvent(evt) {
539 // move to handler
540 var pt = digilib.trafo.invtransform(evtPosition(evt));
541 var newarea = digilib.area.copy();
542 newarea.setCenter(pt);
543 newarea.stayInside(this.MAX_AREA);
544 // newarea = dlMaxArea.fit(newarea);
545 // debugProps(newarea, "newarea");
546 // debugProps(dlArea, "dlArea");
547 if (newarea.equals(digilib.area)) return; // keep event handler
548 unregisterEvent("mousedown", digilib.scalerImg, moveCenterEvent);
549 // set parameters
550 digilib.setParamFromArea(newarea);
551 digilib.display();
552 }
553 }
554
555 Digilib.prototype.isFullArea = function(area) {
556 if (!area) area = this.area;
557 return (area.width == 1.0) && (area.height == 1.0);
558 }
559
560 Digilib.prototype.canMove = function(movx, movy) {
561 if (this.isFullArea()) return false;
562 var x2 = this.area.x + this.area.width;
563 var y2 = this.area.y + this.area.height;
564 // debugProps(dlArea);
565 return ((movx < 0) && (this.area.x > 0))
566 || ((movx > 0) && (x2 < 1.0))
567 || ((movy < 0) && (this.area.y > 0))
568 || ((movy > 0) && (y2 < 1.0))
569 }
570
571 Digilib.prototype.moveBy = function(movx, movy) {
572 // move visible area by movx and movy (in units of ww, wh)
573 if (!this.canMove(movx, movy)) return; // nothing to do
574 var newarea = this.area.copy();
575 newarea.x += parseFloat(movx)*this.area.width;
576 newarea.y += parseFloat(movy)*this.area.height;
577 newarea = this.MAX_AREA.fit(newarea);
578 // set parameters
579 this.setParamFromArea(newarea);
580 this.display();
581 }
582
583 Digilib.prototype.getRef = function(baseUrl) {
584 // returns a reference to the current digilib set
585 if (!baseUrl) baseUrl
586 = location.protocol
587 + "//"
588 + location.host
589 + location.pathname;
590 var hyperlinkRef = baseUrl;
591 with (this.params) {
592 // all without ddpi, pt
593 var ps = getAll(PARAM_ALL & ~(PARAM_DPI | PARAM_PAGES | PARAM_CLIENT));
594 }
595 if (ps.length > 0) hyperlinkRef += "?" + ps;
596 return hyperlinkRef;
597 }
598
599 Digilib.prototype.getRefWin = function(type, msg) {
600 // shows an alert with a reference to the current digilib set
601 if (! msg) msg = "URL reference to the current view";
602 prompt(msg, this.getRef());
603 }
604
605 Digilib.prototype.getQuality = function() {
606 // returns the current q setting
607 for (var i = 0; i < 3; i++) {
608 if (this.flags.get("q"+i)) return i;
609 }
610 return 1
611 }
612
613 Digilib.prototype.setQuality = function(qual) {
614 // set the image quality
615 if ((qual < 0)||(qual > 2)) return alert("Quality setting not supported");
616 for (var i = 0; i < 3; i++) this.flags.reset("q" + i);
617 this.flags.set("q" + qual);
618 this.display();
619 }
620
621 Digilib.prototype.setQualityWin = function(msg) {
622 // dialog for setting quality
623 if (! msg) msg = "Quality (0..2)";
624 var q = this.getQuality();
625 var newq = window.prompt(msg, q);
626 if (newq) this.setQuality(newq);
627 }
628
629 Digilib.prototype.mirror = function(dir) {
630 // mirror the image horizontally or vertically
631 if (dir == "h") {
632 this.flags.toggle("hmir");
633 } else {
634 this.flags.toggle("vmir");
635 }
636 this.display();
637 }
638
639 Digilib.prototype.gotoPage = function(gopage, keep) {
640 // goto given page nr (+/-: relative)
641 var oldpn = parseInt(this.params.get("pn"));
642 // set with relative=true uses the sign
643 this.params.set("pn", gopage, true);
644 // now check the outcome
645 var pn = parseInt(this.params.get("pn"));
646 if (pn < 1) {
647 alert("No such page! (Page number too low)");
648 this.params.set("pn", oldpn);
649 return;
650 }
651 if (this.params.isSet("pt")) {
652 pt = parseInt(this.params.get("pt"))
653 if (pn > pt) {
654 alert("No such page! (Page number too high)");
655 this.params.set("pn", oldpn);
656 return;
657 }
658 }
659 if (keep) {
660 this.display(this.params.PARAM_ALL & ~this.params.PARAM_MARK); // all, no mark
661 } else {
662 this.display(this.params.PARAM_FILE | this.params.PARAM_MODE | this.params.PARAM_PAGES, this.params.MODE_QUAL | this.params.MODE_OTHER); // fn, pn, ws, mo + pt
663 }
664 }
665
666 Digilib.prototype.gotoPageWin = function() {
667 // dialog to ask for new page nr
668 var pn = this.params.get("pn");
669 var gopage = window.prompt("Go to page", pn);
670 if (gopage) this.gotoPage(gopage);
671 }
672
673 Digilib.prototype.setParamWin = function(param, text, relative) {
674 // dialog to ask for new parameter value
675 var val = this.params.get(param);
676 var newval = window.prompt(text, val);
677 if (newval) {
678 this.params.set(param, newval, relative);
679 this.display();
680 }
681 }
682
683 Digilib.prototype.showOptions = function(show) {
684 // show or hide option div
685 var elem = getElement("dloptions");
686 showElement(elem, show);
687 // FIX ME: get rid of the dotted line around the buttons when focused
688 }
689
690 Digilib.prototype.showAboutDiv = function(show) {
691 // show or hide "about" div
692 var elem = getElement("about");
693 if (elem == null) {
694 if (show) alert("About Digilib - dialog missing in HTML code!"
695 + "\nDigilib Version: " + digilibVersion
696 + "\JSP Version: " + jspVersion
697 + "\ndlLib Version: " + dllibVersion
698 + "\nbaseLib Version: " + baseLibVersion);
699 return;
700 }
701 if (show) {
702 getElement("digilib-version").innerHTML = "Digilib Version: " + digilibVersion;
703 getElement("jsp-version").innerHTML = "JSP Version: " + jspVersion;
704 getElement("baselib-version").innerHTML = "baseLib Version: " + baseLibVersion;
705 getElement("dllib-version").innerHTML = "dlLib Version: " + dllibVersion;
706 var aboutRect = getElementRect(elem);
707 aboutRect.setCenter(getWinRect().getCenter());
708 moveElement(elem, aboutRect);
709 }
710 showElement(elem, show);
711 }
712
713 Digilib.prototype.setBirdImage = function() {
714 var img = getElement("bird-image");
715 var src = "../servlet/Scaler?"
716 + this.params.getAll(this.params.PARAM_FILE)
717 + "&dw=" + this.BIRD_MAXX
718 + "&dh=" + this.BIRD_MAXY;
719 img.src = src;
720 }
721
722 Digilib.prototype.showBirdDiv = function(show) {
723 // show or hide "bird's eye" div
724 var startPos; // anchor for dragging
725 var newRect; // position after drag
726 var birdImg = getElement("bird-image");
727 var birdArea = getElement("bird-area");
728 var overlay = getElement("bird-overlay");
729 showElement(birdImg, show);
730 // dont show selector if area has full size
731 if (!show || this.isFullArea()) {
732 // hide area
733 showElement(birdArea, false);
734 showElement(overlay, false);
735 return;
736 };
737 var birdImgRect = getElementRect(birdImg);
738 var area = this.area;
739 if (this.flags.get("osize") || this.flags.get("clip")) {
740 // in original-size and pixel-by-pixel mode the area size is not valid
741 var birdAreaRect = new Rectangle(
742 birdImgRect.x + birdImgRect.width * area.x,
743 birdImgRect.y + birdImgRect.height * area.y,
744 5,
745 5);
746 } else {
747 // scale area down to img size
748 var birdAreaRect = new Rectangle(
749 // what about borders ??
750 birdImgRect.x + birdImgRect.width * area.x,
751 birdImgRect.y + birdImgRect.height * area.y,
752 birdImgRect.width * area.width,
753 birdImgRect.height * area.height);
754 }
755 moveElement(birdArea, birdAreaRect);
756 showElement(birdArea, true);
757 moveElement(overlay, birdImgRect);
758 showElement(overlay, true);
759 registerEvent("mousedown", overlay, birdAreaStartDrag);
760 registerEvent("mousedown", birdImg, birdAreaStartDrag);
761
762 // our own reference to this for local functions
763 var digilib = this;
764
765 function birdAreaStartDrag(evt) {
766 // mousedown handler: start drag
767 startPos = evtPosition(evt);
768 unregisterEvent("mousedown", overlay, birdAreaStartDrag);
769 unregisterEvent("mousedown", birdImg, birdAreaStartDrag);
770 registerEvent("mousemove", document, birdAreaMove);
771 registerEvent("mouseup", document, birdAreaEndDrag);
772 // debugProps(getElementRect(bird))
773 return stopEvent(evt);
774 }
775
776 function birdAreaMove(evt) {
777 // mousemove handler: drag
778 var pos = evtPosition(evt);
779 var dx = pos.x - startPos.x;
780 var dy = pos.y - startPos.y;
781 // move birdArea div, keeping size
782 newRect = new Rectangle(
783 birdAreaRect.x + dx,
784 birdAreaRect.y + dy,
785 birdAreaRect.width,
786 birdAreaRect.height);
787 // stay within image
788 newRect.stayInside(birdImgRect);
789 moveElement(birdArea, newRect);
790 showElement(birdArea, true);
791 return stopEvent(evt);
792 }
793
794 function birdAreaEndDrag(evt) {
795 // mouseup handler: reload page
796 unregisterEvent("mousemove", document, birdAreaMove);
797 unregisterEvent("mouseup", document, birdAreaEndDrag);
798 showElement(overlay, false);
799 if (newRect == null) { // no movement happened
800 startPos = birdAreaRect.getCenter();
801 birdAreaMove(evt); // set center to click position
802 }
803 digilib.params.set("wx", cropFloat((newRect.x - birdImgRect.x) / birdImgRect.width));
804 digilib.params.set("wy", cropFloat((newRect.y - birdImgRect.y) / birdImgRect.height));
805 // zoomed is always fit
806 digilib.params.set("ws", 1);
807 digilib.display();
808 return stopEvent(evt);
809 }
810 }
811
812 Digilib.prototype.showArrow = function(name, rect, show) {
813 var arrow = getElement(name);
814 moveElement(arrow, rect);
815 showElement(arrow, show);
816 }
817
818 Digilib.prototype.showArrows = function() {
819 // show the 4 arrow bars on top of scaler img according to current dlArea
820 var r = getElementRect(this.scalerImg);
821 this.showArrow('up',
822 new Rectangle(r.x, r.y, r.width, this.ARROW_WIDTH),
823 this.canMove(0, -1)
824 );
825 this.showArrow('down',
826 new Rectangle(r.x, r.y + r.height - this.ARROW_WIDTH, r.width, this.ARROW_WIDTH),
827 this.canMove(0, 1)
828 );
829 this.showArrow('left',
830 new Rectangle(r.x, r.y, this.ARROW_WIDTH, r.height),
831 this.canMove(-1, 0)
832 );
833 this.showArrow('right',
834 new Rectangle(r.x + r.width - this.ARROW_WIDTH, r.y, this.ARROW_WIDTH, r.height),
835 this.canMove(1, 0)
836 );
837 }
838
839 Digilib.prototype.calibrate = function() {
840 // calibrate screen resolution
841 var calDiv = getElement("calibration");
842 var calRect = getElementRect(calDiv);
843 moveCenter(false);
844 var wins = getWinSize();
845 calRect.setCenter(new Position(wins.width / 2, wins.height / 2));
846 moveElement(calDiv, calRect);
847 showElement(calDiv, true);
848 var cm = window.prompt("The length of the scale on your screen in centimeter:");
849 if (cm) {
850 var dpi = calRect.width / parseFloat(cm) * 2.54;
851 this.params.set("ddpi", cropFloat(dpi));
852 }
853 showElement(calDiv, false);
854 }
855
856
857 Digilib.prototype.setScale = function(scale) {
858 // sets original-size, pixel-by-pixel or fit-to-screen scale type
859 if (scale == "pixel") {
860 // pixel by pixel
861 this.flags.set("clip");
862 this.flags.reset("osize");
863 this.flags.reset("fit");
864 } else if (scale == "original") {
865 // original size -- needs calibrated screen
866 if (!this.params.isSet("ddpi")) {
867 var dpi = cookie.get("ddpi");
868 if (dpi == null) {
869 alert("Your screen has not yet been calibrated - using default value of 72 dpi");
870 dpi = 72;
871 }
872 this.params.set("ddpi", dpi);
873 }
874 this.flags.set("osize");
875 this.flags.reset("clip");
876 this.flags.reset("fit");
877 } else {
878 // scale to screen size (default)
879 this.flags.reset("clip");
880 this.flags.reset("osize");
881 }
882 this.display();
883 }
884
885 Digilib.prototype.getScale = function() {
886 // returns scale type
887 if (this.flags.get("clip")) {
888 return "pixel";
889 } else if (this.flags.get("osize")) {
890 return "original";
891 } else {
892 return "fit";
893 }
894 }
895
896 Digilib.prototype.pageWidth = function() {
897 this.zoomFullpage('width');
898 }
899
900 Digilib.prototype.setSize = function(factor) {
901 this.params.set("ws", factor);
902 this.display();
903 }
904
905 Digilib.prototype.showMenu = function(menuId, buttonId, show) {
906 var menu = getElement(menuId);
907 if (show) {
908 // align right side of menu with button
909 var buttonPos = getElementPosition(getElement(buttonId));
910 var menusize = getElementSize(menu);
911 moveElement(menu, new Position(buttonPos.x - menusize.width - 3, buttonPos.y));
912 }
913 showElement(menu, show);
914 }
915
916
917 /********************************
918 * global variables
919 ********************************/
920
921 var dl = new Digilib();
922
923 /* old parameter function compatibility stuff */
924 function newParameter(a,b,c) {return dl.params.define(a,b,c)};
925 function resetParameter(a) {return dl.params.reset(a)};
926 function deleteParameter(a) {return dl.params.remove(a)};
927 function getParameter(a) {return dl.params.get(a)};
928 function setParameter(a,b,c) {return dl.params.set(a,b,c)};
929 function hasParameter(a) {return dl.params.isSet(a)};
930 function getAllParameters(a) {return dl.params.getAll(a)};
931 getQueryString = getAllParameters;
932 function parseParameters(a) {return dl.params.parse(a)};
933 function getAllMarks() {return dl.marks.getAll()};
934 getMarksQueryString = getAllMarks;
935 function addMark(evt) {return dl.marks.addEvent(evt)};
936 function deleteMark() {return dl.marks.pop()};
937 function deleteAllMarks() {return dl.marks = new Marks()};
938 function hasFlag(mode) {return dl.flags.get(mode)};
939 function addFlag(mode) {return dl.flags.set(mode)};
940 function removeFlag(mode) {return dl.flags.reset(mode)};
941 function toggleFlag(mode) {return dl.flags.toggle(mode)};
942 function getAllFlags() {return dl.flags.getAll()};
943 /* old digilib function compatibility */
944 function setDLParam(e, s, relative) {dl.setDLParam(e, s, relative)};
945 function display(detail, moDetail) {dl.display(detail, moDetail)};
946 function setMark(reload) {dl.setMark(reload)};
947 function removeMark(reload) {dl.removeMark(reload)};
948 function zoomArea() {dl.zoomArea()};
949 function zoomBy(factor) {dl.zoomBy(factor)};
950 function zoomFullpage(a) {dl.zoomFullpage(a)};
951 function moveCenter(on) {dl.moveCenter(on)};
952 function isFullArea(area) {dl.isFullArea(area)};
953 function canMove(movx, movy) {dl.canMove(movx, movy)};
954 function moveBy(movx, movy) {dl.moveBy(movx, movy)};
955 function getRef(baseURL) {dl.getRef(baseURL)};
956 function getRefWin(type, msg) {dl.getRefWin(type, msg)};
957 function getQuality() {dl.getQuality()};
958 function setQuality(qual) {dl.setQuality(qual)};
959 function setQualityWin(msg) {dl.setQualityWin(msg)};
960 function mirror(dir) {dl.mirror(dir)};
961 function gotoPage(gopage, keep) {dl.gotoPage(gopage, keep)};
962 function gotoPageWin() {dl.gotoPageWin()};
963 function setParamWin(param, text, relative) {dl.setParamWin(param, text, relative)};
964 function showOptions(show) {dl.showOptions(show)};
965 function showBirdDiv(show) {dl.showBirdDiv(show)};
966 function showAboutDiv(show) {dl.showAboutDiv(show)};
967 function calibrate(direction) {dl.calibrate(direction)};
968 function setScale(a) {dl.setScale(a)};
969 function getScale(a) {dl.getScale(a)};
970 function originalSize(on) {dl.originalSize(on)};
971 function pixelByPixel(on) {dl.pixelByPixel(on)};
972 function pageWidth() {dl.pageWidth()};
973 function setSize(factor) {dl.setSize(factor)};
974 function showMenu(a,b,c) {dl.showMenu(a,b,c)};
975
976
977 // :tabSize=4:indentSize=4:noTabs=true:
978