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