Mercurial > hg > digilib-old
annotate client/digitallibrary/greyskin/dllib.js @ 483:2b72e97ec9da
fixed a JS error when going forward/backward between pages
author | hertzhaft |
---|---|
date | Fri, 04 May 2007 18:59:55 +0200 |
parents | 9c16290e6f44 |
children | 351c5924b7a6 |
rev | line source |
---|---|
400 | 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 | |
411 | 21 Martin Raspe <hertzhaft@biblhertz.it>, 12.12.2005 |
400 | 22 |
23 ! Requires baselib.js ! | |
24 | |
25 */ | |
411 | 26 digilibVersion = "Digilib NG"; |
450 | 27 dllibVersion = "2.040"; |
28 | |
451 | 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 | |
450 | 59 /**************************************************** |
60 * digilib specific classes (must be defined first) | |
61 ****************************************************/ | |
62 | |
63 /* | |
64 * Marks class | |
65 */ | |
66 function Marks() { | |
67 return this; | |
68 } | |
69 // Marks inherits from Array | |
70 Marks.prototype = new Array(); | |
71 Marks.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 Marks.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 } | |
451 | 90 Marks.prototype.addEvent = function(evt, digilib) { |
450 | 91 // add a mark from a screen event |
451 | 92 if (!digilib) digilib = dl; |
93 var pos = digilib.trafo.invtransform(evtPosition(evt)); | |
450 | 94 this.push(pos); |
95 } | |
429
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
96 |
450 | 97 /* |
451 | 98 * DLParameters -- digilib parameter class |
450 | 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; | |
452 | 110 this.PARAM_CLIENT = 256; |
450 | 111 /* request parameters */ |
451 | 112 with (this) { |
450 | 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); | |
452 | 139 // client side options |
140 define('clop', '', PARAM_CLIENT); | |
451 | 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) { | |
452 | 148 if (!digilib) digilib = dl; |
451 | 149 // get Flags and Marks first |
150 var mo = digilib.flags.getAll(moDetail); | |
151 this.set("mo", mo); | |
452 | 152 var clop = digilib.opts.getAll(); |
153 this.set("clop", clop); | |
451 | 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; | |
450 | 170 /* mode flags */ |
451 | 171 with (this) { |
450 | 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 } | |
451 | 181 return this; |
450 | 182 } |
451 | 183 // inherits from Flags |
184 DLFlags.prototype = new Flags(); | |
185 | |
416 | 186 |
451 | 187 /* |
188 * Digilib -- digilib base class | |
189 */ | |
190 function Digilib() { | |
191 if (!baseLibVersion) alert("ERROR: baselib.js not loaded!"); | |
452 | 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; | |
451 | 210 this.trafo = null; |
211 // page elements | |
212 this.scalerDiv = null; | |
213 this.scalerImg = null; | |
452 | 214 this.buttons1Div = null; |
215 this.buttons2Div = null; | |
451 | 216 /* parse parameters */ |
455 | 217 this.params = new DLParameters(); |
451 | 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")); | |
452 | 226 this.opts = new Flags(); |
227 this.opts.parse(this.params.get("clop")); | |
451 | 228 return this; |
229 } | |
230 Digilib.prototype.setDLParam = function(e, s, relative) { | |
416 | 231 // sets parameter based on HTML event |
232 var nam; | |
400 | 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) { | |
451 | 242 dl.params.set(nam, val, relative); |
400 | 243 display(); |
244 } else { | |
245 alert("ERROR: unable to process event!"); | |
246 } | |
247 return true; | |
248 } | |
452 | 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 | |
455 | 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))); | |
452 | 273 // scale to screen size |
455 | 274 trafo.concat(trafo.getScale(picsize)); |
275 trafo.concat(trafo.getTranslation(picsize)); | |
452 | 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 | |
451 | 287 Digilib.prototype.onLoad = function() { |
288 // initialize digilib; called by body.onload | |
289 this.scalerDiv = getElement("scaler", true); | |
290 this.scalerImg = getElement("pic", true); | |
452 | 291 this.buttons1Div = getElement("buttons", true); |
292 this.buttons2Div = getElement("options", true); | |
293 /* if (this.scalerImg == null && this.scalerDiv) { | |
451 | 294 // in N4 pic is in the scaler layer |
295 this.scalerImg = this.scalerDiv.document.images[0]; | |
452 | 296 } */ |
451 | 297 if ((!this.scalerImg)||(!this.scalerDiv)) { |
298 alert("Sorry, digilib doesn't work here!"); | |
299 return false; | |
300 } | |
452 | 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) { | |
307 // unlock fixed menus to absolute | |
308 this.buttons1Div.style.position = "absolute"; | |
309 this.buttons2Div.style.position = "absolute"; | |
310 } | |
451 | 311 this.setScalerImage(); // setzt auch onImgLoad |
452 | 312 this.setBirdImage(); // l?dt das Bird's Eye Bild |
450 | 313 } |
452 | 314 |
315 Digilib.prototype.setScalerImage = function() { | |
450 | 316 // set the scaler image source (needs the browser size) |
452 | 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 | |
416 | 323 var src = "../servlet/Scaler?" |
452 | 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 } | |
416 | 332 // debug(src); |
451 | 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 | |
452 | 338 |
451 | 339 function onImgLoad() { |
483
2b72e97ec9da
fixed a JS error when going forward/backward between pages
hertzhaft
parents:
455
diff
changeset
|
340 if (! digilib) |
2b72e97ec9da
fixed a JS error when going forward/backward between pages
hertzhaft
parents:
455
diff
changeset
|
341 return; |
451 | 342 // make sure the image is loaded so we know its size |
452 | 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 } */ | |
451 | 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 | |
455 | 352 //digilib.moveCenter(true); // click to move point to center |
451 | 353 // new Slider("sizes", 1, 5, 2); |
354 focus(); | |
355 } | |
450 | 356 } |
451 | 357 Digilib.prototype.renderMarks = function() { |
416 | 358 // make sure the image is loaded so we know its size |
451 | 359 if (!this.trafo) { |
452 | 360 alert("ERROR: trafo missing, cannot render marks!"); |
450 | 361 return; |
362 } | |
416 | 363 // debugProps(dlArea, "dlArea"); |
451 | 364 for (var i = 0; i < this.marks.length; i++) { |
365 var div = getElement("mark" + i, true) || createMarkDiv(i); | |
366 var mark = this.marks[i]; | |
367 // debugProps(mark, "mark"); | |
368 if (this.area.containsPosition(mark)) { | |
452 | 369 var mpos = this.trafo.transform(mark); |
451 | 370 // debugProps(mark, "mpos"); |
452 | 371 // better not hide the marked spot (MR) |
450 | 372 // suboptimal to place -5 pixels and not half size of mark-image |
373 // mpos.x = mpos.x -5; | |
374 // mpos.y = mpos.y -5; | |
375 moveElement(div, mpos); | |
376 showElement(div, true); | |
377 } else { | |
378 // hide the other marks | |
379 showElement(div, false); | |
380 } | |
400 | 381 } |
450 | 382 } |
400 | 383 |
452 | 384 Digilib.prototype.display = function(detail, moDetail) { |
385 // redisplay the page | |
386 var queryString = this.params.getAll(detail, moDetail); | |
387 location.href | |
388 = location.protocol + "//" | |
389 + location.host | |
390 + location.pathname | |
391 + "?" + queryString; | |
392 } | |
393 | |
451 | 394 /* ********************************************** |
395 * interactive digilib functions | |
396 * ******************************************** */ | |
400 | 397 |
452 | 398 Digilib.prototype.setMark = function() { |
451 | 399 // add a mark where clicked |
400 window.focus(); | |
401 this.moveCenter(false); | |
402 // start event capturing | |
403 registerEvent("mousedown", this.scalerDiv, markEvent); | |
404 | |
405 // our own reference to this for the local function | |
406 var digilib = this; | |
407 | |
416 | 408 function markEvent(evt) { |
409 // event handler adding a new mark | |
451 | 410 unregisterEvent("mousedown", digilib.scalerDiv, markEvent); |
411 digilib.marks.addEvent(evt); | |
412 digilib.display(); | |
434 | 413 return stopEvent(evt); |
450 | 414 } |
416 | 415 |
450 | 416 } |
400 | 417 |
452 | 418 Digilib.prototype.removeMark = function() { |
400 | 419 // remove the last mark |
451 | 420 this.marks.pop(); |
421 this.display(); | |
400 | 422 } |
423 | |
451 | 424 Digilib.prototype.zoomArea = function() { |
416 | 425 var pt1, pt2; |
426 var zoomdiv = getElement("zoom"); | |
427 var overlay = getElement("overlay"); | |
428 // use overlay div to avoid <img> mousemove problems | |
451 | 429 var picRect = getElementRect(this.scalerImg); |
416 | 430 // FIX ME: is there a way to query the border width from CSS info? |
431 // rect.x -= 2; // account for overlay borders | |
432 // rect.y -= 2; | |
434 | 433 moveElement(overlay, picRect); |
416 | 434 showElement(overlay, true); |
435 // start event capturing | |
436 registerEvent("mousedown", overlay, zoomStart); | |
451 | 437 registerEvent("mousedown", this.scalerImg, zoomStart); |
416 | 438 window.focus(); |
400 | 439 |
451 | 440 // our own reference to this for the local function |
441 var digilib = this; | |
442 | |
452 | 443 // mousedown handler: start moving |
416 | 444 function zoomStart(evt) { |
445 pt1 = evtPosition(evt); | |
446 unregisterEvent("mousedown", overlay, zoomStart); | |
451 | 447 unregisterEvent("mousedown", digilib.scalerImg, zoomStart); |
416 | 448 // setup and show zoom div |
449 moveElement(zoomdiv, Rectangle(pt1.x, pt1.y, 0, 0)); | |
450 showElement(zoomdiv, true); | |
434 | 451 // register events |
452 registerEvent("mousemove", document, zoomMove); | |
453 registerEvent("mouseup", document, zoomEnd); | |
416 | 454 return stopEvent(evt); |
450 | 455 } |
416 | 456 |
452 | 457 // mouseup handler: end moving |
416 | 458 function zoomEnd(evt) { |
459 pt2 = evtPosition(evt); | |
460 // assume a click if the area is too small (up to 3 x 3 pixel) | |
450 | 461 var clickRect = new Rectangle(pt1, pt2); |
462 clickRect.normalize(); | |
452 | 463 if (clickRect.getArea() <= this.MIN_AREA_SIZE) return stopEvent(evt); |
416 | 464 // hide zoom div |
465 showElement(zoomdiv, false); | |
466 showElement(overlay, false); | |
434 | 467 // unregister events |
468 unregisterEvent("mousemove", document, zoomMove); | |
469 unregisterEvent("mouseup", document, zoomMove); | |
450 | 470 // clip and transform |
434 | 471 clickRect.clipTo(picRect); |
451 | 472 var area = digilib.trafo.invtransform(clickRect); |
473 digilib.setParamFromArea(area); | |
416 | 474 // zoomed is always fit |
451 | 475 digilib.params.set("ws", 1); |
476 digilib.display(); | |
416 | 477 return stopEvent(evt); |
450 | 478 } |
416 | 479 |
452 | 480 // mouse move handler |
416 | 481 function zoomMove(evt) { |
482 pt2 = evtPosition(evt); | |
450 | 483 var rect = new Rectangle(pt1, pt2); |
484 rect.normalize(); | |
434 | 485 rect.clipTo(picRect); |
416 | 486 // update zoom div |
434 | 487 moveElement(zoomdiv, rect); |
416 | 488 return stopEvent(evt); |
450 | 489 } |
400 | 490 } |
491 | |
451 | 492 Digilib.prototype.zoomBy = function(factor) { |
400 | 493 // zooms by the given factor |
451 | 494 var newarea = this.area.copy(); |
400 | 495 newarea.width /= factor; |
496 newarea.height /= factor; | |
451 | 497 newarea.x -= 0.5 * (newarea.width - this.area.width); |
498 newarea.y -= 0.5 * (newarea.height - this.area.height); | |
452 | 499 newarea = this.MAX_AREA.fit(newarea); |
451 | 500 this.setParamFromArea(newarea); |
501 this.display(); | |
400 | 502 } |
503 | |
504 | |
452 | 505 Digilib.prototype.zoomFullpage = function(fit) { |
400 | 506 // zooms out to show the whole image |
451 | 507 this.params.set("wx", 0.0); |
508 this.params.set("wy", 0.0); | |
509 this.params.set("ww", 1.0); | |
510 this.params.set("wh", 1.0); | |
452 | 511 if (fit == "width") { |
512 this.opts.set('fitwidth'); | |
513 } else if (fit == "height") { | |
514 this.opts.set('fitheight'); | |
515 } else { | |
516 this.opts.reset('fitwidth'); | |
517 this.opts.reset('fitheight'); | |
518 } | |
451 | 519 this.display(); |
400 | 520 } |
521 | |
522 | |
451 | 523 Digilib.prototype.moveCenter = function(on) { |
400 | 524 // move visible area so that it's centered around the clicked point |
451 | 525 if (this.isFullArea()) return; // nothing to do |
434 | 526 // starting event capture |
451 | 527 if (on) registerEvent("mousedown", this.scalerImg, moveCenterEvent); |
528 else unregisterEvent("mousedown", this.scalerImg, moveCenterEvent); | |
400 | 529 window.focus(); |
451 | 530 |
531 // our own reference to this for the local function | |
532 var digilib = this; | |
533 | |
534 function moveCenterEvent(evt) { | |
535 // move to handler | |
536 var pt = digilib.trafo.invtransform(evtPosition(evt)); | |
537 var newarea = digilib.area.copy(); | |
538 newarea.setCenter(pt); | |
452 | 539 newarea.stayInside(this.MAX_AREA); |
451 | 540 // newarea = dlMaxArea.fit(newarea); |
541 // debugProps(newarea, "newarea"); | |
542 // debugProps(dlArea, "dlArea"); | |
543 if (newarea.equals(digilib.area)) return; // keep event handler | |
544 unregisterEvent("mousedown", digilib.scalerImg, moveCenterEvent); | |
545 // set parameters | |
546 digilib.setParamFromArea(newarea); | |
547 digilib.display(); | |
548 } | |
434 | 549 } |
400 | 550 |
451 | 551 Digilib.prototype.isFullArea = function(area) { |
552 if (!area) area = this.area; | |
455 | 553 return (area.width == 1.0) && (area.height == 1.0); |
434 | 554 } |
416 | 555 |
451 | 556 Digilib.prototype.canMove = function(movx, movy) { |
557 if (this.isFullArea()) return false; | |
558 var x2 = this.area.x + this.area.width; | |
559 var y2 = this.area.y + this.area.height; | |
429
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
560 // debugProps(dlArea); |
451 | 561 return ((movx < 0) && (this.area.x > 0)) |
434 | 562 || ((movx > 0) && (x2 < 1.0)) |
451 | 563 || ((movy < 0) && (this.area.y > 0)) |
434 | 564 || ((movy > 0) && (y2 < 1.0)) |
565 } | |
416 | 566 |
451 | 567 Digilib.prototype.moveBy = function(movx, movy) { |
400 | 568 // move visible area by movx and movy (in units of ww, wh) |
451 | 569 if (!this.canMove(movx, movy)) return; // nothing to do |
570 var newarea = this.area.copy(); | |
571 newarea.x += parseFloat(movx)*this.area.width; | |
572 newarea.y += parseFloat(movy)*this.area.height; | |
452 | 573 newarea = this.MAX_AREA.fit(newarea); |
400 | 574 // set parameters |
451 | 575 this.setParamFromArea(newarea); |
576 this.display(); | |
400 | 577 } |
578 | |
451 | 579 Digilib.prototype.getRef = function(baseUrl) { |
400 | 580 // returns a reference to the current digilib set |
429
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
581 if (!baseUrl) baseUrl |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
582 = location.protocol |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
583 + "//" |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
584 + location.host |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
585 + location.pathname; |
400 | 586 var hyperlinkRef = baseUrl; |
451 | 587 with (this.params) { |
452 | 588 // all without ddpi, pt |
589 var ps = getAll(PARAM_ALL & ~(PARAM_DPI | PARAM_PAGES | PARAM_CLIENT)); | |
451 | 590 } |
591 if (ps.length > 0) hyperlinkRef += "?" + ps; | |
411 | 592 return hyperlinkRef; |
450 | 593 } |
400 | 594 |
451 | 595 Digilib.prototype.getRefWin = function(type, msg) { |
400 | 596 // shows an alert with a reference to the current digilib set |
411 | 597 if (! msg) msg = "URL reference to the current view"; |
451 | 598 prompt(msg, this.getRef()); |
450 | 599 } |
400 | 600 |
451 | 601 Digilib.prototype.getQuality = function() { |
411 | 602 // returns the current q setting |
400 | 603 for (var i = 0; i < 3; i++) { |
451 | 604 if (this.flags.get("q"+i)) return i; |
450 | 605 } |
411 | 606 return 1 |
450 | 607 } |
400 | 608 |
451 | 609 Digilib.prototype.setQuality = function(qual) { |
400 | 610 // set the image quality |
450 | 611 if ((qual < 0)||(qual > 2)) return alert("Quality setting not supported"); |
451 | 612 for (var i = 0; i < 3; i++) this.flags.reset("q" + i); |
613 this.flags.set("q" + qual); | |
614 this.display(); | |
411 | 615 } |
400 | 616 |
451 | 617 Digilib.prototype.setQualityWin = function(msg) { |
416 | 618 // dialog for setting quality |
619 if (! msg) msg = "Quality (0..2)"; | |
451 | 620 var q = this.getQuality(); |
416 | 621 var newq = window.prompt(msg, q); |
451 | 622 if (newq) this.setQuality(newq); |
450 | 623 } |
400 | 624 |
451 | 625 Digilib.prototype.mirror = function(dir) { |
400 | 626 // mirror the image horizontally or vertically |
450 | 627 if (dir == "h") { |
451 | 628 this.flags.toggle("hmir"); |
450 | 629 } else { |
451 | 630 this.flags.toggle("vmir"); |
450 | 631 } |
451 | 632 this.display(); |
400 | 633 } |
634 | |
451 | 635 Digilib.prototype.gotoPage = function(gopage, keep) { |
416 | 636 // goto given page nr (+/-: relative) |
451 | 637 var oldpn = parseInt(this.params.get("pn")); |
638 // set with relative=true uses the sign | |
639 this.params.set("pn", gopage, true); | |
640 // now check the outcome | |
641 var pn = parseInt(this.params.get("pn")); | |
416 | 642 if (pn < 1) { |
643 alert("No such page! (Page number too low)"); | |
451 | 644 this.params.set("pn", oldpn); |
416 | 645 return; |
646 } | |
451 | 647 if (this.params.isSet("pt")) { |
648 pt = parseInt(this.params.get("pt")) | |
416 | 649 if (pn > pt) { |
650 alert("No such page! (Page number too high)"); | |
451 | 651 this.params.set("pn", oldpn); |
416 | 652 return; |
653 } | |
654 } | |
655 if (keep) { | |
451 | 656 this.display(this.params.PARAM_ALL & ~this.params.PARAM_MARK); // all, no mark |
416 | 657 } else { |
451 | 658 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 |
416 | 659 } |
400 | 660 } |
661 | |
451 | 662 Digilib.prototype.gotoPageWin = function() { |
416 | 663 // dialog to ask for new page nr |
451 | 664 var pn = this.params.get("pn"); |
416 | 665 var gopage = window.prompt("Go to page", pn); |
451 | 666 if (gopage) this.gotoPage(gopage); |
667 } | |
400 | 668 |
451 | 669 Digilib.prototype.setParamWin = function(param, text, relative) { |
416 | 670 // dialog to ask for new parameter value |
451 | 671 var val = this.params.get(param); |
416 | 672 var newval = window.prompt(text, val); |
673 if (newval) { | |
451 | 674 this.params.set(param, newval, relative); |
675 this.display(); | |
416 | 676 } |
400 | 677 } |
678 | |
451 | 679 Digilib.prototype.showOptions = function(show) { |
416 | 680 // show or hide option div |
681 var elem = getElement("dloptions"); | |
682 showElement(elem, show); | |
683 // FIX ME: get rid of the dotted line around the buttons when focused | |
684 } | |
411 | 685 |
451 | 686 Digilib.prototype.showAboutDiv = function(show) { |
416 | 687 // show or hide "about" div |
688 var elem = getElement("about"); | |
689 if (elem == null) { | |
443 | 690 if (show) alert("About Digilib - dialog missing in HTML code!" |
416 | 691 + "\nDigilib Version: " + digilibVersion |
434 | 692 + "\JSP Version: " + jspVersion |
416 | 693 + "\ndlLib Version: " + dllibVersion |
694 + "\nbaseLib Version: " + baseLibVersion); | |
695 return; | |
696 } | |
443 | 697 if (show) { |
698 getElement("digilib-version").innerHTML = "Digilib Version: " + digilibVersion; | |
699 getElement("jsp-version").innerHTML = "JSP Version: " + jspVersion; | |
700 getElement("baselib-version").innerHTML = "baseLib Version: " + baseLibVersion; | |
701 getElement("dllib-version").innerHTML = "dlLib Version: " + dllibVersion; | |
702 var aboutRect = getElementRect(elem); | |
703 aboutRect.setCenter(getWinRect().getCenter()); | |
704 moveElement(elem, aboutRect); | |
705 } | |
416 | 706 showElement(elem, show); |
707 } | |
708 | |
452 | 709 Digilib.prototype.setBirdImage = function() { |
416 | 710 var img = getElement("bird-image"); |
711 var src = "../servlet/Scaler?" | |
451 | 712 + this.params.getAll(this.params.PARAM_FILE) |
452 | 713 + "&dw=" + this.BIRD_MAXX |
714 + "&dh=" + this.BIRD_MAXY; | |
416 | 715 img.src = src; |
451 | 716 } |
416 | 717 |
451 | 718 Digilib.prototype.showBirdDiv = function(show) { |
416 | 719 // show or hide "bird's eye" div |
720 var startPos; // anchor for dragging | |
721 var newRect; // position after drag | |
722 var birdImg = getElement("bird-image"); | |
434 | 723 var birdArea = getElement("bird-area"); |
724 var overlay = getElement("overlay"); | |
416 | 725 showElement(birdImg, show); |
434 | 726 // dont show selector if area has full size |
451 | 727 if (!show || this.isFullArea()) { |
416 | 728 // hide area |
729 showElement(birdArea, false); | |
434 | 730 showElement(overlay, false); |
416 | 731 return; |
451 | 732 }; |
416 | 733 var birdImgRect = getElementRect(birdImg); |
451 | 734 var area = this.area; |
455 | 735 if (this.flags.get("osize") || this.flags.get("clip")) { |
736 // in original-size and pixel-by-pixel mode the area size is not valid | |
737 var birdAreaRect = new Rectangle( | |
738 birdImgRect.x + birdImgRect.width * area.x, | |
739 birdImgRect.y + birdImgRect.height * area.y, | |
740 5, | |
741 5); | |
742 } else { | |
743 // scale area down to img size | |
744 var birdAreaRect = new Rectangle( | |
745 // what about borders ?? | |
746 birdImgRect.x + birdImgRect.width * area.x, | |
747 birdImgRect.y + birdImgRect.height * area.y, | |
748 birdImgRect.width * area.width, | |
749 birdImgRect.height * area.height); | |
750 } | |
416 | 751 moveElement(birdArea, birdAreaRect); |
434 | 752 showElement(birdArea, true); |
753 moveElement(overlay, birdImgRect); | |
754 showElement(overlay, true); | |
755 registerEvent("mousedown", overlay, birdAreaStartDrag); | |
756 registerEvent("mousedown", birdImg, birdAreaStartDrag); | |
416 | 757 |
451 | 758 // our own reference to this for local functions |
759 var digilib = this; | |
760 | |
416 | 761 function birdAreaStartDrag(evt) { |
762 // mousedown handler: start drag | |
763 startPos = evtPosition(evt); | |
434 | 764 unregisterEvent("mousedown", overlay, birdAreaStartDrag); |
765 unregisterEvent("mousedown", birdImg, birdAreaStartDrag); | |
766 registerEvent("mousemove", document, birdAreaMove); | |
767 registerEvent("mouseup", document, birdAreaEndDrag); | |
416 | 768 // debugProps(getElementRect(bird)) |
769 return stopEvent(evt); | |
451 | 770 } |
416 | 771 |
772 function birdAreaMove(evt) { | |
773 // mousemove handler: drag | |
774 var pos = evtPosition(evt); | |
775 var dx = pos.x - startPos.x; | |
776 var dy = pos.y - startPos.y; | |
777 // move birdArea div, keeping size | |
778 newRect = new Rectangle( | |
779 birdAreaRect.x + dx, | |
780 birdAreaRect.y + dy, | |
781 birdAreaRect.width, | |
782 birdAreaRect.height); | |
783 // stay within image | |
784 newRect.stayInside(birdImgRect); | |
785 moveElement(birdArea, newRect); | |
786 showElement(birdArea, true); | |
787 return stopEvent(evt); | |
451 | 788 } |
416 | 789 |
790 function birdAreaEndDrag(evt) { | |
791 // mouseup handler: reload page | |
434 | 792 unregisterEvent("mousemove", document, birdAreaMove); |
793 unregisterEvent("mouseup", document, birdAreaEndDrag); | |
794 showElement(overlay, false); | |
795 if (newRect == null) { // no movement happened | |
796 startPos = birdAreaRect.getCenter(); | |
797 birdAreaMove(evt); // set center to click position | |
798 } | |
451 | 799 digilib.params.set("wx", cropFloat((newRect.x - birdImgRect.x) / birdImgRect.width)); |
800 digilib.params.set("wy", cropFloat((newRect.y - birdImgRect.y) / birdImgRect.height)); | |
416 | 801 // zoomed is always fit |
451 | 802 digilib.params.set("ws", 1); |
803 digilib.display(); | |
416 | 804 return stopEvent(evt); |
805 } | |
451 | 806 } |
416 | 807 |
451 | 808 Digilib.prototype.showArrow = function(name, rect, show) { |
429
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
809 var arrow = getElement(name); |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
810 moveElement(arrow, rect); |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
811 showElement(arrow, show); |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
812 } |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
813 |
451 | 814 Digilib.prototype.showArrows = function() { |
443 | 815 // show the 4 arrow bars on top of scaler img according to current dlArea |
451 | 816 var r = getElementRect(this.scalerImg); |
817 this.showArrow('up', | |
452 | 818 new Rectangle(r.x, r.y, r.width, this.ARROW_WIDTH), |
451 | 819 this.canMove(0, -1) |
429
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
820 ); |
451 | 821 this.showArrow('down', |
452 | 822 new Rectangle(r.x, r.y + r.height - this.ARROW_WIDTH, r.width, this.ARROW_WIDTH), |
451 | 823 this.canMove(0, 1) |
429
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
824 ); |
451 | 825 this.showArrow('left', |
452 | 826 new Rectangle(r.x, r.y, this.ARROW_WIDTH, r.height), |
451 | 827 this.canMove(-1, 0) |
429
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
828 ); |
451 | 829 this.showArrow('right', |
452 | 830 new Rectangle(r.x + r.width - this.ARROW_WIDTH, r.y, this.ARROW_WIDTH, r.height), |
451 | 831 this.canMove(1, 0) |
429
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
832 ); |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
833 } |
416 | 834 |
455 | 835 Digilib.prototype.calibrate = function() { |
836 // calibrate screen resolution | |
434 | 837 var calDiv = getElement("calibration"); |
455 | 838 var calRect = getElementRect(calDiv); |
434 | 839 moveCenter(false); |
455 | 840 var wins = getWinSize(); |
841 calRect.setCenter(new Position(wins.width / 2, wins.height / 2)); | |
842 moveElement(calDiv, calRect); | |
843 showElement(calDiv, true); | |
844 var cm = window.prompt("The length of the scale on your screen in centimeter:"); | |
845 if (cm) { | |
846 var dpi = calRect.width / parseFloat(cm) * 2.54; | |
847 this.params.set("ddpi", cropFloat(dpi)); | |
848 } | |
849 showElement(calDiv, false); | |
850 } | |
434 | 851 |
852 | |
455 | 853 Digilib.prototype.setScale = function(scale) { |
854 // sets original-size, pixel-by-pixel or fit-to-screen scale type | |
855 if (scale == "pixel") { | |
856 // pixel by pixel | |
857 this.flags.set("clip"); | |
858 this.flags.reset("osize"); | |
859 this.flags.reset("fit"); | |
860 } else if (scale == "original") { | |
861 // original size -- needs calibrated screen | |
862 if (!this.params.isSet("ddpi")) { | |
863 var dpi = cookie.get("ddpi"); | |
864 if (dpi == null) { | |
865 alert("Your screen has not yet been calibrated - using default value of 72 dpi"); | |
866 dpi = 72; | |
867 } | |
868 this.params.set("ddpi", dpi); | |
869 } | |
451 | 870 this.flags.set("osize"); |
455 | 871 this.flags.reset("clip"); |
872 this.flags.reset("fit"); | |
451 | 873 } else { |
455 | 874 // scale to screen size (default) |
875 this.flags.reset("clip"); | |
451 | 876 this.flags.reset("osize"); |
877 } | |
455 | 878 this.display(); |
439 | 879 } |
451 | 880 |
455 | 881 Digilib.prototype.getScale = function() { |
882 // returns scale type | |
883 if (this.flags.get("clip")) { | |
884 return "pixel"; | |
885 } else if (this.flags.get("osize")) { | |
886 return "original"; | |
887 } else { | |
888 return "fit"; | |
889 } | |
890 } | |
440 | 891 |
451 | 892 Digilib.prototype.pageWidth = function() { |
452 | 893 this.zoomFullpage('width'); |
445 | 894 } |
895 | |
455 | 896 Digilib.prototype.setSize = function(factor) { |
451 | 897 this.params.set("ws", factor); |
898 this.display(); | |
440 | 899 } |
900 | |
455 | 901 Digilib.prototype.showMenu = function(menuId, buttonId, show) { |
902 var menu = getElement(menuId); | |
443 | 903 if (show) { |
455 | 904 // align right side of menu with button |
905 var buttonPos = getElementPosition(getElement(buttonId)); | |
906 var menusize = getElementSize(menu); | |
907 moveElement(menu, new Position(buttonPos.x - menusize.width - 3, buttonPos.y)); | |
443 | 908 } |
909 showElement(menu, show); | |
440 | 910 } |
451 | 911 |
912 | |
913 /******************************** | |
914 * global variables | |
915 ********************************/ | |
916 | |
917 var dl = new Digilib(); | |
918 | |
919 /* old parameter function compatibility stuff */ | |
920 function newParameter(a,b,c) {return dl.params.define(a,b,c)}; | |
921 function resetParameter(a) {return dl.params.reset(a)}; | |
922 function deleteParameter(a) {return dl.params.remove(a)}; | |
923 function getParameter(a) {return dl.params.get(a)}; | |
924 function setParameter(a,b,c) {return dl.params.set(a,b,c)}; | |
925 function hasParameter(a) {return dl.params.isSet(a)}; | |
926 function getAllParameters(a) {return dl.params.getAll(a)}; | |
927 getQueryString = getAllParameters; | |
928 function parseParameters(a) {return dl.params.parse(a)}; | |
929 function getAllMarks() {return dl.marks.getAll()}; | |
930 getMarksQueryString = getAllMarks; | |
931 function addMark(evt) {return dl.marks.addEvent(evt)}; | |
932 function deleteMark() {return dl.marks.pop()}; | |
933 function deleteAllMarks() {return dl.marks = new Marks()}; | |
934 function hasFlag(mode) {return dl.flags.get(mode)}; | |
935 function addFlag(mode) {return dl.flags.set(mode)}; | |
936 function removeFlag(mode) {return dl.flags.reset(mode)}; | |
937 function toggleFlag(mode) {return dl.flags.toggle(mode)}; | |
938 function getAllFlags() {return dl.flags.getAll()}; | |
939 /* old digilib function compatibility */ | |
940 function setDLParam(e, s, relative) {dl.setDLParam(e, s, relative)}; | |
941 function display(detail, moDetail) {dl.display(detail, moDetail)}; | |
942 function setMark(reload) {dl.setMark(reload)}; | |
943 function removeMark(reload) {dl.removeMark(reload)}; | |
944 function zoomArea() {dl.zoomArea()}; | |
945 function zoomBy(factor) {dl.zoomBy(factor)}; | |
455 | 946 function zoomFullpage(a) {dl.zoomFullpage(a)}; |
451 | 947 function moveCenter(on) {dl.moveCenter(on)}; |
948 function isFullArea(area) {dl.isFullArea(area)}; | |
949 function canMove(movx, movy) {dl.canMove(movx, movy)}; | |
950 function moveBy(movx, movy) {dl.moveBy(movx, movy)}; | |
951 function getRef(baseURL) {dl.getRef(baseURL)}; | |
952 function getRefWin(type, msg) {dl.getRefWin(type, msg)}; | |
953 function getQuality() {dl.getQuality()}; | |
954 function setQuality(qual) {dl.setQuality(qual)}; | |
955 function setQualityWin(msg) {dl.setQualityWin(msg)}; | |
956 function mirror(dir) {dl.mirror(dir)}; | |
957 function gotoPage(gopage, keep) {dl.gotoPage(gopage, keep)}; | |
958 function gotoPageWin() {dl.gotoPageWin()}; | |
959 function setParamWin(param, text, relative) {dl.setParamWin(param, text, relative)}; | |
960 function showOptions(show) {dl.showOptions(show)}; | |
961 function showBirdDiv(show) {dl.showBirdDiv(show)}; | |
962 function showAboutDiv(show) {dl.showAboutDiv(show)}; | |
963 function calibrate(direction) {dl.calibrate(direction)}; | |
455 | 964 function setScale(a) {dl.setScale(a)}; |
965 function getScale(a) {dl.getScale(a)}; | |
451 | 966 function originalSize(on) {dl.originalSize(on)}; |
967 function pixelByPixel(on) {dl.pixelByPixel(on)}; | |
968 function pageWidth() {dl.pageWidth()}; | |
455 | 969 function setSize(factor) {dl.setSize(factor)}; |
970 function showMenu(a,b,c) {dl.showMenu(a,b,c)}; | |
451 | 971 |
972 | |
434 | 973 // :tabSize=4:indentSize=4:noTabs=true: |
974 |