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