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