Mercurial > hg > digilib-old
annotate client/digitallibrary/jquery/jquery.digilib.js @ 798:b07d1824ca2a jquery
fullscreen mode works without reload on browsers supporting history.pushstate!
author | robcast |
---|---|
date | Fri, 18 Feb 2011 20:09:15 +0100 |
parents | 6914ddedaca7 |
children | 12f790cb30de |
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 } |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
794 settings.mk += cropFloat(data.marks[i].x).toString() + |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
795 '/' + cropFloat(data.marks[i].y).toString(); |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
796 } |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
797 } |
650 | 798 // Scaler flags |
799 if (data.scalerFlags) { | |
800 var mo = ''; | |
801 for (var f in data.scalerFlags) { | |
802 if (mo) { | |
803 mo += ','; | |
804 } | |
805 mo += f; | |
806 } | |
807 settings.mo = mo; | |
808 } | |
710 | 809 // user interface options |
723 | 810 storeOptions(data); |
709 | 811 }; |
688 | 812 |
723 | 813 var storeOptions = function (data) { |
701 | 814 // save digilib options in cookie |
709 | 815 var settings = data.settings; |
816 if (data.dlOpts) { | |
817 // save digilib settings in options | |
818 data.dlOpts.birdview = settings.isBirdDivVisible ? 1 : 0; | |
819 data.dlOpts.buttons = settings.visibleButtonSets; | |
820 var clop = ''; | |
821 for (var o in data.dlOpts) { | |
822 if (clop) { | |
823 clop += '&'; | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
824 } |
709 | 825 clop += o + '=' + data.dlOpts[o]; |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
826 } |
785 | 827 if ($.cookie) { |
709 | 828 var ck = "digilib:fn:" + escape(settings.fn) + ":pn:" + settings.pn; |
829 console.debug("set cookie=", ck, " value=", clop); | |
785 | 830 $.cookie(ck, clop); |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
831 } |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
832 } |
785 | 833 if (settings.interactionMode !== 'fullscreen' && $.cookie) { |
727 | 834 // store normal parameters in cookie for embedded mode |
835 var qs = getParamString(settings, settings.digilibParamNames, defaults); | |
836 var ck = "digilib-embed:fn:" + escape(settings.fn) + ":pn:" + settings.pn; | |
837 console.debug("set cookie=", ck, " value=", qs); | |
785 | 838 $.cookie(ck, qs); |
727 | 839 } |
631 | 840 }; |
655 | 841 |
723 | 842 var retrieveOptions = function (data) { |
709 | 843 // clop (digilib options) |
844 var opts = {}; | |
845 var settings = data.settings; | |
785 | 846 if ($.cookie) { |
709 | 847 // read from cookie |
848 var ck = "digilib:fn:" + escape(settings.fn) + ":pn:" + settings.pn; | |
785 | 849 var cp = $.cookie(ck); |
709 | 850 console.debug("get cookie=", ck, " value=", cp); |
851 // in query string format | |
852 opts = parseQueryString(cp); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
853 } |
709 | 854 data.dlOpts = opts; |
855 // birdview option | |
856 if (opts.birdview != null) { | |
857 settings.isBirdDivVisible = opts.birdview === '1'; | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
858 } |
709 | 859 // visible button sets |
860 if (opts.buttons != null) { | |
861 settings.visibleButtonSets = opts.buttons; | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
862 } |
711 | 863 }; |
709 | 864 |
622 | 865 // (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
|
866 var redisplay = function (data) { |
636 | 867 var settings = data.settings; |
868 if (settings.interactionMode === 'fullscreen') { | |
869 // 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
|
870 var url = getDigilibUrl(data); |
636 | 871 var history = window.history; |
798
b07d1824ca2a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
797
diff
changeset
|
872 if (typeof history.pushState === 'function') { |
b07d1824ca2a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
797
diff
changeset
|
873 console.debug("faking reload to "+url); |
b07d1824ca2a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
797
diff
changeset
|
874 // change url without reloading (stateObj, title, url) |
b07d1824ca2a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
797
diff
changeset
|
875 history.pushState({}, '', url); |
b07d1824ca2a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
797
diff
changeset
|
876 // change img src |
b07d1824ca2a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
797
diff
changeset
|
877 var imgurl = getScalerUrl(data); |
b07d1824ca2a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
797
diff
changeset
|
878 data.$img.attr('src', imgurl); |
b07d1824ca2a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
797
diff
changeset
|
879 highlightButtons(data); |
b07d1824ca2a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
797
diff
changeset
|
880 // send event |
b07d1824ca2a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
797
diff
changeset
|
881 $(data).trigger('redisplay'); |
b07d1824ca2a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
797
diff
changeset
|
882 } else { |
b07d1824ca2a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
797
diff
changeset
|
883 // reload window |
b07d1824ca2a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
797
diff
changeset
|
884 window.location = url; |
b07d1824ca2a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
797
diff
changeset
|
885 } |
636 | 886 } else { |
887 // embedded mode -- just change img src | |
888 var url = getScalerUrl(data); | |
889 data.$img.attr('src', url); | |
765 | 890 highlightButtons(data); |
795 | 891 // send event |
892 $(data).trigger('redisplay'); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
893 } |
622 | 894 }; |
895 | |
767 | 896 // update display (overlays etc.) |
897 var updateDisplay = function (data) { | |
898 updateImgTrafo(data); | |
899 renderMarks(data); | |
900 setupZoomDrag(data); | |
784 | 901 // send event |
902 $(data).trigger('update'); | |
767 | 903 }; |
775 | 904 |
662 | 905 // returns maximum size for scaler img in fullscreen mode |
778 | 906 var getFullscreenImgSize = function (data) { |
662 | 907 var $win = $(window); |
908 var winH = $win.height(); | |
779 | 909 var winW = $win.width(); |
910 var $body = $('body'); | |
780 | 911 // include standard body margins |
912 var borderW = $body.outerWidth(true) - $body.width(); | |
913 var borderH = $body.outerHeight(true) - $body.height(); | |
779 | 914 // get width of first button div |
915 var buttonsW = 0; | |
916 if (data.$buttonSets) { | |
917 buttonsW = data.$buttonSets[0].outerWidth(); | |
918 } | |
919 // account for left/right border, body margins and additional requirements | |
780 | 920 var calcW = winW - borderW - buttonsW - data.settings.scalerInset; |
921 var calcH = winH - borderH; | |
922 console.debug(winW, winH, 'winW:', $win.width(), 'border:', borderW, 'buttonsW:', buttonsW, 'calc:', calcW); | |
923 return geom.size(calcW, calcH); | |
662 | 924 }; |
925 | |
608 | 926 // creates HTML structure for digilib in elem |
627 | 927 var setupScalerDiv = function (data) { |
928 var settings = data.settings; | |
647 | 929 var $elem = data.$elem; |
725 | 930 $elem.addClass('digilib'); |
728 | 931 var $img; |
932 var scalerUrl; | |
608 | 933 if (settings.interactionMode === 'fullscreen') { |
728 | 934 // fullscreen |
725 | 935 $elem.addClass('dl_fullscreen'); |
778 | 936 var imgSize = getFullscreenImgSize(data); |
650 | 937 // fitwidth/height omits destination height/width |
728 | 938 if (data.dlOpts.fitheight == null) { |
650 | 939 settings.dw = imgSize.width; |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
940 } |
728 | 941 if (data.dlOpts.fitwidth == null) { |
650 | 942 settings.dh = imgSize.height; |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
943 } |
686 | 944 scalerUrl = getScalerUrl(data); |
728 | 945 $img = $('<img/>'); |
609 | 946 } else { |
728 | 947 // embedded mode -- try to keep img tag |
725 | 948 $elem.addClass('dl_embedded'); |
728 | 949 scalerUrl = getScalerUrl(data); |
623 | 950 $img = $elem.find('img'); |
613
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
951 if ($img.length > 0) { |
728 | 952 oldUrl = $img.attr('src'); |
953 if (oldUrl === scalerUrl) { | |
954 console.debug("img detach:", $img); | |
955 $img.detach(); | |
956 } else { | |
957 $img = $('<img/>'); | |
958 } | |
613
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
959 } else { |
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
960 $img = $('<img/>'); |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
961 } |
608 | 962 } |
779 | 963 // create new inner html, keep buttons |
964 $elem.contents(":not(div.buttons)").remove(); | |
613
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
965 var $scaler = $('<div class="scaler"/>'); |
779 | 966 // scaler should be the first child element? |
967 $elem.prepend($scaler); | |
613
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
968 $scaler.append($img); |
622 | 969 $img.addClass('pic'); |
649 | 970 data.$scaler = $scaler; |
636 | 971 data.$img = $img; |
687 | 972 // setup image load handler before setting the src attribute (IE bug) |
973 $img.load(scalerImgLoadedHandler(data)); | |
767 | 974 $img.error(function () {console.error("error loading scaler image");}); |
687 | 975 $img.attr('src', scalerUrl); |
608 | 976 }; |
615 | 977 |
610 | 978 // creates HTML structure for buttons in elem |
697 | 979 var createButtons = function (data, buttonSetIdx) { |
647 | 980 var $elem = data.$elem; |
628
1f077f8afc5e
changed methods to pass "data" around instead of "settings"
robcast
parents:
627
diff
changeset
|
981 var settings = data.settings; |
665 | 982 var mode = settings.interactionMode; |
672
7f7536a5b6d9
image transform works now under rotation!!! (at least for multiples of 90deg)
robcast
parents:
671
diff
changeset
|
983 var buttonSettings = settings.buttonSettings[mode]; |
682 | 984 var buttonGroup = buttonSettings.buttonSets[buttonSetIdx]; |
690 | 985 if (buttonGroup == null) { |
986 // no buttons here | |
987 return; | |
988 } | |
989 var $buttonsDiv = $('<div class="buttons"/>'); | |
682 | 990 var buttonNames = buttonSettings[buttonGroup]; |
991 for (var i = 0; i < buttonNames.length; i++) { | |
992 var buttonName = buttonNames[i]; | |
993 var buttonConfig = settings.buttons[buttonName]; | |
665 | 994 // construct the button html |
995 var $button = $('<div class="button"></div>'); | |
996 var $a = $('<a/>'); | |
997 var $img = $('<img class="button"/>'); | |
998 $buttonsDiv.append($button); | |
999 $button.append($a); | |
1000 $a.append($img); | |
1001 // add attributes and bindings | |
1002 $button.attr('title', buttonConfig.tooltip); | |
682 | 1003 $button.addClass('button-' + buttonName); |
665 | 1004 // create handler for the buttons |
1005 $a.bind('click.digilib', (function () { | |
1006 // we create a new closure to capture the value of action | |
1007 var action = buttonConfig.onclick; | |
1008 if ($.isArray(action)) { | |
1009 // the handler function calls digilib with action and parameters | |
1010 return function (evt) { | |
1011 console.debug('click action=', action, ' evt=', evt); | |
1012 $elem.digilib.apply($elem, action); | |
1013 return false; | |
1014 }; | |
1015 } else { | |
1016 // the handler function calls digilib with action | |
1017 return function (evt) { | |
1018 console.debug('click action=', action, ' evt=', evt); | |
1019 $elem.digilib(action); | |
1020 return false; | |
1021 }; | |
1022 } | |
1023 })()); | |
765 | 1024 $img.attr('src', buttonSettings.imagePath + buttonConfig.icon); |
690 | 1025 } |
662 | 1026 // make buttons div scroll if too large for window |
1027 if ($buttonsDiv.height() > $(window).height() - 10) { | |
1028 $buttonsDiv.css('position', 'absolute'); | |
1029 } | |
697 | 1030 // buttons hidden at first |
1031 $buttonsDiv.hide(); | |
1032 $elem.append($buttonsDiv); | |
682 | 1033 if (data.$buttonSets == null) { |
697 | 1034 // first button set |
682 | 1035 data.$buttonSets = [$buttonsDiv]; |
1036 } else { | |
690 | 1037 $elem.append($buttonsDiv); |
682 | 1038 data.$buttonSets[buttonSetIdx] = $buttonsDiv; |
1039 } | |
612 | 1040 return $buttonsDiv; |
610 | 1041 }; |
615 | 1042 |
625 | 1043 // 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
|
1044 var setupAboutDiv = function (data) { |
647 | 1045 var $elem = data.$elem; |
628
1f077f8afc5e
changed methods to pass "data" around instead of "settings"
robcast
parents:
627
diff
changeset
|
1046 var settings = data.settings; |
625 | 1047 var $aboutDiv = $('<div class="about" style="display:none"/>'); |
616 | 1048 var $header = $('<p>Digilib Graphic Viewer</p>'); |
1049 var $link = $('<a/>'); | |
1050 var $logo = $('<img class="logo" title="digilib"/>'); | |
1051 var $content = $('<p/>'); | |
1052 $elem.append($aboutDiv); | |
1053 $aboutDiv.append($header); | |
1054 $aboutDiv.append($link); | |
1055 $aboutDiv.append($content); | |
1056 $link.append($logo); | |
1057 $logo.attr('src', settings.logoUrl); | |
635 | 1058 $link.attr('href', settings.homeUrl); |
616 | 1059 $content.text('Version: ' + settings.version); |
775 | 1060 data.$aboutDiv = $aboutDiv; |
635 | 1061 // click hides |
775 | 1062 $aboutDiv.bind('click.digilib', function () { |
1063 actions['showAboutDiv'](data, false); | |
710 | 1064 }); |
634 | 1065 }; |
1066 | |
635 | 1067 // shows some window e.g. 'about' (toggle visibility if show is null) |
1068 var showDiv = function (isVisible, $div, show) { | |
645 | 1069 if (show == null) { |
635 | 1070 // toggle visibility |
1071 isVisible = !isVisible; | |
1072 } else { | |
1073 // set visibility | |
1074 isVisible = show; | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1075 } |
635 | 1076 if (isVisible) { |
1077 $div.fadeIn(); | |
1078 } else { | |
1079 $div.fadeOut(); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1080 } |
635 | 1081 return isVisible; |
634 | 1082 }; |
616 | 1083 |
697 | 1084 // display more (or less) button sets |
1085 var showButtons = function (data, more, setIdx, animated) { | |
711 | 1086 var atime = animated ? 'fast': 0; |
697 | 1087 if (more) { |
1088 // add set | |
1089 var $otherSets = data.$elem.find('div.buttons:visible'); | |
1090 var $set; | |
1091 if (data.$buttonSets && data.$buttonSets[setIdx]) { | |
1092 // set exists | |
1093 $set = data.$buttonSets[setIdx]; | |
1094 } else { | |
1095 $set = createButtons(data, setIdx); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1096 } |
697 | 1097 if ($set == null) return false; |
765 | 1098 // include border in calculation |
1099 var btnWidth = $set.outerWidth(); | |
779 | 1100 // console.debug("btnWidth", btnWidth); |
697 | 1101 // move remaining sets left and show new set |
711 | 1102 if ($otherSets.length > 0) { |
1103 $otherSets.animate({right : '+='+btnWidth+'px'}, atime, | |
1104 function () {$set.show();}); | |
697 | 1105 } else { |
1106 $set.show(); | |
711 | 1107 } |
697 | 1108 } else { |
1109 // remove set | |
1110 var $set = data.$buttonSets[setIdx]; | |
1111 if ($set == null) return false; | |
779 | 1112 var btnWidth = $set.outerWidth(); |
697 | 1113 // hide last set |
1114 $set.hide(); | |
1115 // take remaining sets and move right | |
1116 var $otherSets = data.$elem.find('div.buttons:visible'); | |
711 | 1117 $otherSets.animate({right : '-='+btnWidth+'px'}, atime); |
1118 } | |
697 | 1119 return true; |
1120 }; | |
1121 | |
765 | 1122 // check for buttons to highlight |
1123 var highlightButtons = function (data, name, on) { | |
1124 var $buttons = data.$elem.find('div.buttons:visible'); // include hidden? | |
1125 // add a class for highlighted button | |
1126 var highlight = function (name, on) { | |
1127 var $button = $buttons.find('div.button-' + name); | |
1128 if (on) { | |
1129 $button.addClass('button-on'); | |
1130 } else { | |
1131 $button.removeClass('button-on'); | |
1132 } | |
1133 }; | |
1134 if (name != null) { | |
1135 return highlight(name, on); | |
1136 } | |
1137 var flags = data.scalerFlags; | |
1138 var settings = data.settings; | |
1139 highlight('rot', settings.rot); | |
1140 highlight('brgt', settings.brgt); | |
1141 highlight('cont', settings.cont); | |
1142 highlight('bird', settings.isBirdDivVisible); | |
1143 highlight('help', settings.isAboutDivVisible); | |
1144 highlight('hmir', flags.hmir); | |
1145 highlight('vmir', flags.vmir); | |
766 | 1146 highlight('quality', flags.q1 || flags.q2); |
765 | 1147 highlight('zoomin', ! isFullArea(data.zoomArea)); |
1148 }; | |
775 | 1149 |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1150 // create Transform from area and $img |
772
33b5477f8d84
original size mode works with zoom area now. needs error handling.
robcast
parents:
769
diff
changeset
|
1151 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
|
1152 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
|
1153 if (mode != null) { |
772
33b5477f8d84
original size mode works with zoom area now. needs error handling.
robcast
parents:
769
diff
changeset
|
1154 var imgInfo = data.imgInfo; |
763
31664707999e
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
761
diff
changeset
|
1155 if (mode === 'pixel') { |
31664707999e
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
761
diff
changeset
|
1156 // 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
|
1157 if (imgInfo != null) { |
31664707999e
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
761
diff
changeset
|
1158 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
|
1159 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
|
1160 } else { |
31664707999e
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
761
diff
changeset
|
1161 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
|
1162 } |
31664707999e
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
761
diff
changeset
|
1163 } |
772
33b5477f8d84
original size mode works with zoom area now. needs error handling.
robcast
parents:
769
diff
changeset
|
1164 if (mode === 'size') { |
33b5477f8d84
original size mode works with zoom area now. needs error handling.
robcast
parents:
769
diff
changeset
|
1165 // 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
|
1166 if (imgInfo != null) { |
33b5477f8d84
original size mode works with zoom area now. needs error handling.
robcast
parents:
769
diff
changeset
|
1167 var ddpi = parseFloat(data.settings.ddpi); |
33b5477f8d84
original size mode works with zoom area now. needs error handling.
robcast
parents:
769
diff
changeset
|
1168 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
|
1169 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
|
1170 } else { |
33b5477f8d84
original size mode works with zoom area now. needs error handling.
robcast
parents:
769
diff
changeset
|
1171 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
|
1172 } |
33b5477f8d84
original size mode works with zoom area now. needs error handling.
robcast
parents:
769
diff
changeset
|
1173 } |
763
31664707999e
pixel-by-pixel scale mode works with zoom area. (not in all cases)
robcast
parents:
761
diff
changeset
|
1174 } |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1175 var trafo = geom.transform(); |
675 | 1176 // 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
|
1177 trafo.concat(trafo.getTranslation(geom.position(-area.x, -area.y))); |
675 | 1178 // 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
|
1179 trafo.concat(trafo.getScale(geom.size(1/area.width, 1/area.height))); |
675 | 1180 // rotate and mirror (around transformed image center i.e. [0.5,0.5]) |
1181 if (rot || hmir || vmir) { | |
1182 // move [0.5,0.5] to center | |
1183 trafo.concat(trafo.getTranslation(geom.position(-0.5, -0.5))); | |
1184 if (hmir) { | |
1185 // mirror about center | |
1186 trafo.concat(trafo.getMirror('y')); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1187 } |
675 | 1188 if (vmir) { |
1189 // mirror about center | |
1190 trafo.concat(trafo.getMirror('x')); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1191 } |
675 | 1192 if (rot) { |
1193 // rotate around center | |
1194 trafo.concat(trafo.getRotation(parseFloat(rot))); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1195 } |
675 | 1196 // move back |
1197 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
|
1198 } |
664
d5a5ee4cbf04
work on getting transformation to work with rotation (currently still doesn't)
robcast
parents:
663
diff
changeset
|
1199 // 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
|
1200 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
|
1201 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
|
1202 return trafo; |
655 | 1203 }; |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1204 |
767 | 1205 // update scaler image transform |
1206 var updateImgTrafo = function (data) { | |
1207 var $img = data.$img; | |
1208 if ($img != null && $img.get(0).complete) { | |
760
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1209 // create Transform from current zoomArea and image size |
675 | 1210 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
|
1211 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
|
1212 data.scaleMode, data); |
760
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1213 // console.debug("imgTrafo=", data.imgTrafo); |
767 | 1214 } |
1215 }; | |
775 | 1216 |
797 | 1217 // returns handler for load event of scaler img |
767 | 1218 var scalerImgLoadedHandler = function (data) { |
1219 return function () { | |
1220 var $img = $(this); | |
1221 console.debug("scaler img loaded=",$img); | |
1222 var $scaler = data.$scaler; | |
760
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1223 var imgRect = geom.rectangle($img); |
733 | 1224 // adjust scaler div size |
738 | 1225 imgRect.adjustDiv($scaler); |
715 | 1226 // show image in case it was hidden (for example in zoomDrag) |
733 | 1227 $img.css('visibility', 'visible'); |
741 | 1228 $scaler.css({'opacity' : '1', 'background-image' : 'none'}); |
767 | 1229 // update display (render marks, etc.) |
1230 updateDisplay(data); | |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1231 }; |
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 |
797 | 1234 // handler for imageInfo loaded event |
1235 var handleImageInfo = function (evt, json) { | |
1236 var data = this; | |
1237 updateDisplay(data); | |
1238 }; | |
1239 | |
633 | 1240 // place marks on the image |
1241 var renderMarks = function (data) { | |
767 | 1242 if (data.$img == null || data.imgTrafo == null) return; |
1243 console.debug("rendermarks img=",data.$img," imgtrafo=",data.imgTrafo); | |
647 | 1244 var $elem = data.$elem; |
643 | 1245 var marks = data.marks; |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1246 // clear marks |
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1247 $elem.find('div.mark').remove(); |
633 | 1248 for (var i = 0; i < marks.length; i++) { |
1249 var mark = marks[i]; | |
643 | 1250 if (data.zoomArea.containsPosition(mark)) { |
633 | 1251 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
|
1252 console.debug("renderMarks: mpos=",mpos); |
633 | 1253 // create mark |
1254 var html = '<div class="mark">'+(i+1)+'</div>'; | |
1255 var $mark = $(html); | |
1256 $elem.append($mark); | |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1257 mpos.adjustDiv($mark); |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1258 } |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1259 } |
633 | 1260 }; |
655 | 1261 |
647 | 1262 // zooms by the given factor |
643 | 1263 var zoomBy = function(data, factor) { |
1264 var area = data.zoomArea; | |
1265 var newarea = area.copy(); | |
1266 // scale | |
1267 newarea.width /= factor; | |
1268 newarea.height /= factor; | |
1269 // and recenter | |
1270 newarea.x -= 0.5 * (newarea.width - area.width); | |
1271 newarea.y -= 0.5 * (newarea.height - area.height); | |
735
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
1272 newarea = FULL_AREA.fit(newarea); |
643 | 1273 data.zoomArea = newarea; |
644
ee8ccd84c5f8
reload doesn't take list of changed parameters any more
robcast
parents:
643
diff
changeset
|
1274 redisplay(data); |
643 | 1275 }; |
1276 | |
647 | 1277 // add a mark where clicked |
1278 var setMark = function (data) { | |
649 | 1279 var $scaler = data.$scaler; |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1280 // unbind other handler |
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1281 $scaler.unbind(".dlZoomDrag"); |
647 | 1282 // start event capturing |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1283 $scaler.one('mousedown.dlSetMark', function (evt) { |
647 | 1284 // event handler adding a new mark |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1285 console.log("setmark at=", evt); |
672
7f7536a5b6d9
image transform works now under rotation!!! (at least for multiples of 90deg)
robcast
parents:
671
diff
changeset
|
1286 var mpos = geom.position(evt); |
647 | 1287 var pos = data.imgTrafo.invtransform(mpos); |
1288 data.marks.push(pos); | |
1289 redisplay(data); | |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1290 return false; |
647 | 1291 }); |
1292 }; | |
668 | 1293 |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1294 // zoom to the area around two clicked points |
654 | 1295 var zoomArea = function(data) { |
1296 $elem = data.$elem; | |
1297 $scaler = data.$scaler; | |
1298 var pt1, pt2; | |
1299 var $zoomDiv = $('<div class="zoomrect" style="display:none"/>'); | |
1300 $elem.append($zoomDiv); | |
775 | 1301 // $zoomDiv.css(data.settings.zoomrectStyle); |
654 | 1302 var picRect = geom.rectangle($scaler); |
1303 // FIX ME: is there a way to query the border width from CSS info? | |
1304 // rect.x -= 2; // account for overlay borders | |
1305 // rect.y -= 2; | |
1306 | |
1307 var zoomStart = function (evt) { | |
1308 pt1 = geom.position(evt); | |
1309 // setup and show zoom div | |
738 | 1310 pt1.adjustDiv($zoomDiv); |
668 | 1311 $zoomDiv.width(0).height(0); |
654 | 1312 $zoomDiv.show(); |
1313 // register events | |
738 | 1314 $elem.bind("mousemove.dlZoomArea", zoomMove); |
1315 $elem.bind("mouseup.dlZoomArea", zoomEnd); | |
654 | 1316 return false; |
1317 }; | |
668 | 1318 |
741 | 1319 // mouse move handler |
1320 var zoomMove = function (evt) { | |
1321 pt2 = geom.position(evt); | |
1322 var rect = geom.rectangle(pt1, pt2); | |
1323 rect.clipTo(picRect); | |
1324 // update zoom div | |
1325 rect.adjustDiv($zoomDiv); | |
1326 return false; | |
1327 }; | |
745
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1328 |
654 | 1329 // mouseup handler: end moving |
1330 var zoomEnd = function (evt) { | |
1331 pt2 = geom.position(evt); | |
1332 // assume a click and continue if the area is too small | |
1333 var clickRect = geom.rectangle(pt1, pt2); | |
710 | 1334 if (clickRect.getArea() <= 5) return false; |
654 | 1335 // hide zoom div |
1336 $zoomDiv.remove(); | |
1337 // unregister events | |
738 | 1338 $elem.unbind("mousemove.dlZoomArea", zoomMove); |
1339 $elem.unbind("mouseup.dlZoomArea", zoomEnd); | |
654 | 1340 // clip and transform |
1341 clickRect.clipTo(picRect); | |
1342 var area = data.imgTrafo.invtransform(clickRect); | |
1343 data.zoomArea = area; | |
1344 // zoomed is always fit | |
1345 data.settings.ws = 1; | |
738 | 1346 delete data.dlOpts.fitwidth; |
1347 delete data.dlOpts.fitheight; | |
654 | 1348 redisplay(data); |
1349 return false; | |
1350 }; | |
668 | 1351 |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1352 // clear old handler (also ZoomDrag) |
738 | 1353 $scaler.unbind('.dlZoomArea'); |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1354 $scaler.unbind(".dlZoomDrag"); |
738 | 1355 $elem.unbind('.dlZoomArea'); |
654 | 1356 // bind start zoom handler |
738 | 1357 $scaler.one('mousedown.dlZoomArea', zoomStart); |
654 | 1358 }; |
647 | 1359 |
746
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1360 // set zoom background |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1361 var setZoomBG = function(data) { |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1362 var $scaler = data.$scaler; |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1363 var $img = data.$img; |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1364 var fullRect = null; |
767 | 1365 // hide marks |
1366 data.$elem.find('div.mark').hide(); | |
746
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) { |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
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; |
733 | 1411 startPos = geom.position(evt); |
741 | 1412 delta = null; |
746
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1413 // set low res background immediately on mousedown |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1414 fullRect = setZoomBG(data); |
733 | 1415 $document.bind("mousemove.dlZoomDrag", dragMove); |
1416 $document.bind("mouseup.dlZoomDrag", dragEnd); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1417 return false; |
705 | 1418 }; |
745
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1419 |
733 | 1420 // mousemove handler: drag zoomed image |
705 | 1421 var dragMove = function (evt) { |
1422 var pos = geom.position(evt); | |
741 | 1423 delta = startPos.delta(pos); |
1424 if (fullRect) { | |
1425 var bgPos = fullRect.getPosition().add(delta); | |
1426 } else { | |
1427 var bgPos = delta; | |
1428 } | |
705 | 1429 // move the background image to the new position |
715 | 1430 $scaler.css({ |
741 | 1431 'background-position' : bgPos.x + "px " + bgPos.y + "px" |
705 | 1432 }); |
746
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1433 // set birdview indicator to reflect new zoom position |
745
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1434 var za = geom.rectangle($img); |
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1435 za.addPosition(delta.neg()); |
795 | 1436 $data.trigger('dragZoom', [za]); |
1437 //TODO: setBirdZoom(data, za); | |
705 | 1438 return false; |
1439 }; | |
710 | 1440 |
733 | 1441 // mouseup handler: reload zoomed image in new position |
705 | 1442 var dragEnd = function (evt) { |
739 | 1443 $scaler.css('cursor', 'auto'); |
733 | 1444 $document.unbind("mousemove.dlZoomDrag", dragMove); |
1445 $document.unbind("mouseup.dlZoomDrag", dragEnd); | |
1446 if (delta == null || delta.distance() < 2) { | |
1447 // no movement | |
1448 $img.css('visibility', 'visible'); | |
741 | 1449 $scaler.css({'opacity' : '1', 'background-image' : 'none'}); |
767 | 1450 // unhide marks |
1451 data.$elem.find('div.mark').show(); | |
733 | 1452 return false; |
1453 } | |
1454 // get old zoom area (screen coordinates) | |
741 | 1455 var za = geom.rectangle($img); |
733 | 1456 // move |
741 | 1457 za.addPosition(delta.neg()); |
733 | 1458 // transform back |
1459 var newArea = data.imgTrafo.invtransform(za); | |
735
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
1460 data.zoomArea = FULL_AREA.fit(newArea); |
708
120ace160386
img reload works for fullscreen, but somehow not precise
hertzhaft
parents:
707
diff
changeset
|
1461 redisplay(data); |
705 | 1462 return false; |
1463 }; | |
735
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
1464 |
733 | 1465 // clear old handler |
1466 $document.unbind(".dlZoomDrag"); | |
741 | 1467 $scaler.unbind(".dlZoomDrag"); |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1468 if (! isFullArea(data.zoomArea)) { |
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1469 // set handler |
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1470 $scaler.bind("mousedown.dlZoomDrag", dragStart); |
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1471 } |
705 | 1472 }; |
1473 | |
703 | 1474 // get image quality as a number (0..2) |
1475 var getQuality = function (data) { | |
1476 var flags = data.scalerFlags; | |
1477 var q = flags.q2 || flags.q1 || 'q0'; // assume q0 as default | |
1478 return parseInt(q[1], 10); | |
706 | 1479 }; |
703 | 1480 |
1481 // set image quality as a number (0..2) | |
1482 var setQuality = function (data, qual) { | |
1483 var flags = data.scalerFlags; | |
1484 // clear flags | |
1485 for (var i = 0; i < 3; ++i) { | |
1486 delete flags['q'+i]; | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1487 } |
703 | 1488 flags['q'+qual] = 'q'+qual; |
706 | 1489 }; |
710 | 1490 |
761
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1491 // get image scale mode (screen, pixel, size) |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1492 var getScaleMode = function (data) { |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1493 if (data.scalerFlags.clip != null) { |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1494 return 'pixel'; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1495 } else if (data.scalerFlags.osize != null) { |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1496 return 'size'; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1497 } |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1498 // mo=fit is default |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1499 return 'screen'; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1500 }; |
775 | 1501 |
761
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1502 // set image scale mode (screen, pixel, size) |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1503 var setScaleMode = function (data, mode) { |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1504 delete data.scalerFlags.fit; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1505 delete data.scalerFlags.clip; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1506 delete data.scalerFlags.osize; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1507 if (mode === 'pixel') { |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1508 data.scalerFlags.clip = 'clip'; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1509 } else if (mode === 'size') { |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1510 data.scalerFlags.osize = 'osize'; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1511 } |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1512 // mo=fit is default |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1513 }; |
775 | 1514 |
761
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1515 // sets a key to a value (relative values with +/- if relative=true) |
650 | 1516 var setNumValue = function(settings, key, value) { |
716 | 1517 if (value == null) return null; |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1518 if (isNumber(value)) { |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1519 settings[key] = value; |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1520 return value; |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1521 } |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1522 var sign = value[0]; |
650 | 1523 if (sign === '+' || sign === '-') { |
1524 if (settings[key] == null) { | |
651
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1525 // this isn't perfect but still... |
650 | 1526 settings[key] = 0; |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1527 } |
650 | 1528 settings[key] = parseFloat(settings[key]) + parseFloat(value); |
1529 } else { | |
1530 settings[key] = value; | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1531 } |
650 | 1532 return settings[key]; |
1533 }; | |
655 | 1534 |
775 | 1535 // auxiliary function, assuming equal border width on all sides |
1536 var getBorderWidth = function($elem) { | |
1537 var border = $elem.outerWidth() - $elem.width(); | |
1538 return border/2; | |
1539 }; | |
1540 | |
655 | 1541 // auxiliary function (from old dllib.js) |
795 | 1542 var isFullArea = function (area) { |
659 | 1543 return (area.width === 1.0) && (area.height === 1.0); |
655 | 1544 }; |
1545 | |
641 | 1546 // auxiliary function (from Douglas Crockford, A.10) |
795 | 1547 var isNumber = function (value) { |
710 | 1548 return typeof value === 'number' && isFinite(value); |
641 | 1549 }; |
655 | 1550 |
631 | 1551 // auxiliary function to crop senseless precision |
1552 var cropFloat = function (x) { | |
637 | 1553 return parseInt(10000 * x, 10) / 10000; |
631 | 1554 }; |
655 | 1555 |
692 | 1556 // fallback for console.log calls |
1557 if (customConsole) { | |
1558 var logFunction = function(type) { | |
1559 return function(){ | |
1560 var $debug = $('#debug'); // debug div | |
1561 if (!$debug) return; | |
1562 var args = Array.prototype.slice.call(arguments); | |
1563 var argtext = args.join(' '); | |
1564 var $logDiv = $('<div/>'); | |
1565 $logDiv.addClass(type); | |
1566 $logDiv.text(argtext); | |
1567 $debug.append($logDiv); | |
1568 }; | |
1569 }; | |
1570 console.log = logFunction('_log'); | |
1571 console.debug = logFunction('_debug'); | |
1572 console.error = logFunction('_error'); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1573 } |
692 | 1574 |
787 | 1575 // functions to export to plugins |
1576 fn = { | |
791 | 1577 geometry : geom, |
787 | 1578 parseQueryString : parseQueryString, |
1579 getScalerUrl : getScalerUrl, | |
1580 getParamString : getParamString, | |
1581 getDigilibUrl : getDigilibUrl, | |
1582 unpackParams : unpackParams, | |
1583 packParams : packParams, | |
795 | 1584 storeOptions : storeOptions, |
787 | 1585 redisplay : redisplay, |
1586 updateDisplay : updateDisplay, | |
795 | 1587 highlightButtons : highlightButtons, |
791 | 1588 showDiv : showDiv, |
795 | 1589 setZoomBG : setZoomBG, |
787 | 1590 getImgTrafo : getImgTrafo, |
1591 getQuality : getQuality, | |
1592 setQuality : setQuality, | |
1593 getScaleMode : getScaleMode, | |
1594 setScaleMode : setScaleMode, | |
795 | 1595 isFullArea : isFullArea, |
1596 getBorderWidth : getBorderWidth | |
787 | 1597 }; |
788 | 1598 |
605 | 1599 // hook plugin into jquery |
785 | 1600 $.fn.digilib = function (action) { |
760
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1601 // plugin extension mechanism |
786 | 1602 if (action === 'plugin') { |
1603 var plugin = arguments[1]; | |
1604 // each plugin needs a name | |
1605 if (plugin.name != null) { | |
1606 plugins[plugin.name] = plugin; | |
793
63c1b33e38b1
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
791
diff
changeset
|
1607 // share common objects |
63c1b33e38b1
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
791
diff
changeset
|
1608 plugin.defaults = defaults; |
63c1b33e38b1
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
791
diff
changeset
|
1609 plugin.buttons = buttons; |
63c1b33e38b1
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
791
diff
changeset
|
1610 plugin.actions = actions; |
63c1b33e38b1
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
791
diff
changeset
|
1611 plugin.fn = fn; |
63c1b33e38b1
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
791
diff
changeset
|
1612 plugin.plugins = plugins; |
63c1b33e38b1
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
791
diff
changeset
|
1613 // and install |
63c1b33e38b1
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
791
diff
changeset
|
1614 if (typeof plugin.install === 'function') { |
63c1b33e38b1
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
791
diff
changeset
|
1615 plugin.install(plugin); |
63c1b33e38b1
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
791
diff
changeset
|
1616 } |
786 | 1617 } |
787 | 1618 // initialisation of plugins done later |
760
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1619 } else if (actions[action]) { |
651
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1620 // 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
|
1621 var $elem = $(this); |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1622 var data = $elem.data('digilib'); |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1623 var args = Array.prototype.slice.call(arguments, 1); |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1624 args.unshift(data); |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1625 return actions[action].apply(this, args); |
798
b07d1824ca2a
fullscreen mode works without reload on browsers supporting history.pushstate!
robcast
parents:
797
diff
changeset
|
1626 } else if (typeof action === 'object' || !action) { |
634 | 1627 // call init on this |
651
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1628 return actions.init.apply(this, arguments); |
605 | 1629 } else { |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1630 $.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
|
1631 } |
605 | 1632 }; |
692 | 1633 |
604 | 1634 })(jQuery); |