Mercurial > hg > digilib
annotate client/digitallibrary/jquery/jquery.digilib.js @ 849:2b7143c331c3 jquery
first step towards zoom arrows
author | hertzhaft |
---|---|
date | Tue, 08 Mar 2011 09:07:07 +0100 |
parents | 8aa2891583f1 |
children | 34b20eec036b |
rev | line source |
---|---|
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1 /* Copyright (c) 2011 Martin Raspe, Robert Casties |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
2 |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
3 This program is free software: you can redistribute it and/or modify |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
4 it under the terms of the GNU Lesser General Public License as published by |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
5 the Free Software Foundation, either version 2 of the License, or |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
6 (at your option) any later version. |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
7 |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
8 This program is distributed in the hope that it will be useful, |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
9 but WITHOUT ANY WARRANTY; without even the implied warranty of |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
11 GNU Lesser General Public License for more details. |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
12 |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
13 You should have received a copy of the GNU Lesser General Public License |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
15 |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
16 Authors: |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
17 Martin Raspe, Robert Casties, 11.1.2011 |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
18 */ |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
19 |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
20 /** |
597 | 21 * digilib jQuery plugin |
738
bd283b2cdbbc
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
737
diff
changeset
|
22 **/ |
bd283b2cdbbc
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
737
diff
changeset
|
23 |
760 | 24 /*jslint browser: true, debug: true, forin: true |
738
bd283b2cdbbc
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
737
diff
changeset
|
25 */ |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
26 |
629 | 27 // fallback for console.log calls |
790 | 28 if (typeof console === 'undefined') { |
629 | 29 var console = { |
685 | 30 log : function(){}, |
31 debug : function(){}, | |
32 error : function(){} | |
33 }; | |
772 | 34 var customConsole = false; // set to true if debugging for MS IE |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
35 } |
597 | 36 |
37 (function($) { | |
644
bffc7d8c3641
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
643
diff
changeset
|
38 var buttons = { |
603 | 39 reference : { |
682 | 40 onclick : "reference", |
603 | 41 tooltip : "get a reference URL", |
758 | 42 icon : "reference.png" |
603 | 43 }, |
44 zoomin : { | |
636 | 45 onclick : ["zoomBy", 1.4], |
603 | 46 tooltip : "zoom in", |
758 | 47 icon : "zoom-in.png" |
603 | 48 }, |
49 zoomout : { | |
636 | 50 onclick : ["zoomBy", 0.7], |
603 | 51 tooltip : "zoom out", |
758 | 52 icon : "zoom-out.png" |
603 | 53 }, |
54 zoomarea : { | |
647 | 55 onclick : "zoomArea", |
603 | 56 tooltip : "zoom area", |
758 | 57 icon : "zoom-area.png" |
603 | 58 }, |
59 zoomfull : { | |
643 | 60 onclick : "zoomFull", |
603 | 61 tooltip : "view the whole image", |
758 | 62 icon : "zoom-full.png" |
603 | 63 }, |
64 pagewidth : { | |
643 | 65 onclick : ["zoomFull", "width"], |
603 | 66 tooltip : "page width", |
758 | 67 icon : "pagewidth.png" |
603 | 68 }, |
69 back : { | |
616 | 70 onclick : ["gotoPage", "-1"], |
603 | 71 tooltip : "goto previous image", |
758 | 72 icon : "back.png" |
603 | 73 }, |
74 fwd : { | |
616 | 75 onclick : ["gotoPage", "+1"], |
603 | 76 tooltip : "goto next image", |
758 | 77 icon : "fwd.png" |
603 | 78 }, |
79 page : { | |
709 | 80 onclick : "gotoPage", |
81 tooltip : "goto image number", | |
758 | 82 icon : "page.png" |
603 | 83 }, |
84 help : { | |
628 | 85 onclick : "showAboutDiv", |
603 | 86 tooltip : "about Digilib", |
758 | 87 icon : "help.png" |
603 | 88 }, |
89 reset : { | |
681 | 90 onclick : "reset", |
603 | 91 tooltip : "reset image", |
758 | 92 icon : "reset.png" |
603 | 93 }, |
94 mark : { | |
640 | 95 onclick : "setMark", |
603 | 96 tooltip : "set a mark", |
758 | 97 icon : "mark.png" |
603 | 98 }, |
99 delmark : { | |
643 | 100 onclick : "removeMark", |
603 | 101 tooltip : "delete the last mark", |
758 | 102 icon : "delmark.png" |
603 | 103 }, |
104 hmir : { | |
654 | 105 onclick : ["mirror", "h"], |
603 | 106 tooltip : "mirror horizontally", |
758 | 107 icon : "mirror-horizontal.png" |
603 | 108 }, |
109 vmir : { | |
654 | 110 onclick : ["mirror", "v"], |
603 | 111 tooltip : "mirror vertically", |
758 | 112 icon : "mirror-vertical.png" |
603 | 113 }, |
114 rot : { | |
656 | 115 onclick : "rotate", |
603 | 116 tooltip : "rotate image", |
758 | 117 icon : "rotate.png" |
603 | 118 }, |
119 brgt : { | |
656 | 120 onclick : "brightness", |
603 | 121 tooltip : "set brightness", |
758 | 122 icon : "brightness.png" |
603 | 123 }, |
124 cont : { | |
656 | 125 onclick : "contrast", |
603 | 126 tooltip : "set contrast", |
758 | 127 icon : "contrast.png" |
603 | 128 }, |
129 rgb : { | |
130 onclick : "javascript:setParamWin('rgb', '...')", | |
131 tooltip : "set rgb values", | |
758 | 132 icon : "rgb.png" |
603 | 133 }, |
134 quality : { | |
741 | 135 onclick : "setQuality", |
603 | 136 tooltip : "set image quality", |
758 | 137 icon : "quality.png" |
603 | 138 }, |
139 size : { | |
140 onclick : "javascript:toggleSizeMenu()", | |
141 tooltip : "set page size", | |
758 | 142 icon : "size.png" |
603 | 143 }, |
144 calibrationx : { | |
747
5d3da97089bc
reading image info asynchronously works now. has just no use yet.
robcast
parents:
744
diff
changeset
|
145 onclick : "calibrate", |
5d3da97089bc
reading image info asynchronously works now. has just no use yet.
robcast
parents:
744
diff
changeset
|
146 tooltip : "calibrate screen resolution", |
758 | 147 icon : "calibration-x.png" |
603 | 148 }, |
149 scale : { | |
754
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
150 onclick : "setScaleMode", |
603 | 151 tooltip : "change image scale", |
758 | 152 icon : "original-size.png" |
603 | 153 }, |
692 | 154 toggleoptions : { |
741 | 155 onclick : "moreButtons", |
692 | 156 tooltip : "more options", |
758 | 157 icon : "options.png" |
692 | 158 }, |
683 | 159 moreoptions : { |
741 | 160 onclick : ["moreButtons", "+1"], |
683 | 161 tooltip : "more options", |
758 | 162 icon : "options.png" |
683 | 163 }, |
164 lessoptions : { | |
741 | 165 onclick : ["moreButtons", "-1"], |
683 | 166 tooltip : "less options", |
758 | 167 icon : "options.png" |
603 | 168 }, |
169 SEP : { | |
758 | 170 icon : "sep.png" |
603 | 171 } |
172 }; | |
610
2f2cd8c44a1c
toggle view event handlers for bird's eye and 'about windows
hertzhaft
parents:
609
diff
changeset
|
173 |
598 | 174 var defaults = { |
609 | 175 // version of this script |
628 | 176 'version' : 'jquery.digilib.js 0.9', |
609 | 177 // logo url |
178 'logoUrl' : '../img/digilib-logo-text1.png', | |
628 | 179 // homepage url (behind logo) |
180 'homeUrl' : 'http://digilib.berlios.de', | |
737 | 181 // base URL to digilib viewer (for reference URLs) |
182 'digilibBaseUrl' : null, | |
603 | 183 // base URL to Scaler servlet |
645 | 184 'scalerBaseUrl' : null, |
603 | 185 // list of Scaler parameters |
620 | 186 'scalerParamNames' : ['fn','pn','dw','dh','ww','wh','wx','wy','ws','mo', |
187 'rot','cont','brgt','rgbm','rgba','ddpi','ddpix','ddpiy'], | |
188 // Scaler parameter defaults | |
636 | 189 'pn' : 1, |
620 | 190 'ww' : 1.0, |
191 'wh' : 1.0, | |
192 'wx' : 0.0, | |
193 'wy' : 0.0, | |
194 'ws' : 1.0, | |
636 | 195 'mo' : '', |
196 'rot' : 0, | |
197 'cont' : 0, | |
198 'brgt' : 0, | |
199 'rgbm' : '0/0/0', | |
200 'rgba' : '0/0/0', | |
201 'ddpi' : null, | |
202 'ddpix' : null, | |
203 'ddpiy' : null, | |
637
71cc855e2e4b
reload doesn't take list of changed parameters any more
robcast
parents:
636
diff
changeset
|
204 // list of digilib parameters |
765
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
205 'digilibParamNames' : ['fn','pn','ww','wh','wx','wy','ws','mo','rot','cont','brgt','rgbm','rgba','ddpi','mk','clop'], |
637
71cc855e2e4b
reload doesn't take list of changed parameters any more
robcast
parents:
636
diff
changeset
|
206 // digilib parameter defaults |
636 | 207 'mk' : '', |
643 | 208 'clop' : '', |
636 | 209 // mode of operation: |
210 // fullscreen = take parameters from page URL, keep state in page URL | |
211 // embedded = take parameters from Javascript options, keep state inside object | |
603 | 212 'interactionMode' : 'fullscreen', |
644
bffc7d8c3641
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
643
diff
changeset
|
213 // buttons |
bffc7d8c3641
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
643
diff
changeset
|
214 'buttons' : buttons, |
661 | 215 // defaults for digilib buttons |
658 | 216 'buttonSettings' : { |
217 'fullscreen' : { | |
661 | 218 // path to button images (must end with a slash) |
658 | 219 'imagePath' : 'img/fullscreen/', |
788 | 220 'standardSet' : ["reference","zoomin","zoomout","zoomarea","zoomfull","pagewidth","back","fwd","page","help","reset","toggleoptions"], |
843
76c23870ac0b
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
842
diff
changeset
|
221 'specialSet' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","size","calibrationx","scale","lessoptions"], |
675 | 222 'buttonSets' : ['standardSet', 'specialSet'] |
658 | 223 }, |
224 'embedded' : { | |
225 'imagePath' : 'img/embedded/16/', | |
788 | 226 'standardSet' : ["reference","zoomin","zoomout","zoomarea","zoomfull","help","reset","toggleoptions"], |
843
76c23870ac0b
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
842
diff
changeset
|
227 'specialSet' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","scale","lessoptions"], |
675 | 228 'buttonSets' : ['standardSet', 'specialSet'] |
658 | 229 } |
690 | 230 }, |
849 | 231 // arrow overlays for moving the zoomed area |
232 'zoomArrows' : true, | |
233 // zoom arrow image info | |
234 'zoomArrowImg' : { | |
235 // path to arrow images (must end with a slash) | |
236 'imagePath' : 'img/', | |
237 // minimal width of the arrow bar (pixel) | |
238 'minwidth' : 6, | |
239 // image file names | |
240 'up' : 'up.png', | |
241 'down' : 'down.png', | |
242 'left' : 'left.png', | |
243 'right' : 'right.png' | |
244 }, | |
690 | 245 // number of visible button groups |
728
53584f90f66b
improved some embedded buttons; fixed reset function
hertzhaft
parents:
726
diff
changeset
|
246 'visibleButtonSets' : 1, |
609 | 247 // is the "about" window shown? |
734 | 248 'isAboutDivVisible' : false, |
788 | 249 // default size of background image for drag-scroll (same as Bird's Eye View image) |
250 'bgImgWidth' : 200, | |
251 'bgImgHeight' : 200, | |
252 // maximum width or height of background image for drag-scroll | |
771 | 253 'maxBgSize' : 10000, |
788 | 254 // parameters used by background image |
255 'bgImgParams' : ['fn','pn','dw','dh','mo','rot'], | |
849 | 256 // reserved space in full page display (default value accounts for vertical scrollbar) |
778 | 257 'scalerInset' : 10 |
603 | 258 }; |
648 | 259 |
779 | 260 // list of plugins |
261 var plugins = {}; | |
780 | 262 // object to export functions to plugins |
263 var fn; | |
779 | 264 // affine geometry plugin stub |
778 | 265 var geom; |
648 | 266 |
778 | 267 var FULL_AREA; |
648 | 268 |
644
bffc7d8c3641
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
643
diff
changeset
|
269 var actions = { |
661 | 270 // init: digilib initialization |
271 init : function(options) { | |
779 | 272 // import geometry classes |
273 if (plugins.geometry == null) { | |
274 $.error("jquery.digilib.geometry plugin not found!"); | |
783
16cff012d7c1
put plugins reference into plugin object. put geom into fn object for plugins.
robcast
parents:
781
diff
changeset
|
275 // last straw: old version |
778 | 276 geom = dlGeometry(); |
277 } else { | |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
278 // geometry plugin puts classes in the shared fn |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
279 geom = fn.geometry; |
778 | 280 } |
281 FULL_AREA = geom.rectangle(0, 0, 1, 1); | |
781 | 282 |
661 | 283 // settings for this digilib instance are merged from defaults and options |
284 var settings = $.extend({}, defaults, options); | |
285 var isFullscreen = settings.interactionMode === 'fullscreen'; | |
286 var queryParams = {}; | |
287 if (isFullscreen) { | |
288 queryParams = parseQueryParams(); | |
289 // check scalerBaseUrl | |
290 if (settings.scalerBaseUrl == null) { | |
291 // try the host this came from | |
292 var h = window.location.host; | |
293 if (window.location.host) { | |
294 var url = window.location.href; | |
295 // assume the page lives in [webapp]/jquery/ | |
296 var pos = url.indexOf('jquery/'); | |
297 if (pos > 0) { | |
298 settings.scalerBaseUrl = url.substring(0, pos) + 'servlet/Scaler'; | |
645 | 299 } |
300 } | |
629 | 301 } |
661 | 302 } |
303 return this.each(function() { | |
304 var $elem = $(this); | |
305 var data = $elem.data('digilib'); | |
681 | 306 var params, elemSettings; |
661 | 307 // if the plugin hasn't been initialized yet |
308 if (!data) { | |
309 // merge query parameters | |
310 if (isFullscreen) { | |
681 | 311 params = queryParams; |
661 | 312 } else { |
681 | 313 params = parseImgParams($elem); |
778 | 314 if ($.cookie) { |
720 | 315 // retrieve params from cookie |
316 var ck = "digilib-embed:fn:" + escape(params.fn) + ":pn:" + (params.pn || '1'); | |
778 | 317 var cs = $.cookie(ck); |
720 | 318 console.debug("get cookie=", ck, " value=", cs); |
319 if (cs) { | |
320 var cp = parseQueryString(cs); | |
721 | 321 // ignore fn and pn from cookie TODO: should we keep pn? |
322 delete cp.fn; | |
323 delete cp.pn; | |
778 | 324 $.extend(params, cp); |
720 | 325 } |
326 } | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
327 } |
849 | 328 // setup $elem.data, needs "deep copy" because of nesting |
842 | 329 elemSettings = $.extend(true, {}, settings, params); |
690 | 330 data = { |
849 | 331 // let $(this) know about $(this) :-) |
661 | 332 $elem : $elem, |
849 | 333 // let $elem have its own copy of settings |
661 | 334 settings : elemSettings, |
849 | 335 // and of the URL query parameters |
781 | 336 queryParams : params, |
783
16cff012d7c1
put plugins reference into plugin object. put geom into fn object for plugins.
robcast
parents:
781
diff
changeset
|
337 // TODO: move plugins reference out of data |
781 | 338 plugins : plugins |
661 | 339 }; |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
340 // store in jQuery data element |
661 | 341 $elem.data('digilib', data); |
342 } | |
343 unpackParams(data); | |
737 | 344 // check if browser knows *background-size |
734 | 345 for (var bs in {'':1, '-moz-':1, '-webkit-':1, '-o-':1}) { |
346 if ($elem.css(bs+'background-size')) { | |
347 data.hasBgSize = true; | |
348 data.bgSizeName = bs+'background-size'; | |
349 break; | |
350 } | |
351 } | |
737 | 352 // check digilib base URL |
353 if (elemSettings.digilibBaseUrl == null) { | |
354 if (isFullscreen) { | |
355 // take current host | |
356 var url = window.location.toString(); | |
357 var pos = url.indexOf('?'); | |
358 elemSettings.digilibBaseUrl = url.substring(0, pos); | |
359 } else { | |
360 var url = elemSettings.scalerBaseUrl; | |
361 if (url) { | |
362 // build it from scaler URL | |
363 var bp = url.indexOf('/servlet/Scaler'); | |
758 | 364 elemSettings.digilibBaseUrl = url.substring(0, bp) + '/digilib.jsp'; |
737 | 365 } |
366 } | |
367 } | |
779 | 368 // initialise plugins |
780 | 369 for (n in plugins) { |
370 var p = plugins[n]; | |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
371 if (typeof p.init === 'function') { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
372 p.init(data); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
373 } |
779 | 374 } |
756
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
375 // get image info from server if needed |
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
376 if (data.scaleMode === 'pixel' || data.scaleMode === 'size') { |
790 | 377 $(data).bind('imageInfo', handleImageInfo); |
378 loadImageInfo(data); // triggers "imageInfo" on completion | |
756
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
379 } |
772 | 380 // create buttons before scaler |
690 | 381 for (var i = 0; i < elemSettings.visibleButtonSets; ++i) { |
382 showButtons(data, true, i); | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
383 } |
772 | 384 // create HTML structure for scaler, taking width of buttons div into account |
385 setupScalerDiv(data); | |
758 | 386 highlightButtons(data); |
661 | 387 // about window creation - TODO: could be deferred? restrict to only one item? |
388 setupAboutDiv(data); | |
849 | 389 // arrow overlays for moving zoomed detail |
390 setupZoomArrows(data); | |
788 | 391 // send setup event |
392 $(data).trigger('setup'); | |
661 | 393 }); |
394 }, | |
395 | |
396 // destroy: clean up digilib | |
397 destroy : function(data) { | |
398 return this.each(function(){ | |
399 var $elem = $(this); | |
400 $(window).unbind('.digilib'); // unbind all digilibs(?) | |
401 data.digilib.remove(); | |
402 $elem.removeData('digilib'); | |
403 }); | |
404 }, | |
405 | |
406 // show or hide the 'about' window | |
407 showAboutDiv : function(data, show) { | |
758 | 408 var on = showDiv(data.settings.isAboutDivVisible, data.$aboutDiv, show); |
409 data.settings.isAboutDivVisible = on; | |
410 highlightButtons(data, 'help', on); | |
661 | 411 }, |
648 | 412 |
661 | 413 // goto given page nr (+/-: relative) |
414 gotoPage : function (data, pageNr) { | |
415 var settings = data.settings; | |
416 var oldpn = settings.pn; | |
709 | 417 if (pageNr == null) { |
418 pageNr = window.prompt("Goto page number", oldpn); | |
419 } | |
661 | 420 var pn = setNumValue(settings, "pn", pageNr); |
421 if (pn == null) return false; // nothing happened | |
422 if (pn < 1) { | |
423 alert("no such page (page number too low)"); | |
424 settings.pn = oldpn; | |
425 return false; | |
426 } | |
760 | 427 // TODO: how do we get pt? |
661 | 428 if (settings.pt) { |
429 if (pn > settings.pt) { | |
430 alert("no such page (page number too high)"); | |
616 | 431 settings.pn = oldpn; |
432 return false; | |
627 | 433 } |
661 | 434 } |
435 // reset mk and others(?) | |
436 data.marks = []; | |
728
53584f90f66b
improved some embedded buttons; fixed reset function
hertzhaft
parents:
726
diff
changeset
|
437 data.zoomArea = FULL_AREA; |
661 | 438 // then reload |
439 redisplay(data); | |
440 }, | |
647 | 441 |
661 | 442 // zoom by a given factor |
443 zoomBy : function (data, factor) { | |
444 zoomBy(data, factor); | |
445 }, | |
640 | 446 |
760 | 447 // zoom to area (or interactive) |
448 zoomArea : function (data, area) { | |
449 var settings = data.settings; | |
450 if (area == null) { | |
451 // interactively | |
452 zoomArea(data); | |
453 } else { | |
454 data.zoomArea = geom.rectangle(area); | |
455 redisplay(data); | |
456 } | |
661 | 457 }, |
643 | 458 |
661 | 459 // zoom out to full page |
460 zoomFull : function (data, mode) { | |
728
53584f90f66b
improved some embedded buttons; fixed reset function
hertzhaft
parents:
726
diff
changeset
|
461 data.zoomArea = FULL_AREA; |
661 | 462 if (mode === 'width') { |
463 data.dlOpts.fitwidth = 1; | |
464 delete data.dlOpts.fitheight; | |
465 } else if (mode === 'height') { | |
466 data.dlOpts.fitheight = 1; | |
467 delete data.dlOpts.fitwidth; | |
468 } else { | |
469 delete data.dlOpts.fitwidth; | |
470 delete data.dlOpts.fitheight; | |
471 } | |
472 redisplay(data); | |
473 }, | |
474 | |
475 // set a mark by clicking (or giving a position) | |
476 setMark : function (data, mpos) { | |
477 if (mpos == null) { | |
478 // interactive | |
479 setMark(data); | |
480 } else { | |
481 // use position | |
482 data.marks.push(pos); | |
656 | 483 redisplay(data); |
597 | 484 } |
661 | 485 }, |
486 | |
487 // remove the last mark | |
488 removeMark : function (data) { | |
489 data.marks.pop(); | |
490 redisplay(data); | |
491 }, | |
492 | |
493 // mirror the image | |
494 mirror : function (data, mode) { | |
495 var flags = data.scalerFlags; | |
496 if (mode === 'h') { | |
497 if (flags.hmir) { | |
498 delete flags.hmir; | |
499 } else { | |
500 flags.hmir = 1; | |
501 } | |
502 } else { | |
503 if (flags.vmir) { | |
504 delete flags.vmir; | |
505 } else { | |
506 flags.vmir = 1; | |
507 } | |
508 } | |
509 redisplay(data); | |
510 }, | |
643 | 511 |
661 | 512 // rotate the image |
513 rotate : function (data, angle) { | |
514 var rot = data.settings.rot; | |
515 if (angle == null) { | |
516 angle = window.prompt("Rotation angle:", rot); | |
517 } | |
518 data.settings.rot = angle; | |
519 redisplay(data); | |
520 }, | |
521 | |
522 // change brightness | |
523 brightness : function (data, factor) { | |
524 var brgt = data.settings.brgt; | |
525 if (factor == null) { | |
526 factor = window.prompt("Brightness (-255..255)", brgt); | |
527 } | |
528 data.settings.brgt = factor; | |
529 redisplay(data); | |
530 }, | |
531 | |
532 // change contrast | |
533 contrast : function (data, factor) { | |
534 var cont = data.settings.cont; | |
535 if (factor == null) { | |
536 factor = window.prompt("Contrast (-8, 8)", cont); | |
537 } | |
538 data.settings.cont = factor; | |
539 redisplay(data); | |
681 | 540 }, |
703 | 541 |
683 | 542 // display more (or less) button sets |
741 | 543 moreButtons : function (data, more) { |
689 | 544 var settings = data.settings; |
692 | 545 if (more == null) { |
696 | 546 // toggle more or less (only works for 2 sets) |
692 | 547 var maxbtns = settings.buttonSettings[settings.interactionMode].buttonSets.length; |
548 if (settings.visibleButtonSets >= maxbtns) { | |
549 more = '-1'; | |
550 } else { | |
551 more = '+1'; | |
552 } | |
553 } | |
683 | 554 if (more === '-1') { |
555 // remove set | |
690 | 556 var setIdx = settings.visibleButtonSets - 1; |
557 if (showButtons(data, false, setIdx, true)) { | |
558 settings.visibleButtonSets--; | |
559 } | |
683 | 560 } else { |
561 // add set | |
690 | 562 var setIdx = settings.visibleButtonSets; |
563 if (showButtons(data, true, setIdx, true)) { | |
564 settings.visibleButtonSets++; | |
683 | 565 } |
566 } | |
716 | 567 // persist setting |
568 storeOptions(data); | |
684 | 569 }, |
681 | 570 |
696 | 571 // reset image parameters to defaults |
681 | 572 reset : function (data) { |
573 var settings = data.settings; | |
574 var paramNames = settings.digilibParamNames; | |
575 var params = data.queryParams; | |
576 // delete all digilib parameters | |
577 for (var i = 0; i < paramNames.length; i++) { | |
578 var paramName = paramNames[i]; | |
579 delete settings[paramName]; | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
580 } |
728
53584f90f66b
improved some embedded buttons; fixed reset function
hertzhaft
parents:
726
diff
changeset
|
581 settings.fn = params.fn || ''; // no default defined |
53584f90f66b
improved some embedded buttons; fixed reset function
hertzhaft
parents:
726
diff
changeset
|
582 settings.pn = params.pn || defaults.pn; |
53584f90f66b
improved some embedded buttons; fixed reset function
hertzhaft
parents:
726
diff
changeset
|
583 settings.dw = params.dw; |
53584f90f66b
improved some embedded buttons; fixed reset function
hertzhaft
parents:
726
diff
changeset
|
584 settings.dh = params.dh; |
702 | 585 settings.isBirdDivVisible = false; |
586 settings.visibleButtonSets = 1; | |
728
53584f90f66b
improved some embedded buttons; fixed reset function
hertzhaft
parents:
726
diff
changeset
|
587 // resets zoomArea, marks, scalerflags |
53584f90f66b
improved some embedded buttons; fixed reset function
hertzhaft
parents:
726
diff
changeset
|
588 data.zoomArea = FULL_AREA; |
53584f90f66b
improved some embedded buttons; fixed reset function
hertzhaft
parents:
726
diff
changeset
|
589 data.marks = []; |
53584f90f66b
improved some embedded buttons; fixed reset function
hertzhaft
parents:
726
diff
changeset
|
590 data.scalerFlags = {}; |
705 | 591 delete data.dlOpts.fitwidth; |
592 delete data.dlOpts.fitheight; | |
681 | 593 redisplay(data); |
682 | 594 }, |
595 | |
696 | 596 // presents a reference url (returns value if noprompt) |
597 reference : function (data, noprompt) { | |
682 | 598 var settings = data.settings; |
737 | 599 var url = getDigilibUrl(data); |
696 | 600 if (noprompt == null) { |
601 window.prompt("URL reference to the current view", url); | |
602 } | |
603 return url; | |
604 }, | |
703 | 605 |
696 | 606 // set image quality |
741 | 607 setQuality : function (data, qual) { |
696 | 608 var oldq = getQuality(data); |
609 if (qual == null) { | |
610 qual = window.prompt("Image quality (0..2)", oldq); | |
611 } | |
612 qual = parseInt(qual, 10); | |
613 if (qual >= 0 && qual <= 2) { | |
614 setQuality(data, qual); | |
615 redisplay(data); | |
616 } | |
747
5d3da97089bc
reading image info asynchronously works now. has just no use yet.
robcast
parents:
744
diff
changeset
|
617 }, |
753
8452a485e0e7
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
748
diff
changeset
|
618 |
747
5d3da97089bc
reading image info asynchronously works now. has just no use yet.
robcast
parents:
744
diff
changeset
|
619 // calibrate (only faking) |
765
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
620 calibrate : function (data, res) { |
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
621 var oldRes = data.settings.ddpi; |
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
622 if (res == null) { |
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
623 res = window.prompt("Display resolution (dpi)", oldRes); |
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
624 } |
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
625 if (res != null) { |
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
626 data.settings.ddpi = res; |
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
627 redisplay(data); |
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
628 } |
753
8452a485e0e7
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
748
diff
changeset
|
629 }, |
768 | 630 |
754
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
631 // set image scale mode |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
632 setScaleMode : function (data, mode) { |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
633 var oldM = getScaleMode(data); |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
634 if (mode == null) { |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
635 mode = window.prompt("Image scale mode (screen, pixel, size)", oldM); |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
636 } |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
637 if (mode != null) { |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
638 setScaleMode(data, mode); |
756
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
639 data.scaleMode = mode; |
754
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
640 redisplay(data); |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
641 } |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
642 } |
768 | 643 |
756
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
644 // end of actions |
598 | 645 }; |
597 | 646 |
601 | 647 // returns parameters from page url |
600 | 648 var parseQueryParams = function() { |
629 | 649 return parseQueryString(window.location.search.slice(1)); |
650 }; | |
648 | 651 |
629 | 652 // returns parameters from embedded img-element |
600 | 653 var parseImgParams = function($elem) { |
606
d08d095430c3
keeping img tag for embedded mode seems to work now
robcast
parents:
605
diff
changeset
|
654 var src = $elem.find('img').first().attr('src'); |
703 | 655 if (!src) return null; |
600 | 656 var pos = src.indexOf('?'); |
657 var query = (pos < 0) ? '' : src.substring(pos + 1); | |
658 var scalerUrl = src.substring(0, pos); | |
620 | 659 var params = parseQueryString(query); |
660 params.scalerBaseUrl = scalerUrl; | |
661 return params; | |
629 | 662 }; |
600 | 663 |
601 | 664 // parses query parameter string into parameter object |
600 | 665 var parseQueryString = function(query) { |
694 | 666 var params = {}; |
667 if (query == null) return params; | |
600 | 668 var pairs = query.split("&"); |
629 | 669 //var keys = []; |
600 | 670 for (var i = 0; i < pairs.length; i++) { |
671 var pair = pairs[i].split("="); | |
672 if (pair.length === 2) { | |
620 | 673 params[pair[0]] = pair[1]; |
629 | 674 //keys.push(pair[0]); |
627 | 675 } |
629 | 676 } |
620 | 677 return params; |
629 | 678 }; |
661 | 679 |
636 | 680 // returns a query string from key names from a parameter hash (ignoring if the same value is in defaults) |
681 var getParamString = function (settings, keys, defaults) { | |
608 | 682 var paramString = ''; |
643 | 683 var nx = false; |
608 | 684 for (i = 0; i < keys.length; ++i) { |
685 var key = keys[i]; | |
656 | 686 if ((settings[key] != null) && ((defaults == null) || (settings[key] != defaults[key]))) { |
608 | 687 // first param gets no '&' |
643 | 688 if (nx) { |
689 paramString += '&'; | |
690 } else { | |
691 nx = true; | |
692 } | |
608 | 693 // add parm=val |
694 paramString += key + '=' + settings[key]; | |
636 | 695 } |
608 | 696 } |
697 return paramString; | |
624 | 698 }; |
699 | |
629 | 700 // returns URL and query string for Scaler |
701 var getScalerUrl = function (data) { | |
734 | 702 packParams(data); |
646 | 703 var settings = data.settings; |
645 | 704 if (settings.scalerBaseUrl == null) { |
705 alert("ERROR: URL of digilib Scaler servlet missing!"); | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
706 } |
629 | 707 var keys = settings.scalerParamNames; |
636 | 708 var queryString = getParamString(settings, keys, defaults); |
629 | 709 var url = settings.scalerBaseUrl + '?' + queryString; |
710 return url; | |
711 }; | |
712 | |
734 | 713 // returns URL for bird's eye view image |
788 | 714 var getBgImgUrl = function (data, moreParams) { |
734 | 715 var settings = data.settings; |
788 | 716 var bgOptions = { |
717 dw : settings.bgImgWidth, | |
718 dh : settings.bgImgHeight | |
734 | 719 }; |
788 | 720 var bgSettings = $.extend({}, settings, bgOptions); |
721 // filter scaler flags | |
722 if (bgSettings.mo != null) { | |
723 var mo = ''; | |
724 if (data.scalerFlags.hmir != null) { | |
725 mo += 'hmir,'; | |
760 | 726 } |
788 | 727 if (data.scalerFlags.vmir != null) { |
728 mo += 'vmir'; | |
729 } | |
730 bgSettings.mo = mo; | |
736 | 731 } |
788 | 732 var params = getParamString(bgSettings, settings.bgImgParams, defaults); |
736 | 733 var url = settings.scalerBaseUrl + '?' + params; |
734 | 734 return url; |
735 }; | |
738
bd283b2cdbbc
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
737
diff
changeset
|
736 |
629 | 737 // returns URL and query string for current digilib |
637
71cc855e2e4b
reload doesn't take list of changed parameters any more
robcast
parents:
636
diff
changeset
|
738 var getDigilibUrl = function (data) { |
636 | 739 packParams(data); |
629 | 740 var settings = data.settings; |
637
71cc855e2e4b
reload doesn't take list of changed parameters any more
robcast
parents:
636
diff
changeset
|
741 var queryString = getParamString(settings, settings.digilibParamNames, defaults); |
737 | 742 return settings.digilibBaseUrl + '?' + queryString; |
629 | 743 }; |
744 | |
790 | 745 // loads image information from digilib server via HTTP |
746 var loadImageInfo = function (data) { | |
747
5d3da97089bc
reading image info asynchronously works now. has just no use yet.
robcast
parents:
744
diff
changeset
|
747 var settings = data.settings; |
5d3da97089bc
reading image info asynchronously works now. has just no use yet.
robcast
parents:
744
diff
changeset
|
748 var p = settings.scalerBaseUrl.indexOf('/servlet/Scaler'); |
5d3da97089bc
reading image info asynchronously works now. has just no use yet.
robcast
parents:
744
diff
changeset
|
749 var url = settings.scalerBaseUrl.substring(0, p) + '/ImgInfo-json.jsp'; |
5d3da97089bc
reading image info asynchronously works now. has just no use yet.
robcast
parents:
744
diff
changeset
|
750 url += '?' + getParamString(settings, ['fn', 'pn'], defaults); |
760 | 751 // TODO: better error handling |
778 | 752 $.getJSON(url, function (json) { |
747
5d3da97089bc
reading image info asynchronously works now. has just no use yet.
robcast
parents:
744
diff
changeset
|
753 console.debug("got json data=", json); |
5d3da97089bc
reading image info asynchronously works now. has just no use yet.
robcast
parents:
744
diff
changeset
|
754 data.imgInfo = json; |
790 | 755 // send event |
756 $(data).trigger('imageInfo', [json]); | |
747
5d3da97089bc
reading image info asynchronously works now. has just no use yet.
robcast
parents:
744
diff
changeset
|
757 }); |
5d3da97089bc
reading image info asynchronously works now. has just no use yet.
robcast
parents:
744
diff
changeset
|
758 }; |
768 | 759 |
648 | 760 // processes some parameters into objects and stuff |
624 | 761 var unpackParams = function (data) { |
762 var settings = data.settings; | |
629 | 763 // zoom area |
624 | 764 var zoomArea = geom.rectangle(settings.wx, settings.wy, settings.ww, settings.wh); |
636 | 765 data.zoomArea = zoomArea; |
629 | 766 // marks |
624 | 767 var marks = []; |
643 | 768 if (settings.mk) { |
769 var mk = settings.mk; | |
770 if (mk.indexOf(";") >= 0) { | |
771 var pa = mk.split(";"); // old format with ";" | |
772 } else { | |
773 var pa = mk.split(","); // new format | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
774 } |
643 | 775 for (var i = 0; i < pa.length ; i++) { |
776 var pos = pa[i].split("/"); | |
777 if (pos.length > 1) { | |
778 marks.push(geom.position(pos[0], pos[1])); | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
779 } |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
780 } |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
781 } |
636 | 782 data.marks = marks; |
643 | 783 // mo (Scaler flags) |
784 var flags = {}; | |
785 if (settings.mo) { | |
786 var pa = settings.mo.split(","); | |
787 for (var i = 0; i < pa.length ; i++) { | |
788 flags[pa[i]] = pa[i]; | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
789 } |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
790 } |
643 | 791 data.scalerFlags = flags; |
756
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
792 data.scaleMode = getScaleMode(data); |
716 | 793 retrieveOptions(data); |
648 | 794 }; |
795 | |
815 | 796 // put area into parameters |
797 var packArea = function (settings, area) { | |
798 if (!area) return; | |
799 // zoom area | |
800 settings.wx = cropFloat(area.x); | |
801 settings.wy = cropFloat(area.y); | |
802 settings.ww = cropFloat(area.width); | |
803 settings.wh = cropFloat(area.height); | |
804 }; | |
805 | |
806 // put marks into parameters | |
807 var packMarks = function (settings, marks) { | |
808 if (!marks) return; | |
809 settings.mk = ''; | |
810 for (var i = 0; i < marks.length; i++) { | |
811 if (i) { | |
812 settings.mk += ','; | |
813 } | |
814 settings.mk += | |
815 cropFloatStr(marks[i].x) + '/' + | |
816 cropFloatStr(marks[i].y); | |
817 } | |
818 }; | |
819 | |
820 // pack scaler flags into parameters | |
821 var packScalerFlags = function (settings, flags) { | |
822 if (!flags) return; | |
823 var mo = ''; | |
824 for (var f in flags) { | |
825 if (mo) { | |
826 mo += ','; | |
827 } | |
828 mo += f; | |
829 } | |
830 settings.mo = mo; | |
831 }; | |
832 | |
624 | 833 // put objects back into parameters |
834 var packParams = function (data) { | |
835 var settings = data.settings; | |
815 | 836 packArea(settings, data.zoomArea); |
837 packMarks(settings, data.marks); | |
838 packScalerFlags(settings, data.scalerFlags); | |
839 // store user interface options in cookie | |
716 | 840 storeOptions(data); |
702 | 841 }; |
681 | 842 |
716 | 843 var storeOptions = function (data) { |
694 | 844 // save digilib options in cookie |
702 | 845 var settings = data.settings; |
846 if (data.dlOpts) { | |
847 // save digilib settings in options | |
848 data.dlOpts.birdview = settings.isBirdDivVisible ? 1 : 0; | |
849 data.dlOpts.buttons = settings.visibleButtonSets; | |
850 var clop = ''; | |
851 for (var o in data.dlOpts) { | |
852 if (clop) { | |
853 clop += '&'; | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
854 } |
702 | 855 clop += o + '=' + data.dlOpts[o]; |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
856 } |
778 | 857 if ($.cookie) { |
702 | 858 var ck = "digilib:fn:" + escape(settings.fn) + ":pn:" + settings.pn; |
859 console.debug("set cookie=", ck, " value=", clop); | |
778 | 860 $.cookie(ck, clop); |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
861 } |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
862 } |
778 | 863 if (settings.interactionMode !== 'fullscreen' && $.cookie) { |
720 | 864 // store normal parameters in cookie for embedded mode |
865 var qs = getParamString(settings, settings.digilibParamNames, defaults); | |
866 var ck = "digilib-embed:fn:" + escape(settings.fn) + ":pn:" + settings.pn; | |
867 console.debug("set cookie=", ck, " value=", qs); | |
778 | 868 $.cookie(ck, qs); |
720 | 869 } |
624 | 870 }; |
648 | 871 |
716 | 872 var retrieveOptions = function (data) { |
702 | 873 // clop (digilib options) |
874 var opts = {}; | |
875 var settings = data.settings; | |
778 | 876 if ($.cookie) { |
702 | 877 // read from cookie |
878 var ck = "digilib:fn:" + escape(settings.fn) + ":pn:" + settings.pn; | |
778 | 879 var cp = $.cookie(ck); |
702 | 880 console.debug("get cookie=", ck, " value=", cp); |
881 // in query string format | |
882 opts = parseQueryString(cp); | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
883 } |
702 | 884 data.dlOpts = opts; |
885 // birdview option | |
886 if (opts.birdview != null) { | |
887 settings.isBirdDivVisible = opts.birdview === '1'; | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
888 } |
702 | 889 // visible button sets |
890 if (opts.buttons != null) { | |
891 settings.visibleButtonSets = opts.buttons; | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
892 } |
704 | 893 }; |
702 | 894 |
615 | 895 // (re)load the img from a new scaler URL |
637
71cc855e2e4b
reload doesn't take list of changed parameters any more
robcast
parents:
636
diff
changeset
|
896 var redisplay = function (data) { |
629 | 897 var settings = data.settings; |
898 if (settings.interactionMode === 'fullscreen') { | |
899 // update location.href (browser URL) in fullscreen mode | |
637
71cc855e2e4b
reload doesn't take list of changed parameters any more
robcast
parents:
636
diff
changeset
|
900 var url = getDigilibUrl(data); |
629 | 901 var history = window.history; |
791
0ce8175f025a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
790
diff
changeset
|
902 if (typeof history.pushState === 'function') { |
0ce8175f025a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
790
diff
changeset
|
903 console.debug("faking reload to "+url); |
0ce8175f025a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
790
diff
changeset
|
904 // change url without reloading (stateObj, title, url) |
0ce8175f025a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
790
diff
changeset
|
905 history.pushState({}, '', url); |
0ce8175f025a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
790
diff
changeset
|
906 // change img src |
0ce8175f025a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
790
diff
changeset
|
907 var imgurl = getScalerUrl(data); |
0ce8175f025a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
790
diff
changeset
|
908 data.$img.attr('src', imgurl); |
0ce8175f025a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
790
diff
changeset
|
909 highlightButtons(data); |
0ce8175f025a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
790
diff
changeset
|
910 // send event |
0ce8175f025a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
790
diff
changeset
|
911 $(data).trigger('redisplay'); |
0ce8175f025a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
790
diff
changeset
|
912 } else { |
0ce8175f025a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
790
diff
changeset
|
913 // reload window |
0ce8175f025a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
790
diff
changeset
|
914 window.location = url; |
0ce8175f025a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
790
diff
changeset
|
915 } |
629 | 916 } else { |
917 // embedded mode -- just change img src | |
918 var url = getScalerUrl(data); | |
919 data.$img.attr('src', url); | |
758 | 920 highlightButtons(data); |
788 | 921 // send event |
922 $(data).trigger('redisplay'); | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
923 } |
615 | 924 }; |
925 | |
760 | 926 // update display (overlays etc.) |
927 var updateDisplay = function (data) { | |
928 updateImgTrafo(data); | |
929 renderMarks(data); | |
930 setupZoomDrag(data); | |
777 | 931 // send event |
932 $(data).trigger('update'); | |
760 | 933 }; |
768 | 934 |
655 | 935 // returns maximum size for scaler img in fullscreen mode |
771 | 936 var getFullscreenImgSize = function (data) { |
655 | 937 var $win = $(window); |
938 var winH = $win.height(); | |
772 | 939 var winW = $win.width(); |
940 var $body = $('body'); | |
773 | 941 // include standard body margins |
942 var borderW = $body.outerWidth(true) - $body.width(); | |
943 var borderH = $body.outerHeight(true) - $body.height(); | |
772 | 944 // get width of first button div |
945 var buttonsW = 0; | |
946 if (data.$buttonSets) { | |
947 buttonsW = data.$buttonSets[0].outerWidth(); | |
948 } | |
949 // account for left/right border, body margins and additional requirements | |
773 | 950 var calcW = winW - borderW - buttonsW - data.settings.scalerInset; |
951 var calcH = winH - borderH; | |
952 console.debug(winW, winH, 'winW:', $win.width(), 'border:', borderW, 'buttonsW:', buttonsW, 'calc:', calcW); | |
953 return geom.size(calcW, calcH); | |
655 | 954 }; |
955 | |
601 | 956 // creates HTML structure for digilib in elem |
620 | 957 var setupScalerDiv = function (data) { |
958 var settings = data.settings; | |
640 | 959 var $elem = data.$elem; |
718 | 960 $elem.addClass('digilib'); |
721 | 961 var $img; |
962 var scalerUrl; | |
601 | 963 if (settings.interactionMode === 'fullscreen') { |
721 | 964 // fullscreen |
718 | 965 $elem.addClass('dl_fullscreen'); |
771 | 966 var imgSize = getFullscreenImgSize(data); |
643 | 967 // fitwidth/height omits destination height/width |
721 | 968 if (data.dlOpts.fitheight == null) { |
643 | 969 settings.dw = imgSize.width; |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
970 } |
721 | 971 if (data.dlOpts.fitwidth == null) { |
643 | 972 settings.dh = imgSize.height; |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
973 } |
679 | 974 scalerUrl = getScalerUrl(data); |
721 | 975 $img = $('<img/>'); |
602 | 976 } else { |
721 | 977 // embedded mode -- try to keep img tag |
718 | 978 $elem.addClass('dl_embedded'); |
721 | 979 scalerUrl = getScalerUrl(data); |
616 | 980 $img = $elem.find('img'); |
606
d08d095430c3
keeping img tag for embedded mode seems to work now
robcast
parents:
605
diff
changeset
|
981 if ($img.length > 0) { |
721 | 982 oldUrl = $img.attr('src'); |
983 if (oldUrl === scalerUrl) { | |
984 console.debug("img detach:", $img); | |
985 $img.detach(); | |
986 } else { | |
987 $img = $('<img/>'); | |
988 } | |
606
d08d095430c3
keeping img tag for embedded mode seems to work now
robcast
parents:
605
diff
changeset
|
989 } else { |
d08d095430c3
keeping img tag for embedded mode seems to work now
robcast
parents:
605
diff
changeset
|
990 $img = $('<img/>'); |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
991 } |
601 | 992 } |
815 | 993 // create new inner html, keeping buttons and content marked with "keep" class |
994 $elem.contents(":not(.keep)").remove(); | |
606
d08d095430c3
keeping img tag for embedded mode seems to work now
robcast
parents:
605
diff
changeset
|
995 var $scaler = $('<div class="scaler"/>'); |
772 | 996 // scaler should be the first child element? |
997 $elem.prepend($scaler); | |
606
d08d095430c3
keeping img tag for embedded mode seems to work now
robcast
parents:
605
diff
changeset
|
998 $scaler.append($img); |
615 | 999 $img.addClass('pic'); |
642 | 1000 data.$scaler = $scaler; |
629 | 1001 data.$img = $img; |
680 | 1002 // setup image load handler before setting the src attribute (IE bug) |
1003 $img.load(scalerImgLoadedHandler(data)); | |
760 | 1004 $img.error(function () {console.error("error loading scaler image");}); |
680 | 1005 $img.attr('src', scalerUrl); |
601 | 1006 }; |
608 | 1007 |
603 | 1008 // creates HTML structure for buttons in elem |
690 | 1009 var createButtons = function (data, buttonSetIdx) { |
640 | 1010 var $elem = data.$elem; |
621
7f97716b901c
changed methods to pass "data" around instead of "settings"
robcast
parents:
620
diff
changeset
|
1011 var settings = data.settings; |
658 | 1012 var mode = settings.interactionMode; |
665
0d3d9517e448
image transform works now under rotation!!! (at least for multiples of 90deg)
robcast
parents:
664
diff
changeset
|
1013 var buttonSettings = settings.buttonSettings[mode]; |
675 | 1014 var buttonGroup = buttonSettings.buttonSets[buttonSetIdx]; |
683 | 1015 if (buttonGroup == null) { |
1016 // no buttons here | |
1017 return; | |
1018 } | |
815 | 1019 // button divs are marked with class "keep" |
1020 var $buttonsDiv = $('<div class="keep buttons"/>'); | |
675 | 1021 var buttonNames = buttonSettings[buttonGroup]; |
1022 for (var i = 0; i < buttonNames.length; i++) { | |
1023 var buttonName = buttonNames[i]; | |
1024 var buttonConfig = settings.buttons[buttonName]; | |
658 | 1025 // construct the button html |
1026 var $button = $('<div class="button"></div>'); | |
1027 var $a = $('<a/>'); | |
1028 var $img = $('<img class="button"/>'); | |
1029 $buttonsDiv.append($button); | |
1030 $button.append($a); | |
1031 $a.append($img); | |
1032 // add attributes and bindings | |
1033 $button.attr('title', buttonConfig.tooltip); | |
675 | 1034 $button.addClass('button-' + buttonName); |
658 | 1035 // create handler for the buttons |
1036 $a.bind('click.digilib', (function () { | |
1037 // we create a new closure to capture the value of action | |
1038 var action = buttonConfig.onclick; | |
1039 if ($.isArray(action)) { | |
1040 // the handler function calls digilib with action and parameters | |
1041 return function (evt) { | |
1042 console.debug('click action=', action, ' evt=', evt); | |
1043 $elem.digilib.apply($elem, action); | |
1044 return false; | |
1045 }; | |
1046 } else { | |
1047 // the handler function calls digilib with action | |
1048 return function (evt) { | |
1049 console.debug('click action=', action, ' evt=', evt); | |
1050 $elem.digilib(action); | |
1051 return false; | |
1052 }; | |
1053 } | |
1054 })()); | |
758 | 1055 $img.attr('src', buttonSettings.imagePath + buttonConfig.icon); |
683 | 1056 } |
655 | 1057 // make buttons div scroll if too large for window |
1058 if ($buttonsDiv.height() > $(window).height() - 10) { | |
1059 $buttonsDiv.css('position', 'absolute'); | |
1060 } | |
690 | 1061 // buttons hidden at first |
1062 $buttonsDiv.hide(); | |
1063 $elem.append($buttonsDiv); | |
675 | 1064 if (data.$buttonSets == null) { |
690 | 1065 // first button set |
675 | 1066 data.$buttonSets = [$buttonsDiv]; |
1067 } else { | |
683 | 1068 $elem.append($buttonsDiv); |
675 | 1069 data.$buttonSets[buttonSetIdx] = $buttonsDiv; |
1070 } | |
605 | 1071 return $buttonsDiv; |
603 | 1072 }; |
608 | 1073 |
849 | 1074 // creates arrow overlays for moving the zoomed area |
1075 var setupZoomArrows = function (data) { | |
1076 var $elem = data.$elem; | |
1077 var settings = data.settings; | |
1078 var show = settings.zoomArrows; | |
1079 console.log('zoom arrows:', show); | |
1080 if (!show) return; | |
1081 }; | |
1082 | |
618 | 1083 // creates HTML structure for the about view in elem |
621
7f97716b901c
changed methods to pass "data" around instead of "settings"
robcast
parents:
620
diff
changeset
|
1084 var setupAboutDiv = function (data) { |
640 | 1085 var $elem = data.$elem; |
621
7f97716b901c
changed methods to pass "data" around instead of "settings"
robcast
parents:
620
diff
changeset
|
1086 var settings = data.settings; |
618 | 1087 var $aboutDiv = $('<div class="about" style="display:none"/>'); |
609 | 1088 var $header = $('<p>Digilib Graphic Viewer</p>'); |
1089 var $link = $('<a/>'); | |
1090 var $logo = $('<img class="logo" title="digilib"/>'); | |
1091 var $content = $('<p/>'); | |
1092 $elem.append($aboutDiv); | |
1093 $aboutDiv.append($header); | |
1094 $aboutDiv.append($link); | |
1095 $aboutDiv.append($content); | |
1096 $link.append($logo); | |
1097 $logo.attr('src', settings.logoUrl); | |
628 | 1098 $link.attr('href', settings.homeUrl); |
609 | 1099 $content.text('Version: ' + settings.version); |
768 | 1100 data.$aboutDiv = $aboutDiv; |
628 | 1101 // click hides |
768 | 1102 $aboutDiv.bind('click.digilib', function () { |
1103 actions['showAboutDiv'](data, false); | |
703 | 1104 }); |
627 | 1105 }; |
1106 | |
628 | 1107 // shows some window e.g. 'about' (toggle visibility if show is null) |
1108 var showDiv = function (isVisible, $div, show) { | |
638 | 1109 if (show == null) { |
628 | 1110 // toggle visibility |
1111 isVisible = !isVisible; | |
1112 } else { | |
1113 // set visibility | |
1114 isVisible = show; | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1115 } |
628 | 1116 if (isVisible) { |
1117 $div.fadeIn(); | |
1118 } else { | |
1119 $div.fadeOut(); | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1120 } |
628 | 1121 return isVisible; |
627 | 1122 }; |
609 | 1123 |
690 | 1124 // display more (or less) button sets |
1125 var showButtons = function (data, more, setIdx, animated) { | |
704 | 1126 var atime = animated ? 'fast': 0; |
690 | 1127 if (more) { |
1128 // add set | |
1129 var $otherSets = data.$elem.find('div.buttons:visible'); | |
1130 var $set; | |
1131 if (data.$buttonSets && data.$buttonSets[setIdx]) { | |
1132 // set exists | |
1133 $set = data.$buttonSets[setIdx]; | |
1134 } else { | |
1135 $set = createButtons(data, setIdx); | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1136 } |
690 | 1137 if ($set == null) return false; |
758 | 1138 // include border in calculation |
1139 var btnWidth = $set.outerWidth(); | |
772 | 1140 // console.debug("btnWidth", btnWidth); |
690 | 1141 // move remaining sets left and show new set |
704 | 1142 if ($otherSets.length > 0) { |
1143 $otherSets.animate({right : '+='+btnWidth+'px'}, atime, | |
1144 function () {$set.show();}); | |
690 | 1145 } else { |
1146 $set.show(); | |
704 | 1147 } |
690 | 1148 } else { |
1149 // remove set | |
1150 var $set = data.$buttonSets[setIdx]; | |
1151 if ($set == null) return false; | |
772 | 1152 var btnWidth = $set.outerWidth(); |
690 | 1153 // hide last set |
1154 $set.hide(); | |
1155 // take remaining sets and move right | |
1156 var $otherSets = data.$elem.find('div.buttons:visible'); | |
704 | 1157 $otherSets.animate({right : '-='+btnWidth+'px'}, atime); |
1158 } | |
690 | 1159 return true; |
1160 }; | |
1161 | |
758 | 1162 // check for buttons to highlight |
1163 var highlightButtons = function (data, name, on) { | |
1164 var $buttons = data.$elem.find('div.buttons:visible'); // include hidden? | |
1165 // add a class for highlighted button | |
1166 var highlight = function (name, on) { | |
1167 var $button = $buttons.find('div.button-' + name); | |
1168 if (on) { | |
1169 $button.addClass('button-on'); | |
1170 } else { | |
1171 $button.removeClass('button-on'); | |
1172 } | |
1173 }; | |
1174 if (name != null) { | |
1175 return highlight(name, on); | |
1176 } | |
1177 var flags = data.scalerFlags; | |
1178 var settings = data.settings; | |
1179 highlight('rot', settings.rot); | |
1180 highlight('brgt', settings.brgt); | |
1181 highlight('cont', settings.cont); | |
1182 highlight('bird', settings.isBirdDivVisible); | |
1183 highlight('help', settings.isAboutDivVisible); | |
1184 highlight('hmir', flags.hmir); | |
1185 highlight('vmir', flags.vmir); | |
759 | 1186 highlight('quality', flags.q1 || flags.q2); |
758 | 1187 highlight('zoomin', ! isFullArea(data.zoomArea)); |
1188 }; | |
768 | 1189 |
651
2d85d820501d
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
649
diff
changeset
|
1190 // create Transform from area and $img |
765
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
1191 var getImgTrafo = function ($img, area, rot, hmir, vmir, mode, data) { |
651
2d85d820501d
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
649
diff
changeset
|
1192 var picrect = geom.rectangle($img); |
756
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
1193 if (mode != null) { |
765
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
1194 var imgInfo = data.imgInfo; |
756
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
1195 if (mode === 'pixel') { |
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
1196 // scaler mo=clip - image area size does not come from ww, wh |
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
1197 if (imgInfo != null) { |
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
1198 area.width = picrect.width / imgInfo.width; |
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
1199 area.height = picrect.height / imgInfo.height; |
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
1200 } else { |
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
1201 console.error("No image info for pixel mode!"); |
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
1202 } |
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
1203 } |
765
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
1204 if (mode === 'size') { |
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
1205 // scaler mo=osize - image area size does not come from ww, wh |
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
1206 if (imgInfo != null) { |
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
1207 var ddpi = parseFloat(data.settings.ddpi); |
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
1208 area.width = (picrect.width / ddpi) / (imgInfo.width / imgInfo.dpi_x); |
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
1209 area.height = (picrect.height / ddpi) / (imgInfo.height / imgInfo.dpi_y); |
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
1210 } else { |
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
1211 console.error("No image info for original size mode!"); |
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
1212 } |
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
1213 } |
756
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
1214 } |
651
2d85d820501d
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
649
diff
changeset
|
1215 var trafo = geom.transform(); |
668 | 1216 // move zoom area offset to center |
651
2d85d820501d
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
649
diff
changeset
|
1217 trafo.concat(trafo.getTranslation(geom.position(-area.x, -area.y))); |
668 | 1218 // scale zoom area size to [1,1] |
651
2d85d820501d
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
649
diff
changeset
|
1219 trafo.concat(trafo.getScale(geom.size(1/area.width, 1/area.height))); |
668 | 1220 // rotate and mirror (around transformed image center i.e. [0.5,0.5]) |
1221 if (rot || hmir || vmir) { | |
1222 // move [0.5,0.5] to center | |
1223 trafo.concat(trafo.getTranslation(geom.position(-0.5, -0.5))); | |
1224 if (hmir) { | |
1225 // mirror about center | |
1226 trafo.concat(trafo.getMirror('y')); | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1227 } |
668 | 1228 if (vmir) { |
1229 // mirror about center | |
1230 trafo.concat(trafo.getMirror('x')); | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1231 } |
668 | 1232 if (rot) { |
1233 // rotate around center | |
1234 trafo.concat(trafo.getRotation(parseFloat(rot))); | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1235 } |
668 | 1236 // move back |
1237 trafo.concat(trafo.getTranslation(geom.position(0.5, 0.5))); | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1238 } |
657
b0c6cc4a0932
work on getting transformation to work with rotation (currently still doesn't)
robcast
parents:
656
diff
changeset
|
1239 // scale to screen position and size |
651
2d85d820501d
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
649
diff
changeset
|
1240 trafo.concat(trafo.getScale(picrect)); |
2d85d820501d
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
649
diff
changeset
|
1241 trafo.concat(trafo.getTranslation(picrect)); |
2d85d820501d
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
649
diff
changeset
|
1242 return trafo; |
648 | 1243 }; |
671
ba582354e659
first step at dragging birdview zoom indicator around
hertzhaft
parents:
670
diff
changeset
|
1244 |
760 | 1245 // update scaler image transform |
1246 var updateImgTrafo = function (data) { | |
1247 var $img = data.$img; | |
1248 if ($img != null && $img.get(0).complete) { | |
753
8452a485e0e7
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
748
diff
changeset
|
1249 // create Transform from current zoomArea and image size |
668 | 1250 data.imgTrafo = getImgTrafo($img, data.zoomArea, |
756
8087657fc7bd
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
754
diff
changeset
|
1251 data.settings.rot, data.scalerFlags.hmir, data.scalerFlags.vmir, |
765
5c04652f3660
original size mode works with zoom area now. needs error handling.
robcast
parents:
762
diff
changeset
|
1252 data.scaleMode, data); |
753
8452a485e0e7
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
748
diff
changeset
|
1253 // console.debug("imgTrafo=", data.imgTrafo); |
760 | 1254 } |
1255 }; | |
768 | 1256 |
790 | 1257 // returns handler for load event of scaler img |
760 | 1258 var scalerImgLoadedHandler = function (data) { |
1259 return function () { | |
1260 var $img = $(this); | |
1261 console.debug("scaler img loaded=",$img); | |
1262 var $scaler = data.$scaler; | |
753
8452a485e0e7
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
748
diff
changeset
|
1263 var imgRect = geom.rectangle($img); |
726 | 1264 // adjust scaler div size |
731 | 1265 imgRect.adjustDiv($scaler); |
708 | 1266 // show image in case it was hidden (for example in zoomDrag) |
726 | 1267 $img.css('visibility', 'visible'); |
734 | 1268 $scaler.css({'opacity' : '1', 'background-image' : 'none'}); |
760 | 1269 // update display (render marks, etc.) |
1270 updateDisplay(data); | |
651
2d85d820501d
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
649
diff
changeset
|
1271 }; |
2d85d820501d
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
649
diff
changeset
|
1272 }; |
2d85d820501d
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
649
diff
changeset
|
1273 |
790 | 1274 // handler for imageInfo loaded event |
1275 var handleImageInfo = function (evt, json) { | |
1276 var data = this; | |
1277 updateDisplay(data); | |
1278 }; | |
806 | 1279 |
626 | 1280 // place marks on the image |
1281 var renderMarks = function (data) { | |
760 | 1282 if (data.$img == null || data.imgTrafo == null) return; |
843
76c23870ac0b
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
842
diff
changeset
|
1283 console.debug("renderMarks: img=",data.$img," imgtrafo=",data.imgTrafo); |
640 | 1284 var $elem = data.$elem; |
636 | 1285 var marks = data.marks; |
735
9969e01b37cf
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
734
diff
changeset
|
1286 // clear marks |
9969e01b37cf
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
734
diff
changeset
|
1287 $elem.find('div.mark').remove(); |
626 | 1288 for (var i = 0; i < marks.length; i++) { |
1289 var mark = marks[i]; | |
636 | 1290 if (data.zoomArea.containsPosition(mark)) { |
626 | 1291 var mpos = data.imgTrafo.transform(mark); |
844 | 1292 console.debug("renderMarks: pos=",mpos); |
626 | 1293 // create mark |
806 | 1294 var html = '<div class="mark overlay">'+(i+1)+'</div>'; |
626 | 1295 var $mark = $(html); |
843
76c23870ac0b
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
842
diff
changeset
|
1296 $mark.attr("id", "digilib-mark-"+(i+1)); |
626 | 1297 $elem.append($mark); |
735
9969e01b37cf
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
734
diff
changeset
|
1298 mpos.adjustDiv($mark); |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1299 } |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1300 } |
626 | 1301 }; |
648 | 1302 |
640 | 1303 // zooms by the given factor |
636 | 1304 var zoomBy = function(data, factor) { |
1305 var area = data.zoomArea; | |
1306 var newarea = area.copy(); | |
1307 // scale | |
1308 newarea.width /= factor; | |
1309 newarea.height /= factor; | |
1310 // and recenter | |
1311 newarea.x -= 0.5 * (newarea.width - area.width); | |
1312 newarea.y -= 0.5 * (newarea.height - area.height); | |
728
53584f90f66b
improved some embedded buttons; fixed reset function
hertzhaft
parents:
726
diff
changeset
|
1313 newarea = FULL_AREA.fit(newarea); |
636 | 1314 data.zoomArea = newarea; |
637
71cc855e2e4b
reload doesn't take list of changed parameters any more
robcast
parents:
636
diff
changeset
|
1315 redisplay(data); |
636 | 1316 }; |
1317 | |
640 | 1318 // add a mark where clicked |
1319 var setMark = function (data) { | |
642 | 1320 var $scaler = data.$scaler; |
735
9969e01b37cf
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
734
diff
changeset
|
1321 // unbind other handler |
9969e01b37cf
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
734
diff
changeset
|
1322 $scaler.unbind(".dlZoomDrag"); |
640 | 1323 // start event capturing |
735
9969e01b37cf
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
734
diff
changeset
|
1324 $scaler.one('mousedown.dlSetMark', function (evt) { |
640 | 1325 // event handler adding a new mark |
735
9969e01b37cf
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
734
diff
changeset
|
1326 console.log("setmark at=", evt); |
665
0d3d9517e448
image transform works now under rotation!!! (at least for multiples of 90deg)
robcast
parents:
664
diff
changeset
|
1327 var mpos = geom.position(evt); |
640 | 1328 var pos = data.imgTrafo.invtransform(mpos); |
1329 data.marks.push(pos); | |
1330 redisplay(data); | |
735
9969e01b37cf
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
734
diff
changeset
|
1331 return false; |
640 | 1332 }); |
1333 }; | |
661 | 1334 |
735
9969e01b37cf
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
734
diff
changeset
|
1335 // zoom to the area around two clicked points |
647 | 1336 var zoomArea = function(data) { |
1337 $elem = data.$elem; | |
1338 $scaler = data.$scaler; | |
1339 var pt1, pt2; | |
1340 var $zoomDiv = $('<div class="zoomrect" style="display:none"/>'); | |
1341 $elem.append($zoomDiv); | |
768 | 1342 // $zoomDiv.css(data.settings.zoomrectStyle); |
647 | 1343 var picRect = geom.rectangle($scaler); |
1344 // FIX ME: is there a way to query the border width from CSS info? | |
1345 // rect.x -= 2; // account for overlay borders | |
1346 // rect.y -= 2; | |
1347 | |
1348 var zoomStart = function (evt) { | |
1349 pt1 = geom.position(evt); | |
1350 // setup and show zoom div | |
731 | 1351 pt1.adjustDiv($zoomDiv); |
661 | 1352 $zoomDiv.width(0).height(0); |
647 | 1353 $zoomDiv.show(); |
1354 // register events | |
731 | 1355 $elem.bind("mousemove.dlZoomArea", zoomMove); |
1356 $elem.bind("mouseup.dlZoomArea", zoomEnd); | |
647 | 1357 return false; |
1358 }; | |
661 | 1359 |
734 | 1360 // mouse move handler |
1361 var zoomMove = function (evt) { | |
1362 pt2 = geom.position(evt); | |
1363 var rect = geom.rectangle(pt1, pt2); | |
1364 rect.clipTo(picRect); | |
1365 // update zoom div | |
1366 rect.adjustDiv($zoomDiv); | |
1367 return false; | |
1368 }; | |
738
bd283b2cdbbc
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
737
diff
changeset
|
1369 |
647 | 1370 // mouseup handler: end moving |
1371 var zoomEnd = function (evt) { | |
1372 pt2 = geom.position(evt); | |
1373 // assume a click and continue if the area is too small | |
1374 var clickRect = geom.rectangle(pt1, pt2); | |
703 | 1375 if (clickRect.getArea() <= 5) return false; |
647 | 1376 // hide zoom div |
1377 $zoomDiv.remove(); | |
1378 // unregister events | |
731 | 1379 $elem.unbind("mousemove.dlZoomArea", zoomMove); |
1380 $elem.unbind("mouseup.dlZoomArea", zoomEnd); | |
647 | 1381 // clip and transform |
1382 clickRect.clipTo(picRect); | |
1383 var area = data.imgTrafo.invtransform(clickRect); | |
1384 data.zoomArea = area; | |
1385 // zoomed is always fit | |
1386 data.settings.ws = 1; | |
731 | 1387 delete data.dlOpts.fitwidth; |
1388 delete data.dlOpts.fitheight; | |
647 | 1389 redisplay(data); |
1390 return false; | |
1391 }; | |
661 | 1392 |
735
9969e01b37cf
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
734
diff
changeset
|
1393 // clear old handler (also ZoomDrag) |
731 | 1394 $scaler.unbind('.dlZoomArea'); |
735
9969e01b37cf
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
734
diff
changeset
|
1395 $scaler.unbind(".dlZoomDrag"); |
731 | 1396 $elem.unbind('.dlZoomArea'); |
647 | 1397 // bind start zoom handler |
731 | 1398 $scaler.one('mousedown.dlZoomArea', zoomStart); |
647 | 1399 }; |
640 | 1400 |
739
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1401 // set zoom background |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1402 var setZoomBG = function(data) { |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1403 var $scaler = data.$scaler; |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1404 var $img = data.$img; |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1405 var fullRect = null; |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1406 // hide the scaler img, show background of div instead |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1407 $img.css('visibility', 'hidden'); |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1408 var scalerCss = { |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1409 'background-image' : 'url(' + $img.attr('src') + ')', |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1410 'background-repeat' : 'no-repeat', |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1411 'background-position' : 'left top', |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1412 'opacity' : '0.5', |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1413 'cursor' : 'move' |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1414 }; |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1415 if (data.hasBgSize) { |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1416 // full-size background using CSS3-background-size |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1417 fullRect = data.imgTrafo.transform(FULL_AREA); |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1418 if (fullRect.height < data.settings.maxBgSize && fullRect.width < data.settings.maxBgSize) { |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1419 // correct offset because background is relative |
744
78ed5b49259d
zoom-drag background follows birdZoom also in embedded mode (still imprecise)
hertzhaft
parents:
741
diff
changeset
|
1420 var scalerPos = geom.position($scaler); |
78ed5b49259d
zoom-drag background follows birdZoom also in embedded mode (still imprecise)
hertzhaft
parents:
741
diff
changeset
|
1421 fullRect.addPosition(scalerPos.neg()); |
788 | 1422 var url = getBgImgUrl(data); |
739
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1423 scalerCss['background-image'] = 'url(' + url + ')'; |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1424 scalerCss[data.bgSizeName] = fullRect.width + 'px ' + fullRect.height + 'px'; |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1425 scalerCss['background-position'] = fullRect.x + 'px '+ fullRect.y + 'px'; |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1426 } else { |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1427 // too big |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1428 fullRect = null; |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1429 } |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1430 } |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1431 $scaler.css(scalerCss); |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1432 // isBgReady = true; |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1433 return fullRect; |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1434 }; |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1435 |
731 | 1436 // setup handlers for dragging the zoomed image |
698 | 1437 var setupZoomDrag = function(data) { |
739
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1438 var startPos, delta, fullRect; |
726 | 1439 var $document = $(document); |
788 | 1440 var $data = $(data); |
698 | 1441 var $elem = data.$elem; |
1442 var $scaler = data.$scaler; | |
1443 var $img = data.$img; | |
703 | 1444 |
726 | 1445 // drag the image and load a new detail on mouse up |
698 | 1446 var dragStart = function (evt) { |
806 | 1447 console.debug("dragstart at=", evt); |
730
98a405711289
setup zoomdrag even when image is not initially zoomed
hertzhaft
parents:
729
diff
changeset
|
1448 // don't start dragging if not zoomed |
98a405711289
setup zoomdrag even when image is not initially zoomed
hertzhaft
parents:
729
diff
changeset
|
1449 if (isFullArea(data.zoomArea)) return false; |
806 | 1450 $elem.find(".overlay").hide(); // hide all overlays (marks/regions) |
726 | 1451 startPos = geom.position(evt); |
734 | 1452 delta = null; |
739
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1453 // set low res background immediately on mousedown |
58fcf8d8649f
move zoom-drag background along with birdview indicator
hertzhaft
parents:
738
diff
changeset
|
1454 fullRect = setZoomBG(data); |
726 | 1455 $document.bind("mousemove.dlZoomDrag", dragMove); |
1456 $document.bind("mouseup.dlZoomDrag", dragEnd); | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1457 return false; |
698 | 1458 }; |
738
bd283b2cdbbc
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
737
diff
changeset
|
1459 |
726 | 1460 // mousemove handler: drag zoomed image |
698 | 1461 var dragMove = function (evt) { |
1462 var pos = geom.position(evt); | |
734 | 1463 delta = startPos.delta(pos); |
1464 if (fullRect) { | |
1465 var bgPos = fullRect.getPosition().add(delta); | |
1466 } else { | |
1467 var bgPos = delta; | |
1468 } | |
698 | 1469 // move the background image to the new position |
708 | 1470 $scaler.css({ |
734 | 1471 'background-position' : bgPos.x + "px " + bgPos.y + "px" |
698 | 1472 }); |
800
ac1d6b056a6f
geometry: overlapsRect() plus some comment clarifications
hertzhaft
parents:
792
diff
changeset
|
1473 // send message event with current zoom position |
738
bd283b2cdbbc
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
737
diff
changeset
|
1474 var za = geom.rectangle($img); |
bd283b2cdbbc
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
737
diff
changeset
|
1475 za.addPosition(delta.neg()); |
788 | 1476 $data.trigger('dragZoom', [za]); |
1477 //TODO: setBirdZoom(data, za); | |
698 | 1478 return false; |
1479 }; | |
703 | 1480 |
726 | 1481 // mouseup handler: reload zoomed image in new position |
698 | 1482 var dragEnd = function (evt) { |
732 | 1483 $scaler.css('cursor', 'auto'); |
726 | 1484 $document.unbind("mousemove.dlZoomDrag", dragMove); |
1485 $document.unbind("mouseup.dlZoomDrag", dragEnd); | |
1486 if (delta == null || delta.distance() < 2) { | |
1487 // no movement | |
1488 $img.css('visibility', 'visible'); | |
734 | 1489 $scaler.css({'opacity' : '1', 'background-image' : 'none'}); |
760 | 1490 // unhide marks |
1491 data.$elem.find('div.mark').show(); | |
806 | 1492 $(data).trigger('redisplay'); |
726 | 1493 return false; |
1494 } | |
1495 // get old zoom area (screen coordinates) | |
734 | 1496 var za = geom.rectangle($img); |
726 | 1497 // move |
734 | 1498 za.addPosition(delta.neg()); |
726 | 1499 // transform back |
1500 var newArea = data.imgTrafo.invtransform(za); | |
728
53584f90f66b
improved some embedded buttons; fixed reset function
hertzhaft
parents:
726
diff
changeset
|
1501 data.zoomArea = FULL_AREA.fit(newArea); |
701
2660b733a1e7
img reload works for fullscreen, but somehow not precise
hertzhaft
parents:
700
diff
changeset
|
1502 redisplay(data); |
698 | 1503 return false; |
1504 }; | |
728
53584f90f66b
improved some embedded buttons; fixed reset function
hertzhaft
parents:
726
diff
changeset
|
1505 |
726 | 1506 // clear old handler |
1507 $document.unbind(".dlZoomDrag"); | |
734 | 1508 $scaler.unbind(".dlZoomDrag"); |
735
9969e01b37cf
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
734
diff
changeset
|
1509 if (! isFullArea(data.zoomArea)) { |
9969e01b37cf
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
734
diff
changeset
|
1510 // set handler |
9969e01b37cf
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
734
diff
changeset
|
1511 $scaler.bind("mousedown.dlZoomDrag", dragStart); |
9969e01b37cf
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
734
diff
changeset
|
1512 } |
698 | 1513 }; |
1514 | |
696 | 1515 // get image quality as a number (0..2) |
1516 var getQuality = function (data) { | |
1517 var flags = data.scalerFlags; | |
1518 var q = flags.q2 || flags.q1 || 'q0'; // assume q0 as default | |
1519 return parseInt(q[1], 10); | |
699 | 1520 }; |
696 | 1521 |
1522 // set image quality as a number (0..2) | |
1523 var setQuality = function (data, qual) { | |
1524 var flags = data.scalerFlags; | |
1525 // clear flags | |
1526 for (var i = 0; i < 3; ++i) { | |
1527 delete flags['q'+i]; | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1528 } |
696 | 1529 flags['q'+qual] = 'q'+qual; |
699 | 1530 }; |
703 | 1531 |
754
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1532 // get image scale mode (screen, pixel, size) |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1533 var getScaleMode = function (data) { |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1534 if (data.scalerFlags.clip != null) { |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1535 return 'pixel'; |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1536 } else if (data.scalerFlags.osize != null) { |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1537 return 'size'; |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1538 } |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1539 // mo=fit is default |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1540 return 'screen'; |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1541 }; |
768 | 1542 |
754
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1543 // set image scale mode (screen, pixel, size) |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1544 var setScaleMode = function (data, mode) { |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1545 delete data.scalerFlags.fit; |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1546 delete data.scalerFlags.clip; |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1547 delete data.scalerFlags.osize; |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1548 if (mode === 'pixel') { |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1549 data.scalerFlags.clip = 'clip'; |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1550 } else if (mode === 'size') { |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1551 data.scalerFlags.osize = 'osize'; |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1552 } |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1553 // mo=fit is default |
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1554 }; |
768 | 1555 |
754
17539f6838b6
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
753
diff
changeset
|
1556 // sets a key to a value (relative values with +/- if relative=true) |
643 | 1557 var setNumValue = function(settings, key, value) { |
709 | 1558 if (value == null) return null; |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1559 if (isNumber(value)) { |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1560 settings[key] = value; |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1561 return value; |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1562 } |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1563 var sign = value[0]; |
643 | 1564 if (sign === '+' || sign === '-') { |
1565 if (settings[key] == null) { | |
644
bffc7d8c3641
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
643
diff
changeset
|
1566 // this isn't perfect but still... |
643 | 1567 settings[key] = 0; |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1568 } |
643 | 1569 settings[key] = parseFloat(settings[key]) + parseFloat(value); |
1570 } else { | |
1571 settings[key] = value; | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1572 } |
643 | 1573 return settings[key]; |
1574 }; | |
648 | 1575 |
768 | 1576 // auxiliary function, assuming equal border width on all sides |
1577 var getBorderWidth = function($elem) { | |
1578 var border = $elem.outerWidth() - $elem.width(); | |
1579 return border/2; | |
1580 }; | |
1581 | |
648 | 1582 // auxiliary function (from old dllib.js) |
788 | 1583 var isFullArea = function (area) { |
652 | 1584 return (area.width === 1.0) && (area.height === 1.0); |
648 | 1585 }; |
1586 | |
634 | 1587 // auxiliary function (from Douglas Crockford, A.10) |
788 | 1588 var isNumber = function (value) { |
703 | 1589 return typeof value === 'number' && isFinite(value); |
634 | 1590 }; |
648 | 1591 |
624 | 1592 // auxiliary function to crop senseless precision |
1593 var cropFloat = function (x) { | |
630 | 1594 return parseInt(10000 * x, 10) / 10000; |
624 | 1595 }; |
648 | 1596 |
806 | 1597 // idem, string version |
1598 var cropFloatStr = function (x) { | |
1599 return cropFloat(x).toString(); | |
1600 }; | |
1601 | |
685 | 1602 // fallback for console.log calls |
1603 if (customConsole) { | |
1604 var logFunction = function(type) { | |
1605 return function(){ | |
1606 var $debug = $('#debug'); // debug div | |
1607 if (!$debug) return; | |
1608 var args = Array.prototype.slice.call(arguments); | |
1609 var argtext = args.join(' '); | |
1610 var $logDiv = $('<div/>'); | |
1611 $logDiv.addClass(type); | |
1612 $logDiv.text(argtext); | |
1613 $debug.append($logDiv); | |
1614 }; | |
1615 }; | |
1616 console.log = logFunction('_log'); | |
1617 console.debug = logFunction('_debug'); | |
1618 console.error = logFunction('_error'); | |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1619 } |
685 | 1620 |
780 | 1621 // functions to export to plugins |
1622 fn = { | |
784 | 1623 geometry : geom, |
780 | 1624 parseQueryString : parseQueryString, |
1625 getScalerUrl : getScalerUrl, | |
1626 getParamString : getParamString, | |
1627 getDigilibUrl : getDigilibUrl, | |
1628 unpackParams : unpackParams, | |
1629 packParams : packParams, | |
815 | 1630 packArea : packArea, |
1631 packMarks : packMarks, | |
1632 packScalerFlags : packScalerFlags, | |
788 | 1633 storeOptions : storeOptions, |
780 | 1634 redisplay : redisplay, |
1635 updateDisplay : updateDisplay, | |
788 | 1636 highlightButtons : highlightButtons, |
784 | 1637 showDiv : showDiv, |
788 | 1638 setZoomBG : setZoomBG, |
780 | 1639 getImgTrafo : getImgTrafo, |
1640 getQuality : getQuality, | |
1641 setQuality : setQuality, | |
1642 getScaleMode : getScaleMode, | |
1643 setScaleMode : setScaleMode, | |
788 | 1644 isFullArea : isFullArea, |
806 | 1645 isNumber : isNumber, |
1646 getBorderWidth : getBorderWidth, | |
1647 cropFloat : cropFloat, | |
1648 cropFloatStr : cropFloatStr | |
780 | 1649 }; |
781 | 1650 |
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
791
diff
changeset
|
1651 // hook digilib plugin into jquery |
778 | 1652 $.fn.digilib = function (action) { |
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
791
diff
changeset
|
1653 // plugin extension mechanism, called when the plugins' code is read |
779 | 1654 if (action === 'plugin') { |
1655 var plugin = arguments[1]; | |
1656 // each plugin needs a name | |
1657 if (plugin.name != null) { | |
1658 plugins[plugin.name] = plugin; | |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
1659 // share common objects |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
1660 plugin.defaults = defaults; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
1661 plugin.buttons = buttons; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
1662 plugin.actions = actions; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
1663 plugin.fn = fn; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
1664 plugin.plugins = plugins; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
1665 // and install |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
1666 if (typeof plugin.install === 'function') { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
1667 plugin.install(plugin); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
1668 } |
779 | 1669 } |
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
791
diff
changeset
|
1670 // plugins will be initialised when action.init is called |
753
8452a485e0e7
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
748
diff
changeset
|
1671 } else if (actions[action]) { |
644
bffc7d8c3641
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
643
diff
changeset
|
1672 // call action on this with the remaining arguments (inserting data as first argument) |
bffc7d8c3641
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
643
diff
changeset
|
1673 var $elem = $(this); |
bffc7d8c3641
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
643
diff
changeset
|
1674 var data = $elem.data('digilib'); |
bffc7d8c3641
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
643
diff
changeset
|
1675 var args = Array.prototype.slice.call(arguments, 1); |
bffc7d8c3641
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
643
diff
changeset
|
1676 args.unshift(data); |
bffc7d8c3641
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
643
diff
changeset
|
1677 return actions[action].apply(this, args); |
791
0ce8175f025a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
790
diff
changeset
|
1678 } else if (typeof action === 'object' || !action) { |
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
791
diff
changeset
|
1679 // call init on the digilib jQuery object |
644
bffc7d8c3641
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
643
diff
changeset
|
1680 return actions.init.apply(this, arguments); |
598 | 1681 } else { |
706
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1682 $.error('action ' + action + ' does not exist on jQuery.digilib'); |
498f9c7487ae
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
704
diff
changeset
|
1683 } |
598 | 1684 }; |
685 | 1685 |
597 | 1686 })(jQuery); |