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