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