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