Mercurial > hg > digilib-old
annotate client/digitallibrary/greyskin/dllib.js @ 452:6edd60cfa47f
ongoing experimental intermediary release
- more cleanup on object stuff
- new mark image
- menu is now fixed and tries to work in IE
author | robcast |
---|---|
date | Tue, 24 Jan 2006 21:17:44 +0100 |
parents | a6c83fa262b2 |
children | 9c16290e6f44 |
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 */ |
217 // put the query parameters (sans "?") in the parameters array | |
218 this.params = new DLParameters(); | |
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 | |
271 trafo.concat(getTranslation(new Position(-this.area.x, -this.area.y))); | |
272 trafo.concat(getScale(new Size(1/this.area.width, 1/this.area.height))); | |
273 // scale to screen size | |
274 trafo.concat(getScale(picsize)); | |
275 trafo.concat(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 | |
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 | |
350 digilib.moveCenter(true); // click to move point to center | |
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; | |
443 | 551 // pixel by pixel is not always full area |
452 | 552 return (area.width == 1.0) && (area.height == 1.0) && ! this.flags.get("clip"); |
434 | 553 } |
416 | 554 |
451 | 555 Digilib.prototype.canMove = function(movx, movy) { |
556 if (this.isFullArea()) return false; | |
557 var x2 = this.area.x + this.area.width; | |
558 var y2 = this.area.y + this.area.height; | |
429
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
559 // debugProps(dlArea); |
451 | 560 return ((movx < 0) && (this.area.x > 0)) |
434 | 561 || ((movx > 0) && (x2 < 1.0)) |
451 | 562 || ((movy < 0) && (this.area.y > 0)) |
434 | 563 || ((movy > 0) && (y2 < 1.0)) |
564 } | |
416 | 565 |
451 | 566 Digilib.prototype.moveBy = function(movx, movy) { |
400 | 567 // move visible area by movx and movy (in units of ww, wh) |
451 | 568 if (!this.canMove(movx, movy)) return; // nothing to do |
569 var newarea = this.area.copy(); | |
570 newarea.x += parseFloat(movx)*this.area.width; | |
571 newarea.y += parseFloat(movy)*this.area.height; | |
452 | 572 newarea = this.MAX_AREA.fit(newarea); |
400 | 573 // set parameters |
451 | 574 this.setParamFromArea(newarea); |
575 this.display(); | |
400 | 576 } |
577 | |
451 | 578 Digilib.prototype.getRef = function(baseUrl) { |
400 | 579 // returns a reference to the current digilib set |
429
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
580 if (!baseUrl) baseUrl |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
581 = location.protocol |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
582 + "//" |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
583 + location.host |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
584 + location.pathname; |
400 | 585 var hyperlinkRef = baseUrl; |
451 | 586 with (this.params) { |
452 | 587 // all without ddpi, pt |
588 var ps = getAll(PARAM_ALL & ~(PARAM_DPI | PARAM_PAGES | PARAM_CLIENT)); | |
451 | 589 } |
590 if (ps.length > 0) hyperlinkRef += "?" + ps; | |
411 | 591 return hyperlinkRef; |
450 | 592 } |
400 | 593 |
451 | 594 Digilib.prototype.getRefWin = function(type, msg) { |
400 | 595 // shows an alert with a reference to the current digilib set |
411 | 596 if (! msg) msg = "URL reference to the current view"; |
451 | 597 prompt(msg, this.getRef()); |
450 | 598 } |
400 | 599 |
451 | 600 Digilib.prototype.getQuality = function() { |
411 | 601 // returns the current q setting |
400 | 602 for (var i = 0; i < 3; i++) { |
451 | 603 if (this.flags.get("q"+i)) return i; |
450 | 604 } |
411 | 605 return 1 |
450 | 606 } |
400 | 607 |
451 | 608 Digilib.prototype.setQuality = function(qual) { |
400 | 609 // set the image quality |
450 | 610 if ((qual < 0)||(qual > 2)) return alert("Quality setting not supported"); |
451 | 611 for (var i = 0; i < 3; i++) this.flags.reset("q" + i); |
612 this.flags.set("q" + qual); | |
613 this.display(); | |
411 | 614 } |
400 | 615 |
451 | 616 Digilib.prototype.setQualityWin = function(msg) { |
416 | 617 // dialog for setting quality |
618 if (! msg) msg = "Quality (0..2)"; | |
451 | 619 var q = this.getQuality(); |
416 | 620 var newq = window.prompt(msg, q); |
451 | 621 if (newq) this.setQuality(newq); |
450 | 622 } |
400 | 623 |
451 | 624 Digilib.prototype.mirror = function(dir) { |
400 | 625 // mirror the image horizontally or vertically |
450 | 626 if (dir == "h") { |
451 | 627 this.flags.toggle("hmir"); |
450 | 628 } else { |
451 | 629 this.flags.toggle("vmir"); |
450 | 630 } |
451 | 631 this.display(); |
400 | 632 } |
633 | |
451 | 634 Digilib.prototype.gotoPage = function(gopage, keep) { |
416 | 635 // goto given page nr (+/-: relative) |
451 | 636 var oldpn = parseInt(this.params.get("pn")); |
637 // set with relative=true uses the sign | |
638 this.params.set("pn", gopage, true); | |
639 // now check the outcome | |
640 var pn = parseInt(this.params.get("pn")); | |
416 | 641 if (pn < 1) { |
642 alert("No such page! (Page number too low)"); | |
451 | 643 this.params.set("pn", oldpn); |
416 | 644 return; |
645 } | |
451 | 646 if (this.params.isSet("pt")) { |
647 pt = parseInt(this.params.get("pt")) | |
416 | 648 if (pn > pt) { |
649 alert("No such page! (Page number too high)"); | |
451 | 650 this.params.set("pn", oldpn); |
416 | 651 return; |
652 } | |
653 } | |
654 if (keep) { | |
451 | 655 this.display(this.params.PARAM_ALL & ~this.params.PARAM_MARK); // all, no mark |
416 | 656 } else { |
451 | 657 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 | 658 } |
400 | 659 } |
660 | |
451 | 661 Digilib.prototype.gotoPageWin = function() { |
416 | 662 // dialog to ask for new page nr |
451 | 663 var pn = this.params.get("pn"); |
416 | 664 var gopage = window.prompt("Go to page", pn); |
451 | 665 if (gopage) this.gotoPage(gopage); |
666 } | |
400 | 667 |
451 | 668 Digilib.prototype.setParamWin = function(param, text, relative) { |
416 | 669 // dialog to ask for new parameter value |
451 | 670 var val = this.params.get(param); |
416 | 671 var newval = window.prompt(text, val); |
672 if (newval) { | |
451 | 673 this.params.set(param, newval, relative); |
674 this.display(); | |
416 | 675 } |
400 | 676 } |
677 | |
451 | 678 Digilib.prototype.showOptions = function(show) { |
416 | 679 // show or hide option div |
680 var elem = getElement("dloptions"); | |
681 showElement(elem, show); | |
682 // FIX ME: get rid of the dotted line around the buttons when focused | |
683 } | |
411 | 684 |
451 | 685 Digilib.prototype.showAboutDiv = function(show) { |
416 | 686 // show or hide "about" div |
687 var elem = getElement("about"); | |
688 if (elem == null) { | |
443 | 689 if (show) alert("About Digilib - dialog missing in HTML code!" |
416 | 690 + "\nDigilib Version: " + digilibVersion |
434 | 691 + "\JSP Version: " + jspVersion |
416 | 692 + "\ndlLib Version: " + dllibVersion |
693 + "\nbaseLib Version: " + baseLibVersion); | |
694 return; | |
695 } | |
443 | 696 if (show) { |
697 getElement("digilib-version").innerHTML = "Digilib Version: " + digilibVersion; | |
698 getElement("jsp-version").innerHTML = "JSP Version: " + jspVersion; | |
699 getElement("baselib-version").innerHTML = "baseLib Version: " + baseLibVersion; | |
700 getElement("dllib-version").innerHTML = "dlLib Version: " + dllibVersion; | |
701 var aboutRect = getElementRect(elem); | |
702 aboutRect.setCenter(getWinRect().getCenter()); | |
703 moveElement(elem, aboutRect); | |
704 } | |
416 | 705 showElement(elem, show); |
706 } | |
707 | |
452 | 708 Digilib.prototype.setBirdImage = function() { |
416 | 709 var img = getElement("bird-image"); |
710 var src = "../servlet/Scaler?" | |
451 | 711 + this.params.getAll(this.params.PARAM_FILE) |
452 | 712 + "&dw=" + this.BIRD_MAXX |
713 + "&dh=" + this.BIRD_MAXY; | |
416 | 714 img.src = src; |
451 | 715 } |
416 | 716 |
451 | 717 Digilib.prototype.showBirdDiv = function(show) { |
416 | 718 // show or hide "bird's eye" div |
719 var startPos; // anchor for dragging | |
720 var newRect; // position after drag | |
721 var birdImg = getElement("bird-image"); | |
434 | 722 var birdArea = getElement("bird-area"); |
723 var overlay = getElement("overlay"); | |
416 | 724 showElement(birdImg, show); |
434 | 725 // dont show selector if area has full size |
451 | 726 if (!show || this.isFullArea()) { |
416 | 727 // hide area |
728 showElement(birdArea, false); | |
434 | 729 showElement(overlay, false); |
416 | 730 return; |
451 | 731 }; |
416 | 732 var birdImgRect = getElementRect(birdImg); |
451 | 733 var area = this.area; |
416 | 734 // scale area down to img size |
735 var birdAreaRect = new Rectangle( | |
736 // what about borders ?? | |
737 birdImgRect.x + birdImgRect.width * area.x, | |
738 birdImgRect.y + birdImgRect.height * area.y, | |
739 birdImgRect.width * area.width, | |
740 birdImgRect.height * area.height | |
741 ); | |
742 moveElement(birdArea, birdAreaRect); | |
434 | 743 showElement(birdArea, true); |
744 moveElement(overlay, birdImgRect); | |
745 showElement(overlay, true); | |
746 registerEvent("mousedown", overlay, birdAreaStartDrag); | |
747 registerEvent("mousedown", birdImg, birdAreaStartDrag); | |
416 | 748 |
451 | 749 // our own reference to this for local functions |
750 var digilib = this; | |
751 | |
416 | 752 function birdAreaStartDrag(evt) { |
753 // mousedown handler: start drag | |
754 startPos = evtPosition(evt); | |
434 | 755 unregisterEvent("mousedown", overlay, birdAreaStartDrag); |
756 unregisterEvent("mousedown", birdImg, birdAreaStartDrag); | |
757 registerEvent("mousemove", document, birdAreaMove); | |
758 registerEvent("mouseup", document, birdAreaEndDrag); | |
416 | 759 // debugProps(getElementRect(bird)) |
760 return stopEvent(evt); | |
451 | 761 } |
416 | 762 |
763 function birdAreaMove(evt) { | |
764 // mousemove handler: drag | |
765 var pos = evtPosition(evt); | |
766 var dx = pos.x - startPos.x; | |
767 var dy = pos.y - startPos.y; | |
768 // move birdArea div, keeping size | |
769 newRect = new Rectangle( | |
770 birdAreaRect.x + dx, | |
771 birdAreaRect.y + dy, | |
772 birdAreaRect.width, | |
773 birdAreaRect.height); | |
774 // stay within image | |
775 newRect.stayInside(birdImgRect); | |
776 moveElement(birdArea, newRect); | |
777 showElement(birdArea, true); | |
778 return stopEvent(evt); | |
451 | 779 } |
416 | 780 |
781 function birdAreaEndDrag(evt) { | |
782 // mouseup handler: reload page | |
434 | 783 unregisterEvent("mousemove", document, birdAreaMove); |
784 unregisterEvent("mouseup", document, birdAreaEndDrag); | |
785 showElement(overlay, false); | |
786 if (newRect == null) { // no movement happened | |
787 startPos = birdAreaRect.getCenter(); | |
788 birdAreaMove(evt); // set center to click position | |
789 } | |
451 | 790 digilib.params.set("wx", cropFloat((newRect.x - birdImgRect.x) / birdImgRect.width)); |
791 digilib.params.set("wy", cropFloat((newRect.y - birdImgRect.y) / birdImgRect.height)); | |
416 | 792 // zoomed is always fit |
451 | 793 digilib.params.set("ws", 1); |
794 digilib.display(); | |
416 | 795 return stopEvent(evt); |
796 } | |
451 | 797 } |
416 | 798 |
451 | 799 Digilib.prototype.showArrow = function(name, rect, show) { |
429
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
800 var arrow = getElement(name); |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
801 moveElement(arrow, rect); |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
802 showElement(arrow, show); |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
803 } |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
804 |
451 | 805 Digilib.prototype.showArrows = function() { |
443 | 806 // show the 4 arrow bars on top of scaler img according to current dlArea |
451 | 807 var r = getElementRect(this.scalerImg); |
808 this.showArrow('up', | |
452 | 809 new Rectangle(r.x, r.y, r.width, this.ARROW_WIDTH), |
451 | 810 this.canMove(0, -1) |
429
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
811 ); |
451 | 812 this.showArrow('down', |
452 | 813 new Rectangle(r.x, r.y + r.height - this.ARROW_WIDTH, r.width, this.ARROW_WIDTH), |
451 | 814 this.canMove(0, 1) |
429
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
815 ); |
451 | 816 this.showArrow('left', |
452 | 817 new Rectangle(r.x, r.y, this.ARROW_WIDTH, r.height), |
451 | 818 this.canMove(-1, 0) |
429
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
819 ); |
451 | 820 this.showArrow('right', |
452 | 821 new Rectangle(r.x + r.width - this.ARROW_WIDTH, r.y, this.ARROW_WIDTH, r.height), |
451 | 822 this.canMove(1, 0) |
429
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
823 ); |
813a155d1338
added showArrows() function (navigation arrows overlay)
hertzhaft
parents:
416
diff
changeset
|
824 } |
416 | 825 |
451 | 826 Digilib.prototype.calibrate = function(direction) { |
434 | 827 // calibrate screen |
828 var startPos; // anchor for dragging | |
829 var newRect; // position after drag | |
830 var calDiv = getElement("calibration"); | |
439 | 831 var pixel = calDiv.getElementsByTagName("p")[0]; |
434 | 832 var overlay = getElement("overlay"); |
833 moveElement(overlay, getWinRect()); | |
834 showElement(overlay, true); | |
835 var xDir = direction == "x"; | |
836 moveCenter(false); | |
837 registerEvent("mousedown", document, calibrationStartDrag); | |
838 | |
839 function calibrationStartDrag(evt) { | |
840 // mousedown handler: start drag | |
841 startPos = evtPosition(evt); | |
842 unregisterEvent("mousedown", document, calibrationStartDrag); | |
843 registerEvent("mousemove", document, calibrationMove); | |
844 registerEvent("mouseup", document, calibrationEndDrag); | |
845 newRect = new Rectangle( | |
846 startPos.x, | |
847 startPos.y, | |
848 xDir ? 1 : CALIBRATION_WIDTH, | |
849 xDir ? CALIBRATION_WIDTH : 1 | |
850 ); | |
851 moveElement(calDiv, newRect); | |
852 showElement(calDiv, true); | |
853 // debugProps(getElementRect(bird)) | |
854 return stopEvent(evt); | |
855 } | |
856 | |
857 function calibrationMove(evt) { | |
858 // mousemove handler: drag | |
859 var pos = evtPosition(evt); | |
860 var dx = (xDir) ? pos.x - startPos.x : CALIBRATION_WIDTH; | |
861 var dy = (xDir) ? CALIBRATION_WIDTH : pos.y - startPos.y; | |
862 // move birdArea div, keeping size | |
863 newRect = new Rectangle(startPos.x, startPos.y, dx, dy); | |
439 | 864 pixel.innerHTML = (xDir ? dx : dy) + " px"; |
434 | 865 moveElement(calDiv, newRect); |
866 showElement(calDiv, true); | |
867 return stopEvent(evt); | |
868 } | |
869 | |
870 function calibrationEndDrag(evt) { | |
871 // mouseup handler: calibrate | |
872 unregisterEvent("mousemove", document, calibrationMove); | |
873 unregisterEvent("mouseup", document, calibrationEndDrag); | |
439 | 874 if (xDir) { |
875 var val = newRect.width * 0.254; // ratio dm/inch | |
876 cookie.add("ddpi", val); | |
877 cookie.add("ddpix", val); | |
878 } else { | |
879 var val = newRect.height * 0.254; | |
880 cookie.add("ddpiy", val); | |
881 } | |
434 | 882 showElement(calDiv, false); |
883 showElement(overlay, false); | |
884 moveCenter(true); | |
885 return stopEvent(evt); | |
886 } | |
887 } | |
888 | |
451 | 889 Digilib.prototype.originalSize = function(on) { |
443 | 890 // set osize flag, needs calibrated screen |
891 if (on) { | |
892 var dpi = cookie.get("ddpi"); | |
893 if (dpi == null) { | |
894 alert("Screen has not yet been calibrated - using default value of 72 dpi"); | |
895 dpi = 72; | |
896 } | |
451 | 897 this.params.set("ddpi", dpi); |
898 this.flags.set("osize"); | |
899 this.display(); | |
900 } else { | |
901 this.flags.reset("osize"); | |
902 } | |
439 | 903 } |
451 | 904 |
905 Digilib.prototype.pixelByPixel = function(on) { | |
443 | 906 // sets clip flag |
907 if (on) { | |
451 | 908 this.flags.set("clip"); |
909 this.display(); | |
443 | 910 } |
451 | 911 else this.flags.reset("clip"); |
439 | 912 } |
440 | 913 |
451 | 914 Digilib.prototype.pageWidth = function() { |
452 | 915 this.zoomFullpage('width'); |
445 | 916 } |
917 | |
451 | 918 Digilib.prototype.resize = function(factor) { |
919 this.params.set("ws", factor); | |
920 this.showSizeMenu(false); | |
921 this.display(); | |
440 | 922 } |
923 | |
451 | 924 Digilib.prototype.showSizeMenu = function(show) { |
440 | 925 var menu = getElement("sizes"); |
443 | 926 if (show) { |
927 // align menu with button | |
928 var buttonPos = getElementPosition(getElement("size")); | |
929 moveElement(menu, new Position(buttonPos.x - 50, buttonPos.y)); | |
930 } | |
931 showElement(menu, show); | |
440 | 932 } |
451 | 933 |
934 | |
935 /******************************** | |
936 * global variables | |
937 ********************************/ | |
938 | |
939 var dl = new Digilib(); | |
940 | |
941 /* old parameter function compatibility stuff */ | |
942 function newParameter(a,b,c) {return dl.params.define(a,b,c)}; | |
943 function resetParameter(a) {return dl.params.reset(a)}; | |
944 function deleteParameter(a) {return dl.params.remove(a)}; | |
945 function getParameter(a) {return dl.params.get(a)}; | |
946 function setParameter(a,b,c) {return dl.params.set(a,b,c)}; | |
947 function hasParameter(a) {return dl.params.isSet(a)}; | |
948 function getAllParameters(a) {return dl.params.getAll(a)}; | |
949 getQueryString = getAllParameters; | |
950 function parseParameters(a) {return dl.params.parse(a)}; | |
951 function getAllMarks() {return dl.marks.getAll()}; | |
952 getMarksQueryString = getAllMarks; | |
953 function addMark(evt) {return dl.marks.addEvent(evt)}; | |
954 function deleteMark() {return dl.marks.pop()}; | |
955 function deleteAllMarks() {return dl.marks = new Marks()}; | |
956 function hasFlag(mode) {return dl.flags.get(mode)}; | |
957 function addFlag(mode) {return dl.flags.set(mode)}; | |
958 function removeFlag(mode) {return dl.flags.reset(mode)}; | |
959 function toggleFlag(mode) {return dl.flags.toggle(mode)}; | |
960 function getAllFlags() {return dl.flags.getAll()}; | |
961 /* old digilib function compatibility */ | |
962 function setDLParam(e, s, relative) {dl.setDLParam(e, s, relative)}; | |
963 function display(detail, moDetail) {dl.display(detail, moDetail)}; | |
964 function setMark(reload) {dl.setMark(reload)}; | |
965 function removeMark(reload) {dl.removeMark(reload)}; | |
966 function zoomArea() {dl.zoomArea()}; | |
967 function zoomBy(factor) {dl.zoomBy(factor)}; | |
968 function zoomFullpage() {dl.zoomFullpage()}; | |
969 function moveCenter(on) {dl.moveCenter(on)}; | |
970 function isFullArea(area) {dl.isFullArea(area)}; | |
971 function canMove(movx, movy) {dl.canMove(movx, movy)}; | |
972 function moveBy(movx, movy) {dl.moveBy(movx, movy)}; | |
973 function getRef(baseURL) {dl.getRef(baseURL)}; | |
974 function getRefWin(type, msg) {dl.getRefWin(type, msg)}; | |
975 function getQuality() {dl.getQuality()}; | |
976 function setQuality(qual) {dl.setQuality(qual)}; | |
977 function setQualityWin(msg) {dl.setQualityWin(msg)}; | |
978 function mirror(dir) {dl.mirror(dir)}; | |
979 function gotoPage(gopage, keep) {dl.gotoPage(gopage, keep)}; | |
980 function gotoPageWin() {dl.gotoPageWin()}; | |
981 function setParamWin(param, text, relative) {dl.setParamWin(param, text, relative)}; | |
982 function showOptions(show) {dl.showOptions(show)}; | |
983 function showBirdDiv(show) {dl.showBirdDiv(show)}; | |
984 function showAboutDiv(show) {dl.showAboutDiv(show)}; | |
985 function calibrate(direction) {dl.calibrate(direction)}; | |
986 function originalSize(on) {dl.originalSize(on)}; | |
987 function pixelByPixel(on) {dl.pixelByPixel(on)}; | |
988 function pageWidth() {dl.pageWidth()}; | |
989 function resize(factor) {dl.resize(factor)}; | |
990 function showSizeMenu(show) {dl.showSizeMenu(show)}; | |
991 | |
992 | |
434 | 993 // :tabSize=4:indentSize=4:noTabs=true: |
994 |