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