Mercurial > hg > digilib-old
annotate client/digitallibrary/jquery/jquery.digilib.js @ 712:823f0050f7eb jquery
'reset' should reset fitwidth/fitheight, too
author | hertzhaft |
---|---|
date | Sun, 30 Jan 2011 16:38:54 +0100 |
parents | eab17859be79 |
children | 667a316edb89 |
rev | line source |
---|---|
604 | 1 /* |
2 * digilib jQuery plugin | |
3 * | |
4 */ | |
655 | 5 |
636 | 6 // fallback for console.log calls |
7 if (typeof(console) === 'undefined') { | |
8 var console = { | |
692 | 9 log : function(){}, |
10 debug : function(){}, | |
11 error : function(){} | |
12 }; | |
13 var customConsole = true; | |
14 }; | |
604 | 15 |
16 (function($) { | |
651
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
17 var buttons = { |
610 | 18 reference : { |
689 | 19 onclick : "reference", |
610 | 20 tooltip : "get a reference URL", |
21 img : "reference.png" | |
22 }, | |
23 zoomin : { | |
643 | 24 onclick : ["zoomBy", 1.4], |
610 | 25 tooltip : "zoom in", |
26 img : "zoom-in.png" | |
27 }, | |
28 zoomout : { | |
643 | 29 onclick : ["zoomBy", 0.7], |
610 | 30 tooltip : "zoom out", |
31 img : "zoom-out.png" | |
32 }, | |
33 zoomarea : { | |
654 | 34 onclick : "zoomArea", |
610 | 35 tooltip : "zoom area", |
36 img : "zoom-area.png" | |
37 }, | |
38 zoomfull : { | |
650 | 39 onclick : "zoomFull", |
610 | 40 tooltip : "view the whole image", |
41 img : "zoom-full.png" | |
42 }, | |
43 pagewidth : { | |
650 | 44 onclick : ["zoomFull", "width"], |
610 | 45 tooltip : "page width", |
46 img : "pagewidth.png" | |
47 }, | |
48 back : { | |
623 | 49 onclick : ["gotoPage", "-1"], |
610 | 50 tooltip : "goto previous image", |
51 img : "back.png" | |
52 }, | |
53 fwd : { | |
623 | 54 onclick : ["gotoPage", "+1"], |
610 | 55 tooltip : "goto next image", |
56 img : "fwd.png" | |
57 }, | |
58 page : { | |
59 onclick : "javascript:gotoPageWin()", | |
60 tooltip : "specify image", | |
61 img : "page.png" | |
62 }, | |
63 bird : { | |
635 | 64 onclick : "showBirdDiv", |
610 | 65 tooltip : "show bird's eye view", |
66 img : "birds-eye.png" | |
67 }, | |
68 help : { | |
635 | 69 onclick : "showAboutDiv", |
610 | 70 tooltip : "about Digilib", |
71 img : "help.png" | |
72 }, | |
73 reset : { | |
688 | 74 onclick : "reset", |
610 | 75 tooltip : "reset image", |
76 img : "reset.png" | |
77 }, | |
78 mark : { | |
647 | 79 onclick : "setMark", |
610 | 80 tooltip : "set a mark", |
81 img : "mark.png" | |
82 }, | |
83 delmark : { | |
650 | 84 onclick : "removeMark", |
610 | 85 tooltip : "delete the last mark", |
86 img : "delmark.png" | |
87 }, | |
88 hmir : { | |
661 | 89 onclick : ["mirror", "h"], |
610 | 90 tooltip : "mirror horizontally", |
91 img : "mirror-horizontal.png" | |
92 }, | |
93 vmir : { | |
661 | 94 onclick : ["mirror", "v"], |
610 | 95 tooltip : "mirror vertically", |
96 img : "mirror-vertical.png" | |
97 }, | |
98 rot : { | |
663 | 99 onclick : "rotate", |
610 | 100 tooltip : "rotate image", |
101 img : "rotate.png" | |
102 }, | |
103 brgt : { | |
663 | 104 onclick : "brightness", |
610 | 105 tooltip : "set brightness", |
106 img : "brightness.png" | |
107 }, | |
108 cont : { | |
663 | 109 onclick : "contrast", |
610 | 110 tooltip : "set contrast", |
111 img : "contrast.png" | |
112 }, | |
113 rgb : { | |
114 onclick : "javascript:setParamWin('rgb', '...')", | |
115 tooltip : "set rgb values", | |
116 img : "rgb.png" | |
117 }, | |
118 quality : { | |
703 | 119 onclick : "setquality", |
610 | 120 tooltip : "set image quality", |
121 img : "quality.png" | |
122 }, | |
123 size : { | |
124 onclick : "javascript:toggleSizeMenu()", | |
125 tooltip : "set page size", | |
126 img : "size.png" | |
127 }, | |
128 calibrationx : { | |
129 onclick : "javascript:calibrate('x')", | |
130 tooltip : "calibrate screen x-ratio", | |
131 img : "calibration-x.png" | |
132 }, | |
133 scale : { | |
134 onclick : "javascript:toggleScaleMenu()", | |
135 tooltip : "change image scale", | |
136 img : "original-size.png" | |
137 }, | |
699 | 138 toggleoptions : { |
139 onclick : "morebuttons", | |
140 tooltip : "more options", | |
141 img : "options.png" | |
142 }, | |
690 | 143 moreoptions : { |
144 onclick : ["morebuttons", "+1"], | |
145 tooltip : "more options", | |
146 img : "options.png" | |
147 }, | |
148 lessoptions : { | |
149 onclick : ["morebuttons", "-1"], | |
150 tooltip : "less options", | |
610 | 151 img : "options.png" |
152 }, | |
153 SEP : { | |
154 img : "sep.png" | |
155 } | |
156 }; | |
617
cd846b5c8be8
toggle view event handlers for bird's eye and 'about windows
hertzhaft
parents:
616
diff
changeset
|
157 |
605 | 158 var defaults = { |
616 | 159 // version of this script |
635 | 160 'version' : 'jquery.digilib.js 0.9', |
616 | 161 // logo url |
162 'logoUrl' : '../img/digilib-logo-text1.png', | |
635 | 163 // homepage url (behind logo) |
164 'homeUrl' : 'http://digilib.berlios.de', | |
610 | 165 // base URL to Scaler servlet |
652 | 166 'scalerBaseUrl' : null, |
610 | 167 // list of Scaler parameters |
627 | 168 'scalerParamNames' : ['fn','pn','dw','dh','ww','wh','wx','wy','ws','mo', |
169 'rot','cont','brgt','rgbm','rgba','ddpi','ddpix','ddpiy'], | |
170 // Scaler parameter defaults | |
643 | 171 'pn' : 1, |
627 | 172 'ww' : 1.0, |
173 'wh' : 1.0, | |
174 'wx' : 0.0, | |
175 'wy' : 0.0, | |
176 'ws' : 1.0, | |
643 | 177 'mo' : '', |
178 'rot' : 0, | |
179 'cont' : 0, | |
180 'brgt' : 0, | |
181 'rgbm' : '0/0/0', | |
182 'rgba' : '0/0/0', | |
183 'ddpi' : null, | |
184 'ddpix' : null, | |
185 'ddpiy' : null, | |
644
ee8ccd84c5f8
reload doesn't take list of changed parameters any more
robcast
parents:
643
diff
changeset
|
186 // list of digilib parameters |
650 | 187 'digilibParamNames' : ['fn','pn','ww','wh','wx','wy','ws','mo','rot','cont','brgt','rgbm','rgba','mk','clop'], |
644
ee8ccd84c5f8
reload doesn't take list of changed parameters any more
robcast
parents:
643
diff
changeset
|
188 // digilib parameter defaults |
643 | 189 'mk' : '', |
650 | 190 'clop' : '', |
643 | 191 // mode of operation: |
192 // fullscreen = take parameters from page URL, keep state in page URL | |
193 // embedded = take parameters from Javascript options, keep state inside object | |
610 | 194 'interactionMode' : 'fullscreen', |
651
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
195 // buttons |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
196 'buttons' : buttons, |
668 | 197 // defaults for digilib buttons |
665 | 198 'buttonSettings' : { |
199 'fullscreen' : { | |
668 | 200 // path to button images (must end with a slash) |
665 | 201 'imagePath' : 'img/fullscreen/', |
699 | 202 'standardSet' : ["reference","zoomin","zoomout","zoomarea","zoomfull","pagewidth","back","fwd","page","bird","SEP","help","reset","toggleoptions"], |
203 'specialSet' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","size","calibrationx","scale","SEP","toggleoptions"], | |
682 | 204 'buttonSets' : ['standardSet', 'specialSet'] |
665 | 205 }, |
206 'embedded' : { | |
207 'imagePath' : 'img/embedded/16/', | |
699 | 208 'standardSet' : ["reference","zoomin","zoomout","zoomarea","zoomfull","back","fwd","page","bird","SEP","help","reset","toggleoptions"], |
209 'specialSet' : ["hmir","vmir","rot","brgt","cont","rgb","quality","size","SEP","toggleoptions"], | |
682 | 210 'buttonSets' : ['standardSet', 'specialSet'] |
665 | 211 } |
697 | 212 }, |
213 // number of visible button groups | |
214 'visibleButtonSets' : 1, | |
616 | 215 // is birdView shown? |
216 'isBirdDivVisible' : false, | |
668 | 217 // dimensions of bird's eye div |
674 | 218 'birdDivWidth' : 200, |
219 'birdDivHeight' : 200, | |
668 | 220 // style of the zoom area indicator in the bird's eye div |
659 | 221 'birdIndicatorStyle' : {'border' : '2px solid #ff0000' }, |
668 | 222 // style of zoom area "rubber band" |
223 'zoomrectStyle' : {'border' : '2px solid #ff0000' }, | |
616 | 224 // is the "about" window shown? |
225 'isAboutDivVisible' : false | |
226 | |
610 | 227 }; |
655 | 228 |
608 | 229 // affine geometry classes |
230 var geom = dlGeometry(); | |
655 | 231 |
643 | 232 var MAX_ZOOMAREA = geom.rectangle(0, 0, 1, 1); |
655 | 233 |
651
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
234 var actions = { |
668 | 235 // init: digilib initialization |
236 init : function(options) { | |
237 // settings for this digilib instance are merged from defaults and options | |
238 var settings = $.extend({}, defaults, options); | |
239 var isFullscreen = settings.interactionMode === 'fullscreen'; | |
240 var queryParams = {}; | |
241 if (isFullscreen) { | |
242 queryParams = parseQueryParams(); | |
243 // check scalerBaseUrl | |
244 if (settings.scalerBaseUrl == null) { | |
245 // try the host this came from | |
246 var h = window.location.host; | |
247 if (window.location.host) { | |
248 var url = window.location.href; | |
249 // assume the page lives in [webapp]/jquery/ | |
250 var pos = url.indexOf('jquery/'); | |
251 if (pos > 0) { | |
252 settings.scalerBaseUrl = url.substring(0, pos) + 'servlet/Scaler'; | |
652 | 253 } |
254 } | |
636 | 255 } |
668 | 256 } |
257 return this.each(function() { | |
258 var $elem = $(this); | |
259 var data = $elem.data('digilib'); | |
688 | 260 var params, elemSettings; |
668 | 261 // if the plugin hasn't been initialized yet |
262 if (!data) { | |
263 // merge query parameters | |
264 if (isFullscreen) { | |
688 | 265 params = queryParams; |
668 | 266 } else { |
688 | 267 params = parseImgParams($elem); |
268 }; | |
668 | 269 // store $(this) element in the settings |
688 | 270 elemSettings = $.extend({}, settings, params); |
697 | 271 data = { |
668 | 272 $elem : $elem, |
273 settings : elemSettings, | |
688 | 274 queryParams : params |
668 | 275 }; |
276 // store in data element | |
277 $elem.data('digilib', data); | |
278 } | |
279 unpackParams(data); | |
682 | 280 // create HTML structure for scaler |
668 | 281 setupScalerDiv(data); |
697 | 282 // add buttons |
283 for (var i = 0; i < elemSettings.visibleButtonSets; ++i) { | |
284 showButtons(data, true, i); | |
710 | 285 }; |
668 | 286 // bird's eye view creation |
710 | 287 if (elemSettings.isBirdDivVisible) { |
638 | 288 setupBirdDiv(data); |
710 | 289 }; |
668 | 290 // about window creation - TODO: could be deferred? restrict to only one item? |
291 setupAboutDiv(data); | |
710 | 292 // TODO: the actual moving code |
707 | 293 setupZoomDrag(data); |
668 | 294 }); |
295 }, | |
296 | |
297 // destroy: clean up digilib | |
298 destroy : function(data) { | |
299 return this.each(function(){ | |
300 var $elem = $(this); | |
301 $(window).unbind('.digilib'); // unbind all digilibs(?) | |
302 data.digilib.remove(); | |
303 $elem.removeData('digilib'); | |
304 }); | |
305 }, | |
306 | |
307 // show or hide the 'about' window | |
308 showAboutDiv : function(data, show) { | |
309 data.settings.isAboutDivVisible = showDiv(data.settings.isAboutDivVisible, data.$aboutDiv, show); | |
310 }, | |
655 | 311 |
668 | 312 // event handler: toggles the visibility of the bird's eye window |
313 showBirdDiv : function (data, show) { | |
314 if (data.$birdDiv == null) { | |
315 // no bird div -> create | |
316 setupBirdDiv(data); | |
317 } | |
318 data.settings.isBirdDivVisible = showDiv(data.settings.isBirdDivVisible, data.$birdDiv, show); | |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
319 data.$birdImg.triggerHandler('load'); |
668 | 320 }, |
321 | |
322 // goto given page nr (+/-: relative) | |
323 gotoPage : function (data, pageNr) { | |
324 var settings = data.settings; | |
325 var oldpn = settings.pn; | |
326 var pn = setNumValue(settings, "pn", pageNr); | |
327 if (pn == null) return false; // nothing happened | |
328 if (pn < 1) { | |
329 alert("no such page (page number too low)"); | |
330 settings.pn = oldpn; | |
331 return false; | |
332 } | |
333 if (settings.pt) { | |
334 if (pn > settings.pt) { | |
335 alert("no such page (page number too high)"); | |
623 | 336 settings.pn = oldpn; |
337 return false; | |
634 | 338 } |
668 | 339 } |
340 // reset mk and others(?) | |
341 data.marks = []; | |
342 data.zoomArea = MAX_ZOOMAREA; | |
343 // then reload | |
344 redisplay(data); | |
345 }, | |
654 | 346 |
668 | 347 // zoom by a given factor |
348 zoomBy : function (data, factor) { | |
349 zoomBy(data, factor); | |
350 }, | |
647 | 351 |
668 | 352 // zoom interactively |
353 zoomArea : function (data) { | |
354 zoomArea(data); | |
355 }, | |
650 | 356 |
668 | 357 // zoom out to full page |
358 zoomFull : function (data, mode) { | |
359 data.zoomArea = MAX_ZOOMAREA; | |
360 if (mode === 'width') { | |
361 data.dlOpts.fitwidth = 1; | |
362 delete data.dlOpts.fitheight; | |
363 } else if (mode === 'height') { | |
364 data.dlOpts.fitheight = 1; | |
365 delete data.dlOpts.fitwidth; | |
366 } else { | |
367 delete data.dlOpts.fitwidth; | |
368 delete data.dlOpts.fitheight; | |
369 } | |
370 redisplay(data); | |
371 }, | |
372 | |
373 // set a mark by clicking (or giving a position) | |
374 setMark : function (data, mpos) { | |
375 if (mpos == null) { | |
376 // interactive | |
377 setMark(data); | |
378 } else { | |
379 // use position | |
380 data.marks.push(pos); | |
663 | 381 redisplay(data); |
604 | 382 } |
668 | 383 }, |
384 | |
385 // remove the last mark | |
386 removeMark : function (data) { | |
387 data.marks.pop(); | |
388 redisplay(data); | |
389 }, | |
390 | |
391 // mirror the image | |
392 mirror : function (data, mode) { | |
393 var flags = data.scalerFlags; | |
394 if (mode === 'h') { | |
395 if (flags.hmir) { | |
396 delete flags.hmir; | |
397 } else { | |
398 flags.hmir = 1; | |
399 } | |
400 } else { | |
401 if (flags.vmir) { | |
402 delete flags.vmir; | |
403 } else { | |
404 flags.vmir = 1; | |
405 } | |
406 } | |
407 redisplay(data); | |
408 }, | |
650 | 409 |
668 | 410 // rotate the image |
411 rotate : function (data, angle) { | |
412 var rot = data.settings.rot; | |
413 if (angle == null) { | |
414 angle = window.prompt("Rotation angle:", rot); | |
415 } | |
416 data.settings.rot = angle; | |
417 redisplay(data); | |
418 }, | |
419 | |
420 // change brightness | |
421 brightness : function (data, factor) { | |
422 var brgt = data.settings.brgt; | |
423 if (factor == null) { | |
424 factor = window.prompt("Brightness (-255..255)", brgt); | |
425 } | |
426 data.settings.brgt = factor; | |
427 redisplay(data); | |
428 }, | |
429 | |
430 // change contrast | |
431 contrast : function (data, factor) { | |
432 var cont = data.settings.cont; | |
433 if (factor == null) { | |
434 factor = window.prompt("Contrast (-8, 8)", cont); | |
435 } | |
436 data.settings.cont = factor; | |
437 redisplay(data); | |
688 | 438 }, |
710 | 439 |
690 | 440 // display more (or less) button sets |
441 morebuttons : function (data, more) { | |
696 | 442 var settings = data.settings; |
699 | 443 if (more == null) { |
703 | 444 // toggle more or less (only works for 2 sets) |
699 | 445 var maxbtns = settings.buttonSettings[settings.interactionMode].buttonSets.length; |
446 if (settings.visibleButtonSets >= maxbtns) { | |
447 more = '-1'; | |
448 } else { | |
449 more = '+1'; | |
450 } | |
451 } | |
690 | 452 if (more === '-1') { |
453 // remove set | |
697 | 454 var setIdx = settings.visibleButtonSets - 1; |
455 if (showButtons(data, false, setIdx, true)) { | |
456 settings.visibleButtonSets--; | |
457 } | |
690 | 458 } else { |
459 // add set | |
697 | 460 var setIdx = settings.visibleButtonSets; |
461 if (showButtons(data, true, setIdx, true)) { | |
462 settings.visibleButtonSets++; | |
690 | 463 } |
464 } | |
691 | 465 }, |
688 | 466 |
703 | 467 // reset image parameters to defaults |
688 | 468 reset : function (data) { |
469 var settings = data.settings; | |
470 var paramNames = settings.digilibParamNames; | |
471 var params = data.queryParams; | |
709 | 472 // resets zoomArea, marks, scalerflags |
688 | 473 resetData(data); |
474 // delete all digilib parameters | |
475 for (var i = 0; i < paramNames.length; i++) { | |
476 var paramName = paramNames[i]; | |
477 delete settings[paramName]; | |
478 }; | |
479 // fullscreen: restore only fn/pn parameters | |
480 if (settings.interactionMode === 'fullscreen') { | |
709 | 481 settings['fn'] = params.fn || ''; // no default defined |
482 settings['pn'] = params.pn || defaults.pn; | |
688 | 483 // embedded: restore original parameters |
484 } else { | |
485 $.extend(settings, params); | |
486 }; | |
709 | 487 // TODO: should we really reset all user preferences here? |
488 settings.isBirdDivVisible = false; | |
489 settings.visibleButtonSets = 1; | |
712 | 490 delete data.dlOpts.fitwidth; |
491 delete data.dlOpts.fitheight; | |
688 | 492 redisplay(data); |
689 | 493 }, |
494 | |
703 | 495 // presents a reference url (returns value if noprompt) |
496 reference : function (data, noprompt) { | |
689 | 497 var settings = data.settings; |
498 var url; | |
499 if (settings.interactionMode === 'fullscreen') { | |
500 url = getDigilibUrl(data); | |
501 } else { | |
502 url = getScalerUrl(data); | |
503 }; | |
703 | 504 if (noprompt == null) { |
505 window.prompt("URL reference to the current view", url); | |
506 } | |
507 return url; | |
508 }, | |
710 | 509 |
703 | 510 // set image quality |
511 setquality : function (data, qual) { | |
512 var oldq = getQuality(data); | |
513 if (qual == null) { | |
514 qual = window.prompt("Image quality (0..2)", oldq); | |
515 } | |
516 qual = parseInt(qual, 10); | |
517 if (qual >= 0 && qual <= 2) { | |
518 setQuality(data, qual); | |
519 redisplay(data); | |
520 } | |
668 | 521 } |
605 | 522 }; |
604 | 523 |
608 | 524 // returns parameters from page url |
607 | 525 var parseQueryParams = function() { |
636 | 526 return parseQueryString(window.location.search.slice(1)); |
527 }; | |
655 | 528 |
636 | 529 // returns parameters from embedded img-element |
607 | 530 var parseImgParams = function($elem) { |
613
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
531 var src = $elem.find('img').first().attr('src'); |
710 | 532 if (!src) return null; |
607 | 533 var pos = src.indexOf('?'); |
534 var query = (pos < 0) ? '' : src.substring(pos + 1); | |
535 var scalerUrl = src.substring(0, pos); | |
627 | 536 var params = parseQueryString(query); |
537 params.scalerBaseUrl = scalerUrl; | |
538 return params; | |
636 | 539 }; |
607 | 540 |
608 | 541 // parses query parameter string into parameter object |
607 | 542 var parseQueryString = function(query) { |
701 | 543 var params = {}; |
544 if (query == null) return params; | |
607 | 545 var pairs = query.split("&"); |
636 | 546 //var keys = []; |
607 | 547 for (var i = 0; i < pairs.length; i++) { |
548 var pair = pairs[i].split("="); | |
549 if (pair.length === 2) { | |
627 | 550 params[pair[0]] = pair[1]; |
636 | 551 //keys.push(pair[0]); |
634 | 552 } |
636 | 553 } |
627 | 554 return params; |
636 | 555 }; |
668 | 556 |
643 | 557 // returns a query string from key names from a parameter hash (ignoring if the same value is in defaults) |
558 var getParamString = function (settings, keys, defaults) { | |
615 | 559 var paramString = ''; |
650 | 560 var nx = false; |
615 | 561 for (i = 0; i < keys.length; ++i) { |
562 var key = keys[i]; | |
663 | 563 if ((settings[key] != null) && ((defaults == null) || (settings[key] != defaults[key]))) { |
615 | 564 // first param gets no '&' |
650 | 565 if (nx) { |
566 paramString += '&'; | |
567 } else { | |
568 nx = true; | |
569 } | |
615 | 570 // add parm=val |
571 paramString += key + '=' + settings[key]; | |
643 | 572 } |
615 | 573 } |
574 return paramString; | |
631 | 575 }; |
576 | |
636 | 577 // returns URL and query string for Scaler |
578 var getScalerUrl = function (data) { | |
653 | 579 var settings = data.settings; |
652 | 580 if (settings.scalerBaseUrl == null) { |
581 alert("ERROR: URL of digilib Scaler servlet missing!"); | |
710 | 582 }; |
665 | 583 packParams(data); |
636 | 584 var keys = settings.scalerParamNames; |
643 | 585 var queryString = getParamString(settings, keys, defaults); |
636 | 586 var url = settings.scalerBaseUrl + '?' + queryString; |
587 return url; | |
588 }; | |
589 | |
590 // returns URL and query string for current digilib | |
644
ee8ccd84c5f8
reload doesn't take list of changed parameters any more
robcast
parents:
643
diff
changeset
|
591 var getDigilibUrl = function (data) { |
643 | 592 packParams(data); |
636 | 593 var settings = data.settings; |
644
ee8ccd84c5f8
reload doesn't take list of changed parameters any more
robcast
parents:
643
diff
changeset
|
594 var queryString = getParamString(settings, settings.digilibParamNames, defaults); |
636 | 595 var url = window.location.toString(); |
596 var pos = url.indexOf('?'); | |
597 var baseUrl = url.substring(0, pos); | |
598 var newurl = baseUrl + '?' + queryString; | |
599 return newurl; | |
600 }; | |
601 | |
655 | 602 // processes some parameters into objects and stuff |
631 | 603 var unpackParams = function (data) { |
604 var settings = data.settings; | |
636 | 605 // zoom area |
631 | 606 var zoomArea = geom.rectangle(settings.wx, settings.wy, settings.ww, settings.wh); |
643 | 607 data.zoomArea = zoomArea; |
636 | 608 // marks |
631 | 609 var marks = []; |
650 | 610 if (settings.mk) { |
611 var mk = settings.mk; | |
612 if (mk.indexOf(";") >= 0) { | |
613 var pa = mk.split(";"); // old format with ";" | |
614 } else { | |
615 var pa = mk.split(","); // new format | |
710 | 616 }; |
650 | 617 for (var i = 0; i < pa.length ; i++) { |
618 var pos = pa[i].split("/"); | |
619 if (pos.length > 1) { | |
620 marks.push(geom.position(pos[0], pos[1])); | |
710 | 621 }; |
622 }; | |
623 }; | |
643 | 624 data.marks = marks; |
650 | 625 // mo (Scaler flags) |
626 var flags = {}; | |
627 if (settings.mo) { | |
628 var pa = settings.mo.split(","); | |
629 for (var i = 0; i < pa.length ; i++) { | |
630 flags[pa[i]] = pa[i]; | |
710 | 631 }; |
632 }; | |
650 | 633 data.scalerFlags = flags; |
709 | 634 retrieveOptionsCookie(data); |
655 | 635 }; |
636 | |
631 | 637 // put objects back into parameters |
638 var packParams = function (data) { | |
639 var settings = data.settings; | |
636 | 640 // zoom area |
643 | 641 if (data.zoomArea) { |
647 | 642 settings.wx = cropFloat(data.zoomArea.x); |
643 settings.wy = cropFloat(data.zoomArea.y); | |
644 settings.ww = cropFloat(data.zoomArea.width); | |
645 settings.wh = cropFloat(data.zoomArea.height); | |
710 | 646 }; |
636 | 647 // marks |
643 | 648 if (data.marks) { |
650 | 649 settings.mk = ''; |
643 | 650 for (var i = 0; i < data.marks.length; i++) { |
650 | 651 if (i) { |
652 settings.mk += ','; | |
710 | 653 }; |
654 settings.mk | |
655 += cropFloat(data.marks[i].x).toString() + '/' | |
656 + cropFloat(data.marks[i].y).toString(); | |
657 }; | |
658 }; | |
650 | 659 // Scaler flags |
660 if (data.scalerFlags) { | |
661 var mo = ''; | |
662 for (var f in data.scalerFlags) { | |
663 if (mo) { | |
664 mo += ','; | |
665 } | |
666 mo += f; | |
667 } | |
668 settings.mo = mo; | |
669 } | |
710 | 670 // user interface options |
709 | 671 storeOptionsCookie(data); |
672 }; | |
688 | 673 |
709 | 674 var storeOptionsCookie = function (data) { |
701 | 675 // save digilib options in cookie |
709 | 676 // TODO: in embedded mode this is not called |
701 | 677 /* store in parameter clop |
678 * if (data.dlOpts) { | |
679 var clop = ''; | |
680 for (var o in data.dlOpts) { | |
681 if (clop) { | |
650 | 682 clop += ','; |
683 } | |
684 clop += o; | |
685 } | |
686 settings.clop = clop; | |
701 | 687 } */ |
709 | 688 var settings = data.settings; |
689 if (data.dlOpts) { | |
690 // save digilib settings in options | |
691 data.dlOpts.birdview = settings.isBirdDivVisible ? 1 : 0; | |
692 data.dlOpts.buttons = settings.visibleButtonSets; | |
693 var clop = ''; | |
694 for (var o in data.dlOpts) { | |
695 if (clop) { | |
696 clop += '&'; | |
710 | 697 }; |
709 | 698 clop += o + '=' + data.dlOpts[o]; |
710 | 699 }; |
709 | 700 if (jQuery.cookie) { |
701 var ck = "digilib:fn:" + escape(settings.fn) + ":pn:" + settings.pn; | |
702 console.debug("set cookie=", ck, " value=", clop); | |
703 jQuery.cookie(ck, clop); | |
704 }; | |
705 }; | |
631 | 706 }; |
655 | 707 |
709 | 708 var retrieveOptionsCookie = function (data) { |
709 // clop (digilib options) | |
710 var opts = {}; | |
711 var settings = data.settings; | |
712 if (jQuery.cookie) { | |
713 /* read from parameter clop | |
714 * if (settings.clop) { | |
715 var pa = settings.clop.split(","); | |
716 for (var i = 0; i < pa.length ; i++) { | |
717 opts[pa[i]] = pa[i]; | |
718 } | |
719 } */ | |
720 // read from cookie | |
721 var ck = "digilib:fn:" + escape(settings.fn) + ":pn:" + settings.pn; | |
722 var cp = jQuery.cookie(ck); | |
723 console.debug("get cookie=", ck, " value=", cp); | |
724 // in query string format | |
725 opts = parseQueryString(cp); | |
726 }; | |
727 data.dlOpts = opts; | |
728 // birdview option | |
729 if (opts.birdview != null) { | |
730 settings.isBirdDivVisible = opts.birdview === '1'; | |
731 }; | |
732 // visible button sets | |
733 if (opts.buttons != null) { | |
734 settings.visibleButtonSets = opts.buttons; | |
735 }; | |
711 | 736 }; |
709 | 737 |
688 | 738 // clear digilib data for reset |
739 var resetData = function (data) { | |
740 if (data.zoomArea) delete data.zoomArea; | |
741 if (data.marks) delete data.marks; | |
742 if (data.scalerFlags) delete data.scalerFlags; | |
743 }; | |
744 | |
622 | 745 // (re)load the img from a new scaler URL |
644
ee8ccd84c5f8
reload doesn't take list of changed parameters any more
robcast
parents:
643
diff
changeset
|
746 var redisplay = function (data) { |
636 | 747 var settings = data.settings; |
748 if (settings.interactionMode === 'fullscreen') { | |
749 // update location.href (browser URL) in fullscreen mode | |
644
ee8ccd84c5f8
reload doesn't take list of changed parameters any more
robcast
parents:
643
diff
changeset
|
750 var url = getDigilibUrl(data); |
636 | 751 var history = window.history; |
752 if (typeof(history.pushState) === 'function') { | |
753 console.debug("we could modify history, but we don't..."); | |
710 | 754 }; |
636 | 755 window.location = url; |
756 } else { | |
757 // embedded mode -- just change img src | |
758 var url = getScalerUrl(data); | |
759 data.$img.attr('src', url); | |
710 | 760 }; |
622 | 761 }; |
762 | |
662 | 763 // returns maximum size for scaler img in fullscreen mode |
764 var getFullscreenImgSize = function($elem) { | |
765 var $win = $(window); | |
766 var winH = $win.height(); | |
767 var winW = $win.width(); | |
768 // TODO: account for borders? | |
769 return geom.size(winW, winH); | |
770 }; | |
771 | |
608 | 772 // creates HTML structure for digilib in elem |
627 | 773 var setupScalerDiv = function (data) { |
774 var settings = data.settings; | |
647 | 775 var $elem = data.$elem; |
686 | 776 var $img, scalerUrl; |
777 // fullscreen | |
608 | 778 if (settings.interactionMode === 'fullscreen') { |
609 | 779 var imgSize = getFullscreenImgSize($elem); |
650 | 780 // fitwidth/height omits destination height/width |
712 | 781 if (data.dlOpts['fitheight'] !== '1') { |
650 | 782 settings.dw = imgSize.width; |
686 | 783 }; |
712 | 784 if (data.dlOpts['fitwidth'] !== '1') { |
650 | 785 settings.dh = imgSize.height; |
686 | 786 }; |
613
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
787 $img = $('<img/>'); |
686 | 788 scalerUrl = getScalerUrl(data); |
789 // embedded mode -- try to keep img tag | |
609 | 790 } else { |
623 | 791 $img = $elem.find('img'); |
613
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
792 if ($img.length > 0) { |
686 | 793 console.debug("img detach:", $img); |
794 scalerUrl = $img.attr('src'); | |
613
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
795 $img.detach(); |
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
796 } else { |
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
797 $img = $('<img/>'); |
686 | 798 scalerUrl = getScalerUrl(data); |
799 }; | |
608 | 800 } |
613
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
801 // create new html |
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
802 $elem.empty(); // TODO: should we keep stuff for customization? |
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
803 var $scaler = $('<div class="scaler"/>'); |
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
804 $elem.append($scaler); |
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
805 $scaler.append($img); |
622 | 806 $img.addClass('pic'); |
649 | 807 data.$scaler = $scaler; |
636 | 808 data.$img = $img; |
687 | 809 // setup image load handler before setting the src attribute (IE bug) |
810 $img.load(scalerImgLoadedHandler(data)); | |
811 $img.attr('src', scalerUrl); | |
608 | 812 }; |
615 | 813 |
610 | 814 // creates HTML structure for buttons in elem |
697 | 815 var createButtons = function (data, buttonSetIdx) { |
647 | 816 var $elem = data.$elem; |
628
1f077f8afc5e
changed methods to pass "data" around instead of "settings"
robcast
parents:
627
diff
changeset
|
817 var settings = data.settings; |
665 | 818 var mode = settings.interactionMode; |
672
7f7536a5b6d9
image transform works now under rotation!!! (at least for multiples of 90deg)
robcast
parents:
671
diff
changeset
|
819 var buttonSettings = settings.buttonSettings[mode]; |
682 | 820 var buttonGroup = buttonSettings.buttonSets[buttonSetIdx]; |
690 | 821 if (buttonGroup == null) { |
822 // no buttons here | |
823 return; | |
824 } | |
825 var $buttonsDiv = $('<div class="buttons"/>'); | |
682 | 826 var buttonNames = buttonSettings[buttonGroup]; |
827 for (var i = 0; i < buttonNames.length; i++) { | |
828 var buttonName = buttonNames[i]; | |
829 var buttonConfig = settings.buttons[buttonName]; | |
665 | 830 // construct the button html |
831 var $button = $('<div class="button"></div>'); | |
832 var $a = $('<a/>'); | |
833 var $img = $('<img class="button"/>'); | |
834 $buttonsDiv.append($button); | |
835 $button.append($a); | |
836 $a.append($img); | |
837 // add attributes and bindings | |
838 $button.attr('title', buttonConfig.tooltip); | |
682 | 839 $button.addClass('button-' + buttonName); |
665 | 840 // create handler for the buttons |
841 $a.bind('click.digilib', (function () { | |
842 // we create a new closure to capture the value of action | |
843 var action = buttonConfig.onclick; | |
844 if ($.isArray(action)) { | |
845 // the handler function calls digilib with action and parameters | |
846 return function (evt) { | |
847 console.debug('click action=', action, ' evt=', evt); | |
848 $elem.digilib.apply($elem, action); | |
849 return false; | |
850 }; | |
851 } else { | |
852 // the handler function calls digilib with action | |
853 return function (evt) { | |
854 console.debug('click action=', action, ' evt=', evt); | |
855 $elem.digilib(action); | |
856 return false; | |
857 }; | |
858 } | |
859 })()); | |
860 $img.attr('src', buttonSettings.imagePath + buttonConfig.img); | |
690 | 861 } |
662 | 862 // make buttons div scroll if too large for window |
863 if ($buttonsDiv.height() > $(window).height() - 10) { | |
864 $buttonsDiv.css('position', 'absolute'); | |
865 } | |
697 | 866 // buttons hidden at first |
867 $buttonsDiv.hide(); | |
868 $elem.append($buttonsDiv); | |
682 | 869 if (data.$buttonSets == null) { |
697 | 870 // first button set |
682 | 871 data.$buttonSets = [$buttonsDiv]; |
872 } else { | |
690 | 873 $elem.append($buttonsDiv); |
682 | 874 data.$buttonSets[buttonSetIdx] = $buttonsDiv; |
875 } | |
612 | 876 return $buttonsDiv; |
610 | 877 }; |
615 | 878 |
879 // creates HTML structure for the bird's eye view in elem | |
638 | 880 var setupBirdDiv = function (data) { |
647 | 881 var $elem = data.$elem; |
628
1f077f8afc5e
changed methods to pass "data" around instead of "settings"
robcast
parents:
627
diff
changeset
|
882 var settings = data.settings; |
615 | 883 // use only the relevant parameters |
884 var keys = ['fn','pn','dw','dh']; | |
674 | 885 var birdDivOptions = { |
886 dw : settings.birdDivWidth, | |
887 dh : settings.birdDivHeight | |
888 }; | |
889 var birdSettings = $.extend({}, settings, birdDivOptions); | |
628
1f077f8afc5e
changed methods to pass "data" around instead of "settings"
robcast
parents:
627
diff
changeset
|
890 var birdUrl = settings.scalerBaseUrl + '?' + getParamString(birdSettings, keys); |
615 | 891 // the bird's eye div |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
892 var $birdDiv = $('<div class="birdview" style="display:none"/>'); |
615 | 893 // the detail indicator frame |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
894 var $birdZoom = $('<div class="birdZoom" style="display:none; position:absolute; background-color:transparent;"/>'); |
615 | 895 // the small image |
896 var $birdImg = $('<img class="birdimg"/>'); | |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
897 $elem.append($birdDiv); |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
898 $birdDiv.append($birdZoom); |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
899 $birdDiv.append($birdImg); |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
900 $birdZoom.css(data.settings.birdIndicatorStyle); |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
901 data.$birdDiv = $birdDiv; |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
902 data.$birdZoom = $birdZoom; |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
903 data.$birdImg = $birdImg; |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
904 $birdImg.load(birdImgLoadedHandler(data)); |
615 | 905 $birdImg.attr('src', birdUrl); |
640
fcb887110471
enabling bird's eye view in options now even works...
robcast
parents:
639
diff
changeset
|
906 if (data.settings.isBirdDivVisible) { |
687 | 907 $birdDiv.show(); |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
908 }; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
909 birdZoom(data); |
640
fcb887110471
enabling bird's eye view in options now even works...
robcast
parents:
639
diff
changeset
|
910 }; |
615 | 911 |
625 | 912 // creates HTML structure for the about view in elem |
628
1f077f8afc5e
changed methods to pass "data" around instead of "settings"
robcast
parents:
627
diff
changeset
|
913 var setupAboutDiv = function (data) { |
647 | 914 var $elem = data.$elem; |
628
1f077f8afc5e
changed methods to pass "data" around instead of "settings"
robcast
parents:
627
diff
changeset
|
915 var settings = data.settings; |
625 | 916 var $aboutDiv = $('<div class="about" style="display:none"/>'); |
616 | 917 var $header = $('<p>Digilib Graphic Viewer</p>'); |
918 var $link = $('<a/>'); | |
919 var $logo = $('<img class="logo" title="digilib"/>'); | |
920 var $content = $('<p/>'); | |
921 $elem.append($aboutDiv); | |
922 $aboutDiv.append($header); | |
923 $aboutDiv.append($link); | |
924 $aboutDiv.append($content); | |
925 $link.append($logo); | |
926 $logo.attr('src', settings.logoUrl); | |
635 | 927 $link.attr('href', settings.homeUrl); |
616 | 928 $content.text('Version: ' + settings.version); |
635 | 929 // click hides |
649 | 930 $aboutDiv.bind('click.digilib', function () { |
646 | 931 settings.isAboutDivVisible = showDiv(settings.isAboutDivVisible, $aboutDiv, 0); |
649 | 932 return false; |
710 | 933 }); |
635 | 934 data.$aboutDiv = $aboutDiv; |
634 | 935 }; |
936 | |
635 | 937 // shows some window e.g. 'about' (toggle visibility if show is null) |
938 var showDiv = function (isVisible, $div, show) { | |
645 | 939 if (show == null) { |
635 | 940 // toggle visibility |
941 isVisible = !isVisible; | |
942 } else { | |
943 // set visibility | |
944 isVisible = show; | |
710 | 945 }; |
635 | 946 if (isVisible) { |
947 $div.fadeIn(); | |
948 } else { | |
949 $div.fadeOut(); | |
710 | 950 }; |
635 | 951 return isVisible; |
634 | 952 }; |
616 | 953 |
697 | 954 // display more (or less) button sets |
955 var showButtons = function (data, more, setIdx, animated) { | |
711 | 956 var atime = animated ? 'fast': 0; |
697 | 957 if (more) { |
958 // add set | |
959 var $otherSets = data.$elem.find('div.buttons:visible'); | |
960 var $set; | |
961 if (data.$buttonSets && data.$buttonSets[setIdx]) { | |
962 // set exists | |
963 $set = data.$buttonSets[setIdx]; | |
964 } else { | |
965 $set = createButtons(data, setIdx); | |
710 | 966 }; |
697 | 967 if ($set == null) return false; |
968 var btnWidth = $set.width(); | |
969 // move remaining sets left and show new set | |
711 | 970 if ($otherSets.length > 0) { |
971 $otherSets.animate({right : '+='+btnWidth+'px'}, atime, | |
972 function () {$set.show();}); | |
697 | 973 } else { |
974 $set.show(); | |
711 | 975 } |
697 | 976 } else { |
977 // remove set | |
978 var $set = data.$buttonSets[setIdx]; | |
979 if ($set == null) return false; | |
980 var btnWidth = $set.width(); | |
981 // hide last set | |
982 $set.hide(); | |
983 // take remaining sets and move right | |
984 var $otherSets = data.$elem.find('div.buttons:visible'); | |
711 | 985 $otherSets.animate({right : '-='+btnWidth+'px'}, atime); |
986 } | |
697 | 987 return true; |
988 }; | |
989 | |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
990 // create Transform from area and $img |
675 | 991 var getImgTrafo = function ($img, area, rot, hmir, vmir) { |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
992 var picrect = geom.rectangle($img); |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
993 var trafo = geom.transform(); |
675 | 994 // move zoom area offset to center |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
995 trafo.concat(trafo.getTranslation(geom.position(-area.x, -area.y))); |
675 | 996 // scale zoom area size to [1,1] |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
997 trafo.concat(trafo.getScale(geom.size(1/area.width, 1/area.height))); |
675 | 998 // rotate and mirror (around transformed image center i.e. [0.5,0.5]) |
999 if (rot || hmir || vmir) { | |
1000 // move [0.5,0.5] to center | |
1001 trafo.concat(trafo.getTranslation(geom.position(-0.5, -0.5))); | |
1002 if (hmir) { | |
1003 // mirror about center | |
1004 trafo.concat(trafo.getMirror('y')); | |
710 | 1005 }; |
675 | 1006 if (vmir) { |
1007 // mirror about center | |
1008 trafo.concat(trafo.getMirror('x')); | |
710 | 1009 }; |
675 | 1010 if (rot) { |
1011 // rotate around center | |
1012 trafo.concat(trafo.getRotation(parseFloat(rot))); | |
710 | 1013 }; |
675 | 1014 // move back |
1015 trafo.concat(trafo.getTranslation(geom.position(0.5, 0.5))); | |
710 | 1016 }; |
664
d5a5ee4cbf04
work on getting transformation to work with rotation (currently still doesn't)
robcast
parents:
663
diff
changeset
|
1017 // scale to screen position and size |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1018 trafo.concat(trafo.getScale(picrect)); |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1019 trafo.concat(trafo.getTranslation(picrect)); |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1020 return trafo; |
655 | 1021 }; |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1022 |
613
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
1023 // returns function for load event of scaler img |
636 | 1024 var scalerImgLoadedHandler = function (data) { |
1025 var $img = data.$img; | |
633 | 1026 return function () { |
627 | 1027 console.debug("img loaded! this=", this, " data=", data); |
1028 // create Transform from current area and picsize | |
675 | 1029 data.imgTrafo = getImgTrafo($img, data.zoomArea, |
1030 data.settings.rot, data.scalerFlags.hmir, data.scalerFlags.vmir); | |
686 | 1031 console.debug("imgTrafo=", data.imgTrafo); |
627 | 1032 // display marks |
633 | 1033 renderMarks(data); |
695
5c39f5dd6296
cookie control for birdview, works for fullscreen
hertzhaft
parents:
693
diff
changeset
|
1034 // TODO: digilib.showArrows(); // show arrow overlays for zoom navigation |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1035 var $birdImg = data.$birdImg; |
705 | 1036 // should the birdview adapt to mirror or rotation? decision: No. :-) |
670
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1037 if ($birdImg) { |
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1038 $birdImg.triggerHandler('load'); |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1039 }; |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1040 }; |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1041 }; |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1042 |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1043 // returns function for load event of bird's eye view img |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1044 var birdImgLoadedHandler = function (data) { |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1045 var $img = data.$birdImg; |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1046 return function () { |
677
0233e39305d3
took renderBirdArea hooks out of scalerImgLoaded into redisplay.
robcast
parents:
676
diff
changeset
|
1047 console.debug("birdimg loaded! this=", this, " data=", data); |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1048 // create Transform from current area and picsize |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1049 data.birdTrafo = getImgTrafo($img, MAX_ZOOMAREA); |
668 | 1050 // display red indicator around zoomarea |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1051 renderbirdZoom(data); |
613
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
1052 }; |
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
1053 }; |
633 | 1054 |
1055 // place marks on the image | |
1056 var renderMarks = function (data) { | |
647 | 1057 var $elem = data.$elem; |
643 | 1058 var marks = data.marks; |
649 | 1059 // TODO: clear marks first(?) |
633 | 1060 for (var i = 0; i < marks.length; i++) { |
1061 var mark = marks[i]; | |
643 | 1062 if (data.zoomArea.containsPosition(mark)) { |
633 | 1063 var mpos = data.imgTrafo.transform(mark); |
664
d5a5ee4cbf04
work on getting transformation to work with rotation (currently still doesn't)
robcast
parents:
663
diff
changeset
|
1064 console.debug("renderMarks: mpos=",mpos); |
633 | 1065 // create mark |
1066 var html = '<div class="mark">'+(i+1)+'</div>'; | |
1067 var $mark = $(html); | |
1068 $elem.append($mark); | |
654 | 1069 $mark.offset({left : mpos.x, top : mpos.y}); |
710 | 1070 }; |
1071 }; | |
633 | 1072 }; |
655 | 1073 |
677
0233e39305d3
took renderBirdArea hooks out of scalerImgLoaded into redisplay.
robcast
parents:
676
diff
changeset
|
1074 // show zoom area indicator on bird's eye view |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1075 var renderbirdZoom = function (data) { |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1076 var $birdZoom = data.$birdZoom; |
659 | 1077 var zoomArea = data.zoomArea; |
1078 var indRect = data.birdTrafo.transform(zoomArea); | |
670
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1079 var coords = { |
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1080 left : indRect.x-2, // acount for frame width |
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1081 top : indRect.y-2, |
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1082 width : indRect.width, |
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1083 height: indRect.height |
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1084 }; |
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1085 var normalSize = isFullArea(zoomArea); |
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1086 if (data.settings.interactionMode === 'fullscreen') { |
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1087 // no animation for fullscreen |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1088 if (normalSize) return $birdZoom.hide(); |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1089 $birdZoom.width(coords.width); |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1090 $birdZoom.height(coords.height); |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1091 $birdZoom.offset(coords); |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1092 $birdZoom.show(); |
670
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1093 return; |
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1094 }; |
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1095 // nice animation for embedded mode :-) |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1096 var makeCompleteFunction = function($birdZoom, normalSize) { |
670
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1097 return function() { |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1098 if (normalSize) $birdZoom.hide(); |
672
7f7536a5b6d9
image transform works now under rotation!!! (at least for multiples of 90deg)
robcast
parents:
671
diff
changeset
|
1099 }; |
670
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1100 }; |
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1101 var opts = { |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1102 'complete' : makeCompleteFunction($birdZoom, normalSize) |
670
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1103 }; |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1104 if (!normalSize && $birdZoom.css('display') === 'none') $birdZoom.show(); |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1105 $birdZoom.animate(coords, opts); |
664
d5a5ee4cbf04
work on getting transformation to work with rotation (currently still doesn't)
robcast
parents:
663
diff
changeset
|
1106 }; |
659 | 1107 |
647 | 1108 // zooms by the given factor |
643 | 1109 var zoomBy = function(data, factor) { |
1110 var area = data.zoomArea; | |
1111 var newarea = area.copy(); | |
1112 // scale | |
1113 newarea.width /= factor; | |
1114 newarea.height /= factor; | |
1115 // and recenter | |
1116 newarea.x -= 0.5 * (newarea.width - area.width); | |
1117 newarea.y -= 0.5 * (newarea.height - area.height); | |
1118 newarea = MAX_ZOOMAREA.fit(newarea); | |
1119 data.zoomArea = newarea; | |
644
ee8ccd84c5f8
reload doesn't take list of changed parameters any more
robcast
parents:
643
diff
changeset
|
1120 redisplay(data); |
643 | 1121 }; |
1122 | |
647 | 1123 // add a mark where clicked |
1124 var setMark = function (data) { | |
649 | 1125 var $scaler = data.$scaler; |
647 | 1126 // start event capturing |
649 | 1127 $scaler.one('click.digilib', function (evt) { |
647 | 1128 // event handler adding a new mark |
672
7f7536a5b6d9
image transform works now under rotation!!! (at least for multiples of 90deg)
robcast
parents:
671
diff
changeset
|
1129 var mpos = geom.position(evt); |
647 | 1130 var pos = data.imgTrafo.invtransform(mpos); |
1131 data.marks.push(pos); | |
1132 redisplay(data); | |
649 | 1133 return false; // do we even get here? |
647 | 1134 }); |
1135 }; | |
668 | 1136 |
654 | 1137 var zoomArea = function(data) { |
1138 $elem = data.$elem; | |
1139 $scaler = data.$scaler; | |
1140 var pt1, pt2; | |
1141 var $zoomDiv = $('<div class="zoomrect" style="display:none"/>'); | |
1142 $elem.append($zoomDiv); | |
668 | 1143 $zoomDiv.css(data.settings.zoomrectStyle); |
654 | 1144 var picRect = geom.rectangle($scaler); |
1145 // FIX ME: is there a way to query the border width from CSS info? | |
1146 // rect.x -= 2; // account for overlay borders | |
1147 // rect.y -= 2; | |
1148 | |
1149 var zoomStart = function (evt) { | |
1150 pt1 = geom.position(evt); | |
1151 // setup and show zoom div | |
1152 //moveElement(zoomdiv, Rectangle(pt1.x, pt1.y, 0, 0)); | |
1153 $zoomDiv.offset({left : pt1.x, top : pt1.y}); | |
668 | 1154 $zoomDiv.width(0).height(0); |
654 | 1155 $zoomDiv.show(); |
1156 // register events | |
1157 $elem.bind("mousemove.digilib", zoomMove); | |
1158 $elem.bind("mouseup.digilib", zoomEnd); | |
1159 return false; | |
1160 }; | |
668 | 1161 |
654 | 1162 // mouseup handler: end moving |
1163 var zoomEnd = function (evt) { | |
1164 pt2 = geom.position(evt); | |
1165 // assume a click and continue if the area is too small | |
1166 var clickRect = geom.rectangle(pt1, pt2); | |
710 | 1167 if (clickRect.getArea() <= 5) return false; |
654 | 1168 // hide zoom div |
1169 $zoomDiv.remove(); | |
1170 // unregister events | |
1171 $elem.unbind("mousemove.digilib", zoomMove); | |
1172 $elem.unbind("mouseup.digilib", zoomEnd); | |
1173 // clip and transform | |
1174 clickRect.clipTo(picRect); | |
1175 var area = data.imgTrafo.invtransform(clickRect); | |
1176 data.zoomArea = area; | |
1177 // zoomed is always fit | |
1178 data.settings.ws = 1; | |
1179 redisplay(data); | |
1180 return false; | |
1181 }; | |
668 | 1182 |
654 | 1183 // mouse move handler |
1184 var zoomMove = function (evt) { | |
1185 pt2 = geom.position(evt); | |
1186 var rect = geom.rectangle(pt1, pt2); | |
1187 rect.clipTo(picRect); | |
1188 // update zoom div | |
672
7f7536a5b6d9
image transform works now under rotation!!! (at least for multiples of 90deg)
robcast
parents:
671
diff
changeset
|
1189 rect.adjustDiv($zoomDiv); |
654 | 1190 return false; |
1191 }; | |
668 | 1192 |
654 | 1193 // bind start zoom handler |
1194 $scaler.one('mousedown.digilib', zoomStart); | |
1195 }; | |
647 | 1196 |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1197 var birdZoom = function(data) { |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1198 var $birdImg = data.$birdImg; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1199 var $birdZoom = data.$birdZoom; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1200 var startPos, newRect, birdImgRect, birdZoomRect; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1201 |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1202 var birdZoomMove = function(evt) { |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1203 // mousemove handler: drag |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1204 var pos = geom.position(evt); |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1205 var dx = pos.x - startPos.x; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1206 var dy = pos.y - startPos.y; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1207 // move birdZoom div, keeping size |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1208 newRect = geom.rectangle( |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1209 birdZoomRect.x + dx, |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1210 birdZoomRect.y + dy, |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1211 birdZoomRect.width, |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1212 birdZoomRect.height |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1213 ); |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1214 // stay within birdimage |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1215 newRect.stayInside(birdImgRect); |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1216 $birdZoom.offset({left : newRect.x, top : newRect.y}); |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1217 // $birdZoom.show(); |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1218 return false; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1219 }; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1220 |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1221 var birdZoomEndDrag = function(evt) { |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1222 // mouseup handler: reload page |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1223 var settings = data.settings; |
680 | 1224 $(document).unbind("mousemove.digilib", birdZoomMove); |
1225 $(document).unbind("mouseup.digilib", birdZoomEndDrag); | |
1226 $birdZoom.unbind("mousemove.digilib", birdZoomMove); | |
1227 $birdZoom.unbind("mouseup.digilib", birdZoomEndDrag); | |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1228 if (newRect == null) { // no movement happened |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1229 startPos = birdZoomRect.getCenter(); |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1230 birdZoomMove(evt); // set center to click position |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1231 }; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1232 if (data.zoomArea) { |
679 | 1233 // should always be true |
1234 var x = cropFloat((newRect.x - birdImgRect.x + 2) / birdImgRect.width); | |
1235 var y = cropFloat((newRect.y - birdImgRect.y + 2) / birdImgRect.height); | |
1236 data.zoomArea.x = x; | |
1237 data.zoomArea.y = y; | |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1238 }; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1239 settings.ws = 1; // zoomed is always fit |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1240 redisplay(data); |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1241 return false; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1242 }; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1243 |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1244 var birdZoomStartDrag = function(evt) { |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1245 // mousedown handler: start dragging bird zoom to a new position |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1246 startPos = geom.position(evt); |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1247 birdImgRect = geom.rectangle($birdImg); |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1248 birdZoomRect = geom.rectangle($birdZoom); |
680 | 1249 $(document).bind("mousemove.digilib", birdZoomMove); |
1250 $(document).bind("mouseup.digilib", birdZoomEndDrag); | |
1251 $birdZoom.bind("mousemove.digilib", birdZoomMove); | |
1252 $birdZoom.bind("mouseup.digilib", birdZoomEndDrag); | |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1253 return false; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1254 }; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1255 |
681 | 1256 $birdImg.bind("mousedown.digilib", birdZoomStartDrag); |
1257 $birdZoom.bind("mousedown.digilib", birdZoomStartDrag); | |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1258 }; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1259 |
705 | 1260 var setupZoomDrag = function(data) { |
1261 // setup handlers for dragging the zoomed image | |
1262 var pt1, pt2; | |
1263 var dx = 0; | |
1264 var dy = 0; | |
1265 var $elem = data.$elem; | |
1266 var $scaler = data.$scaler; | |
1267 var $img = data.$img; | |
707 | 1268 var $bg = $elem.has('div.bgDrag'); |
1269 if ($bg.length === 0) { | |
1270 $bg = $('<div class="bgDrag" style="display:none; position:absolute"/>'); | |
1271 $scaler.before($bg); // set as background | |
1272 }; | |
710 | 1273 |
705 | 1274 var dragStart = function (evt) { |
1275 // drag the image and load a new detail on mouse up | |
1276 // useless if not zoomed | |
1277 if (isFullArea(data.zoomArea)) return false; | |
1278 if(evt.preventDefault) evt.preventDefault(); // no Firefox drag and drop (NEEDED?) | |
1279 pt1 = geom.position(evt); | |
1280 $imgRect = geom.rectangle($img); | |
1281 $imgRect.adjustDiv($bg); // set background size | |
1282 // hide the scaler image, show it as background of div instead | |
1283 $bg.css({ | |
1284 'background-image' : 'url(' + $img.attr('src') + ')', | |
1285 'background-repeat' : 'no-repeat', | |
706 | 1286 'background-position' : 'top left', |
705 | 1287 'cursor' : 'move' |
1288 }); | |
1289 $img.hide(); | |
1290 $bg.show(); | |
1291 $(document).bind("mousemove.digilib", dragMove); | |
1292 $(document).bind("mouseup.digilib", dragEnd); | |
1293 window.focus(); | |
1294 }; | |
710 | 1295 |
705 | 1296 var dragMove = function (evt) { |
1297 // mousemove handler: drag | |
1298 var pos = geom.position(evt); | |
1299 if(evt.preventDefault) evt.preventDefault(); // no Firefox drag and drop (NEEDED?) | |
1300 dx = pos.x - pt1.x; | |
1301 dy = pos.y - pt1.y; | |
1302 // move the background image to the new position | |
1303 $bg.css({ | |
1304 'background-position' : dx + "px " + dy + "px" | |
1305 }); | |
1306 return false; | |
1307 }; | |
710 | 1308 |
705 | 1309 var dragEnd = function (evt) { |
1310 // mouseup handler: reload digilib | |
1311 $bg.css({ | |
1312 'cursor' : 'default' | |
1313 }); | |
1314 $(document).unbind("mousemove.digilib", dragMove); | |
1315 $(document).unbind("mouseup.digilib", dragEnd); | |
1316 // calculate relative offset | |
711 | 1317 if (dx == 0 && dy == 0) return false; // no movement |
705 | 1318 // reload with scaler image showing the new ausschnitt |
708
120ace160386
img reload works for fullscreen, but somehow not precise
hertzhaft
parents:
707
diff
changeset
|
1319 // digilib.moveBy(x, y); |
120ace160386
img reload works for fullscreen, but somehow not precise
hertzhaft
parents:
707
diff
changeset
|
1320 var pos = geom.position(-dx, -dy); |
120ace160386
img reload works for fullscreen, but somehow not precise
hertzhaft
parents:
707
diff
changeset
|
1321 var newPos = data.imgTrafo.invtransform(pos); |
120ace160386
img reload works for fullscreen, but somehow not precise
hertzhaft
parents:
707
diff
changeset
|
1322 var newArea = data.zoomArea.setPt1(newPos); |
120ace160386
img reload works for fullscreen, but somehow not precise
hertzhaft
parents:
707
diff
changeset
|
1323 data.zoomArea = MAX_ZOOMAREA.fit(newArea); |
706 | 1324 $bg.hide(); |
708
120ace160386
img reload works for fullscreen, but somehow not precise
hertzhaft
parents:
707
diff
changeset
|
1325 redisplay(data); |
705 | 1326 return false; |
1327 }; | |
1328 | |
1329 $scaler.bind("mousedown.digilib", dragStart); | |
1330 }; | |
1331 | |
703 | 1332 // get image quality as a number (0..2) |
1333 var getQuality = function (data) { | |
1334 var flags = data.scalerFlags; | |
1335 var q = flags.q2 || flags.q1 || 'q0'; // assume q0 as default | |
1336 return parseInt(q[1], 10); | |
706 | 1337 }; |
703 | 1338 |
1339 // set image quality as a number (0..2) | |
1340 var setQuality = function (data, qual) { | |
1341 var flags = data.scalerFlags; | |
1342 // clear flags | |
1343 for (var i = 0; i < 3; ++i) { | |
1344 delete flags['q'+i]; | |
710 | 1345 }; |
703 | 1346 flags['q'+qual] = 'q'+qual; |
706 | 1347 }; |
710 | 1348 |
650 | 1349 // sets a key to a value (relative values with +/- if relative=true) |
1350 var setNumValue = function(settings, key, value) { | |
1351 if (isNumber(value)) return settings[key] = value; | |
1352 var sign = value.substring(0,1); | |
1353 if (sign === '+' || sign === '-') { | |
1354 if (settings[key] == null) { | |
651
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1355 // this isn't perfect but still... |
650 | 1356 settings[key] = 0; |
710 | 1357 }; |
650 | 1358 settings[key] = parseFloat(settings[key]) + parseFloat(value); |
1359 } else { | |
1360 settings[key] = value; | |
710 | 1361 }; |
650 | 1362 return settings[key]; |
1363 }; | |
655 | 1364 |
1365 // auxiliary function (from old dllib.js) | |
659 | 1366 isFullArea = function(area) { |
1367 return (area.width === 1.0) && (area.height === 1.0); | |
655 | 1368 }; |
1369 | |
641 | 1370 // auxiliary function (from Douglas Crockford, A.10) |
1371 var isNumber = function isNumber(value) { | |
710 | 1372 return typeof value === 'number' && isFinite(value); |
641 | 1373 }; |
655 | 1374 |
631 | 1375 // auxiliary function to crop senseless precision |
1376 var cropFloat = function (x) { | |
637 | 1377 return parseInt(10000 * x, 10) / 10000; |
631 | 1378 }; |
655 | 1379 |
692 | 1380 // fallback for console.log calls |
1381 if (customConsole) { | |
1382 var logFunction = function(type) { | |
1383 return function(){ | |
1384 var $debug = $('#debug'); // debug div | |
1385 if (!$debug) return; | |
1386 var args = Array.prototype.slice.call(arguments); | |
1387 var argtext = args.join(' '); | |
1388 var $logDiv = $('<div/>'); | |
1389 $logDiv.addClass(type); | |
1390 $logDiv.text(argtext); | |
1391 $debug.append($logDiv); | |
1392 }; | |
1393 }; | |
1394 console.log = logFunction('_log'); | |
1395 console.debug = logFunction('_debug'); | |
1396 console.error = logFunction('_error'); | |
1397 }; | |
1398 | |
605 | 1399 // hook plugin into jquery |
651
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1400 $.fn.digilib = function(action) { |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1401 if (actions[action]) { |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1402 // call action on this with the remaining arguments (inserting data as first argument) |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1403 var $elem = $(this); |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1404 var data = $elem.data('digilib'); |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1405 var args = Array.prototype.slice.call(arguments, 1); |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1406 args.unshift(data); |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1407 return actions[action].apply(this, args); |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1408 } else if (typeof(action) === 'object' || !action) { |
634 | 1409 // call init on this |
651
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1410 return actions.init.apply(this, arguments); |
605 | 1411 } else { |
651
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1412 $.error( 'action ' + action + ' does not exist on jQuery.digilib' ); |
710 | 1413 }; |
605 | 1414 }; |
692 | 1415 |
604 | 1416 })(jQuery); |