Mercurial > hg > digilib-old
annotate client/digitallibrary/jquery/jquery.digilib.js @ 761:16778bd2de7c jquery
added setScaleMode. no compensation for change in scaling yet.
author | robcast |
---|---|
date | Wed, 09 Feb 2011 10:22:29 +0100 |
parents | f0be4432f515 |
children | 31664707999e |
rev | line source |
---|---|
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1 /* Copyright (c) 2011 Martin Raspe, Robert Casties |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
2 |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
3 This program is free software: you can redistribute it and/or modify |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
4 it under the terms of the GNU Lesser General Public License as published by |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
5 the Free Software Foundation, either version 2 of the License, or |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
6 (at your option) any later version. |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
7 |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
8 This program is distributed in the hope that it will be useful, |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
9 but WITHOUT ANY WARRANTY; without even the implied warranty of |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
11 GNU Lesser General Public License for more details. |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
12 |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
13 You should have received a copy of the GNU Lesser General Public License |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
15 |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
16 Authors: |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
17 Martin Raspe, Robert Casties, 11.1.2011 |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
18 */ |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
19 |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
20 /** |
604 | 21 * digilib jQuery plugin |
745
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
22 **/ |
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
23 |
655 | 24 |
745
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
25 /* jslint browser: true, debug: true, forin: true |
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
26 */ |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
27 |
636 | 28 // fallback for console.log calls |
29 if (typeof(console) === 'undefined') { | |
30 var console = { | |
692 | 31 log : function(){}, |
32 debug : function(){}, | |
33 error : function(){} | |
34 }; | |
35 var customConsole = true; | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
36 } |
604 | 37 |
38 (function($) { | |
651
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
39 var buttons = { |
610 | 40 reference : { |
689 | 41 onclick : "reference", |
610 | 42 tooltip : "get a reference URL", |
43 img : "reference.png" | |
44 }, | |
45 zoomin : { | |
643 | 46 onclick : ["zoomBy", 1.4], |
610 | 47 tooltip : "zoom in", |
48 img : "zoom-in.png" | |
49 }, | |
50 zoomout : { | |
643 | 51 onclick : ["zoomBy", 0.7], |
610 | 52 tooltip : "zoom out", |
53 img : "zoom-out.png" | |
54 }, | |
55 zoomarea : { | |
654 | 56 onclick : "zoomArea", |
610 | 57 tooltip : "zoom area", |
58 img : "zoom-area.png" | |
59 }, | |
60 zoomfull : { | |
650 | 61 onclick : "zoomFull", |
610 | 62 tooltip : "view the whole image", |
63 img : "zoom-full.png" | |
64 }, | |
65 pagewidth : { | |
650 | 66 onclick : ["zoomFull", "width"], |
610 | 67 tooltip : "page width", |
68 img : "pagewidth.png" | |
69 }, | |
70 back : { | |
623 | 71 onclick : ["gotoPage", "-1"], |
610 | 72 tooltip : "goto previous image", |
73 img : "back.png" | |
74 }, | |
75 fwd : { | |
623 | 76 onclick : ["gotoPage", "+1"], |
610 | 77 tooltip : "goto next image", |
78 img : "fwd.png" | |
79 }, | |
80 page : { | |
716 | 81 onclick : "gotoPage", |
82 tooltip : "goto image number", | |
610 | 83 img : "page.png" |
84 }, | |
85 bird : { | |
635 | 86 onclick : "showBirdDiv", |
610 | 87 tooltip : "show bird's eye view", |
88 img : "birds-eye.png" | |
89 }, | |
90 help : { | |
635 | 91 onclick : "showAboutDiv", |
610 | 92 tooltip : "about Digilib", |
93 img : "help.png" | |
94 }, | |
95 reset : { | |
688 | 96 onclick : "reset", |
610 | 97 tooltip : "reset image", |
98 img : "reset.png" | |
99 }, | |
100 mark : { | |
647 | 101 onclick : "setMark", |
610 | 102 tooltip : "set a mark", |
103 img : "mark.png" | |
104 }, | |
105 delmark : { | |
650 | 106 onclick : "removeMark", |
610 | 107 tooltip : "delete the last mark", |
108 img : "delmark.png" | |
109 }, | |
110 hmir : { | |
661 | 111 onclick : ["mirror", "h"], |
610 | 112 tooltip : "mirror horizontally", |
113 img : "mirror-horizontal.png" | |
114 }, | |
115 vmir : { | |
661 | 116 onclick : ["mirror", "v"], |
610 | 117 tooltip : "mirror vertically", |
118 img : "mirror-vertical.png" | |
119 }, | |
120 rot : { | |
663 | 121 onclick : "rotate", |
610 | 122 tooltip : "rotate image", |
123 img : "rotate.png" | |
124 }, | |
125 brgt : { | |
663 | 126 onclick : "brightness", |
610 | 127 tooltip : "set brightness", |
128 img : "brightness.png" | |
129 }, | |
130 cont : { | |
663 | 131 onclick : "contrast", |
610 | 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 : { | |
748 | 141 onclick : "setQuality", |
610 | 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 : { | |
754
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
151 onclick : "calibrate", |
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
152 tooltip : "calibrate screen resolution", |
610 | 153 img : "calibration-x.png" |
154 }, | |
155 scale : { | |
761
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
156 onclick : "setScaleMode", |
610 | 157 tooltip : "change image scale", |
158 img : "original-size.png" | |
159 }, | |
699 | 160 toggleoptions : { |
748 | 161 onclick : "moreButtons", |
699 | 162 tooltip : "more options", |
163 img : "options.png" | |
164 }, | |
690 | 165 moreoptions : { |
748 | 166 onclick : ["moreButtons", "+1"], |
690 | 167 tooltip : "more options", |
168 img : "options.png" | |
169 }, | |
170 lessoptions : { | |
748 | 171 onclick : ["moreButtons", "-1"], |
690 | 172 tooltip : "less options", |
610 | 173 img : "options.png" |
174 }, | |
175 SEP : { | |
176 img : "sep.png" | |
177 } | |
178 }; | |
617
cd846b5c8be8
toggle view event handlers for bird's eye and 'about windows
hertzhaft
parents:
616
diff
changeset
|
179 |
605 | 180 var defaults = { |
616 | 181 // version of this script |
635 | 182 'version' : 'jquery.digilib.js 0.9', |
616 | 183 // logo url |
184 'logoUrl' : '../img/digilib-logo-text1.png', | |
635 | 185 // homepage url (behind logo) |
186 'homeUrl' : 'http://digilib.berlios.de', | |
744 | 187 // base URL to digilib viewer (for reference URLs) |
188 'digilibBaseUrl' : null, | |
610 | 189 // base URL to Scaler servlet |
652 | 190 'scalerBaseUrl' : null, |
610 | 191 // list of Scaler parameters |
627 | 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 | |
643 | 195 'pn' : 1, |
627 | 196 'ww' : 1.0, |
197 'wh' : 1.0, | |
198 'wx' : 0.0, | |
199 'wy' : 0.0, | |
200 'ws' : 1.0, | |
643 | 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, | |
644
ee8ccd84c5f8
reload doesn't take list of changed parameters any more
robcast
parents:
643
diff
changeset
|
210 // list of digilib parameters |
650 | 211 'digilibParamNames' : ['fn','pn','ww','wh','wx','wy','ws','mo','rot','cont','brgt','rgbm','rgba','mk','clop'], |
644
ee8ccd84c5f8
reload doesn't take list of changed parameters any more
robcast
parents:
643
diff
changeset
|
212 // digilib parameter defaults |
643 | 213 'mk' : '', |
650 | 214 'clop' : '', |
643 | 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 | |
610 | 218 'interactionMode' : 'fullscreen', |
651
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
219 // buttons |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
220 'buttons' : buttons, |
668 | 221 // defaults for digilib buttons |
665 | 222 'buttonSettings' : { |
223 'fullscreen' : { | |
668 | 224 // path to button images (must end with a slash) |
665 | 225 'imagePath' : 'img/fullscreen/', |
721 | 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"], | |
682 | 228 'buttonSets' : ['standardSet', 'specialSet'] |
665 | 229 }, |
230 'embedded' : { | |
231 'imagePath' : 'img/embedded/16/', | |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
232 'standardSet' : ["reference","zoomin","zoomout","zoomarea","zoomfull","bird","help","reset","toggleoptions"], |
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
233 'specialSet' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","toggleoptions"], |
682 | 234 'buttonSets' : ['standardSet', 'specialSet'] |
665 | 235 } |
697 | 236 }, |
237 // number of visible button groups | |
735
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
238 'visibleButtonSets' : 1, |
616 | 239 // is birdView shown? |
240 'isBirdDivVisible' : false, | |
668 | 241 // dimensions of bird's eye div |
674 | 242 'birdDivWidth' : 200, |
243 'birdDivHeight' : 200, | |
719
3da6db751448
change birdview along with scalerUrl in embedded mode
hertzhaft
parents:
718
diff
changeset
|
244 // parameters used by bird's eye div |
3da6db751448
change birdview along with scalerUrl in embedded mode
hertzhaft
parents:
718
diff
changeset
|
245 'birdDivParams' : ['fn','pn','dw','dh'], |
668 | 246 // style of the zoom area indicator in the bird's eye div |
659 | 247 'birdIndicatorStyle' : {'border' : '2px solid #ff0000' }, |
668 | 248 // style of zoom area "rubber band" |
249 'zoomrectStyle' : {'border' : '2px solid #ff0000' }, | |
616 | 250 // is the "about" window shown? |
741 | 251 'isAboutDivVisible' : false, |
252 // maximum width of background image for drag-scroll | |
253 'maxBgSize' : 10000 | |
616 | 254 |
610 | 255 }; |
655 | 256 |
608 | 257 // affine geometry classes |
258 var geom = dlGeometry(); | |
655 | 259 |
735
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
260 var FULL_AREA = geom.rectangle(0, 0, 1, 1); |
655 | 261 |
651
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
262 var actions = { |
668 | 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'; | |
652 | 281 } |
282 } | |
636 | 283 } |
668 | 284 } |
285 return this.each(function() { | |
286 var $elem = $(this); | |
287 var data = $elem.data('digilib'); | |
688 | 288 var params, elemSettings; |
668 | 289 // if the plugin hasn't been initialized yet |
290 if (!data) { | |
291 // merge query parameters | |
292 if (isFullscreen) { | |
688 | 293 params = queryParams; |
668 | 294 } else { |
688 | 295 params = parseImgParams($elem); |
727 | 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); | |
728 | 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); | |
727 | 307 } |
308 } | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
309 } |
668 | 310 // store $(this) element in the settings |
728 | 311 elemSettings = jQuery.extend({}, settings, params); |
697 | 312 data = { |
668 | 313 $elem : $elem, |
314 settings : elemSettings, | |
688 | 315 queryParams : params |
668 | 316 }; |
317 // store in data element | |
318 $elem.data('digilib', data); | |
319 } | |
320 unpackParams(data); | |
744 | 321 // check if browser knows *background-size |
741 | 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 } | |
744 | 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 } | |
682 | 345 // create HTML structure for scaler |
668 | 346 setupScalerDiv(data); |
697 | 347 // add buttons |
348 for (var i = 0; i < elemSettings.visibleButtonSets; ++i) { | |
349 showButtons(data, true, i); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
350 } |
668 | 351 // bird's eye view creation |
710 | 352 if (elemSettings.isBirdDivVisible) { |
638 | 353 setupBirdDiv(data); |
723 | 354 data.$birdDiv.show(); |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
355 } |
668 | 356 // about window creation - TODO: could be deferred? restrict to only one item? |
357 setupAboutDiv(data); | |
735
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
358 // drag zoom area around in scaler div |
755 | 359 // setupZoomDrag(data); // is done in scalerImgLoadedHandler() |
668 | 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 }, | |
655 | 377 |
668 | 378 // event handler: toggles the visibility of the bird's eye window |
379 showBirdDiv : function (data, show) { | |
726 | 380 var settings = data.settings; |
668 | 381 if (data.$birdDiv == null) { |
382 // no bird div -> create | |
383 setupBirdDiv(data); | |
384 } | |
726 | 385 settings.isBirdDivVisible = showDiv(settings.isBirdDivVisible, data.$birdDiv, show); |
386 updateBirdDiv(data); | |
723 | 387 storeOptions(data); |
388 // data.$birdImg.triggerHandler('load'); // TODO: we shouldn't do that | |
668 | 389 }, |
390 | |
391 // goto given page nr (+/-: relative) | |
392 gotoPage : function (data, pageNr) { | |
393 var settings = data.settings; | |
394 var oldpn = settings.pn; | |
716 | 395 if (pageNr == null) { |
396 pageNr = window.prompt("Goto page number", oldpn); | |
397 } | |
668 | 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)"); | |
623 | 408 settings.pn = oldpn; |
409 return false; | |
634 | 410 } |
668 | 411 } |
412 // reset mk and others(?) | |
413 data.marks = []; | |
735
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
414 data.zoomArea = FULL_AREA; |
668 | 415 // then reload |
416 redisplay(data); | |
417 }, | |
654 | 418 |
668 | 419 // zoom by a given factor |
420 zoomBy : function (data, factor) { | |
421 zoomBy(data, factor); | |
422 }, | |
647 | 423 |
668 | 424 // zoom interactively |
425 zoomArea : function (data) { | |
426 zoomArea(data); | |
427 }, | |
650 | 428 |
668 | 429 // zoom out to full page |
430 zoomFull : function (data, mode) { | |
735
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
431 data.zoomArea = FULL_AREA; |
668 | 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); | |
663 | 453 redisplay(data); |
604 | 454 } |
668 | 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 }, | |
650 | 481 |
668 | 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); | |
688 | 510 }, |
710 | 511 |
690 | 512 // display more (or less) button sets |
748 | 513 moreButtons : function (data, more) { |
696 | 514 var settings = data.settings; |
699 | 515 if (more == null) { |
703 | 516 // toggle more or less (only works for 2 sets) |
699 | 517 var maxbtns = settings.buttonSettings[settings.interactionMode].buttonSets.length; |
518 if (settings.visibleButtonSets >= maxbtns) { | |
519 more = '-1'; | |
520 } else { | |
521 more = '+1'; | |
522 } | |
523 } | |
690 | 524 if (more === '-1') { |
525 // remove set | |
697 | 526 var setIdx = settings.visibleButtonSets - 1; |
527 if (showButtons(data, false, setIdx, true)) { | |
528 settings.visibleButtonSets--; | |
529 } | |
690 | 530 } else { |
531 // add set | |
697 | 532 var setIdx = settings.visibleButtonSets; |
533 if (showButtons(data, true, setIdx, true)) { | |
534 settings.visibleButtonSets++; | |
690 | 535 } |
536 } | |
723 | 537 // persist setting |
538 storeOptions(data); | |
691 | 539 }, |
688 | 540 |
703 | 541 // reset image parameters to defaults |
688 | 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]; | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
550 } |
735
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
551 settings.fn = params.fn || ''; // no default defined |
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
552 settings.pn = params.pn || defaults.pn; |
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
553 settings.dw = params.dw; |
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
554 settings.dh = params.dh; |
709 | 555 settings.isBirdDivVisible = false; |
556 settings.visibleButtonSets = 1; | |
735
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
557 // resets zoomArea, marks, scalerflags |
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
558 data.zoomArea = FULL_AREA; |
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
559 data.marks = []; |
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
560 data.scalerFlags = {}; |
712 | 561 delete data.dlOpts.fitwidth; |
562 delete data.dlOpts.fitheight; | |
688 | 563 redisplay(data); |
689 | 564 }, |
565 | |
703 | 566 // presents a reference url (returns value if noprompt) |
567 reference : function (data, noprompt) { | |
689 | 568 var settings = data.settings; |
744 | 569 var url = getDigilibUrl(data); |
703 | 570 if (noprompt == null) { |
571 window.prompt("URL reference to the current view", url); | |
572 } | |
573 return url; | |
574 }, | |
710 | 575 |
703 | 576 // set image quality |
748 | 577 setQuality : function (data, qual) { |
703 | 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 } | |
754
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
587 }, |
760
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
588 |
754
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
589 // calibrate (only faking) |
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
590 calibrate : function (data) { |
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
591 getImageInfo(data); |
760
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
592 }, |
761
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
593 |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
594 // set image scale mode |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
595 setScaleMode : function (data, mode) { |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
596 var oldM = getScaleMode(data); |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
597 if (mode == null) { |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
598 mode = window.prompt("Image scale mode (screen, pixel, size)", oldM); |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
599 } |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
600 if (mode != null) { |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
601 setScaleMode(data, mode); |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
602 redisplay(data); |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
603 } |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
604 } |
760
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
605 |
605 | 606 }; |
604 | 607 |
608 | 608 // returns parameters from page url |
607 | 609 var parseQueryParams = function() { |
636 | 610 return parseQueryString(window.location.search.slice(1)); |
611 }; | |
655 | 612 |
636 | 613 // returns parameters from embedded img-element |
607 | 614 var parseImgParams = function($elem) { |
613
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
615 var src = $elem.find('img').first().attr('src'); |
710 | 616 if (!src) return null; |
607 | 617 var pos = src.indexOf('?'); |
618 var query = (pos < 0) ? '' : src.substring(pos + 1); | |
619 var scalerUrl = src.substring(0, pos); | |
627 | 620 var params = parseQueryString(query); |
621 params.scalerBaseUrl = scalerUrl; | |
622 return params; | |
636 | 623 }; |
607 | 624 |
608 | 625 // parses query parameter string into parameter object |
607 | 626 var parseQueryString = function(query) { |
701 | 627 var params = {}; |
628 if (query == null) return params; | |
607 | 629 var pairs = query.split("&"); |
636 | 630 //var keys = []; |
607 | 631 for (var i = 0; i < pairs.length; i++) { |
632 var pair = pairs[i].split("="); | |
633 if (pair.length === 2) { | |
627 | 634 params[pair[0]] = pair[1]; |
636 | 635 //keys.push(pair[0]); |
634 | 636 } |
636 | 637 } |
627 | 638 return params; |
636 | 639 }; |
668 | 640 |
643 | 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) { | |
615 | 643 var paramString = ''; |
650 | 644 var nx = false; |
615 | 645 for (i = 0; i < keys.length; ++i) { |
646 var key = keys[i]; | |
663 | 647 if ((settings[key] != null) && ((defaults == null) || (settings[key] != defaults[key]))) { |
615 | 648 // first param gets no '&' |
650 | 649 if (nx) { |
650 paramString += '&'; | |
651 } else { | |
652 nx = true; | |
653 } | |
615 | 654 // add parm=val |
655 paramString += key + '=' + settings[key]; | |
643 | 656 } |
615 | 657 } |
658 return paramString; | |
631 | 659 }; |
660 | |
636 | 661 // returns URL and query string for Scaler |
662 var getScalerUrl = function (data) { | |
741 | 663 packParams(data); |
653 | 664 var settings = data.settings; |
652 | 665 if (settings.scalerBaseUrl == null) { |
666 alert("ERROR: URL of digilib Scaler servlet missing!"); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
667 } |
636 | 668 var keys = settings.scalerParamNames; |
643 | 669 var queryString = getParamString(settings, keys, defaults); |
636 | 670 var url = settings.scalerBaseUrl + '?' + queryString; |
671 return url; | |
672 }; | |
673 | |
741 | 674 // returns URL for bird's eye view image |
743 | 675 var getBirdImgUrl = function (data, moreParams) { |
741 | 676 var settings = data.settings; |
677 var birdDivOptions = { | |
678 dw : settings.birdDivWidth, | |
679 dh : settings.birdDivHeight | |
680 }; | |
743 | 681 var birdSettings = jQuery.extend({}, settings, birdDivOptions); |
741 | 682 // use only the relevant parameters |
743 | 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; | |
741 | 690 return url; |
691 }; | |
745
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
692 |
636 | 693 // returns URL and query string for current digilib |
644
ee8ccd84c5f8
reload doesn't take list of changed parameters any more
robcast
parents:
643
diff
changeset
|
694 var getDigilibUrl = function (data) { |
643 | 695 packParams(data); |
636 | 696 var settings = data.settings; |
644
ee8ccd84c5f8
reload doesn't take list of changed parameters any more
robcast
parents:
643
diff
changeset
|
697 var queryString = getParamString(settings, settings.digilibParamNames, defaults); |
744 | 698 return settings.digilibBaseUrl + '?' + queryString; |
636 | 699 }; |
700 | |
754
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
701 // gets image information from digilib server via HTTP and calls complete |
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
702 var getImageInfo = function (data, complete) { |
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
703 var settings = data.settings; |
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
704 var p = settings.scalerBaseUrl.indexOf('/servlet/Scaler'); |
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
705 var url = settings.scalerBaseUrl.substring(0, p) + '/ImgInfo-json.jsp'; |
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
706 url += '?' + getParamString(settings, ['fn', 'pn'], defaults); |
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
707 jQuery.getJSON(url, function (json) { |
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
708 console.debug("got json data=", json); |
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
709 data.imgInfo = json; |
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
710 if (complete != null) { |
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
711 complete.call(this, data, json); |
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
712 } |
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
713 }); |
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
714 }; |
ce5a0e6b5ee9
reading image info asynchronously works now. has just no use yet.
robcast
parents:
751
diff
changeset
|
715 |
655 | 716 // processes some parameters into objects and stuff |
631 | 717 var unpackParams = function (data) { |
718 var settings = data.settings; | |
636 | 719 // zoom area |
631 | 720 var zoomArea = geom.rectangle(settings.wx, settings.wy, settings.ww, settings.wh); |
643 | 721 data.zoomArea = zoomArea; |
636 | 722 // marks |
631 | 723 var marks = []; |
650 | 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 | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
730 } |
650 | 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])); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
735 } |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
736 } |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
737 } |
643 | 738 data.marks = marks; |
650 | 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]; | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
745 } |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
746 } |
650 | 747 data.scalerFlags = flags; |
723 | 748 retrieveOptions(data); |
655 | 749 }; |
750 | |
631 | 751 // put objects back into parameters |
752 var packParams = function (data) { | |
753 var settings = data.settings; | |
636 | 754 // zoom area |
643 | 755 if (data.zoomArea) { |
647 | 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); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
760 } |
636 | 761 // marks |
643 | 762 if (data.marks) { |
650 | 763 settings.mk = ''; |
643 | 764 for (var i = 0; i < data.marks.length; i++) { |
650 | 765 if (i) { |
766 settings.mk += ','; | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
767 } |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
768 settings.mk += cropFloat(data.marks[i].x).toString() + |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
769 '/' + cropFloat(data.marks[i].y).toString(); |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
770 } |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
771 } |
650 | 772 // 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 } | |
710 | 783 // user interface options |
723 | 784 storeOptions(data); |
709 | 785 }; |
688 | 786 |
723 | 787 var storeOptions = function (data) { |
701 | 788 // save digilib options in cookie |
709 | 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 += '&'; | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
798 } |
709 | 799 clop += o + '=' + data.dlOpts[o]; |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
800 } |
709 | 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); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
805 } |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
806 } |
727 | 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 } | |
631 | 814 }; |
655 | 815 |
723 | 816 var retrieveOptions = function (data) { |
709 | 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); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
827 } |
709 | 828 data.dlOpts = opts; |
829 // birdview option | |
830 if (opts.birdview != null) { | |
831 settings.isBirdDivVisible = opts.birdview === '1'; | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
832 } |
709 | 833 // visible button sets |
834 if (opts.buttons != null) { | |
835 settings.visibleButtonSets = opts.buttons; | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
836 } |
711 | 837 }; |
709 | 838 |
622 | 839 // (re)load the img from a new scaler URL |
644
ee8ccd84c5f8
reload doesn't take list of changed parameters any more
robcast
parents:
643
diff
changeset
|
840 var redisplay = function (data) { |
636 | 841 var settings = data.settings; |
842 if (settings.interactionMode === 'fullscreen') { | |
843 // update location.href (browser URL) in fullscreen mode | |
644
ee8ccd84c5f8
reload doesn't take list of changed parameters any more
robcast
parents:
643
diff
changeset
|
844 var url = getDigilibUrl(data); |
636 | 845 var history = window.history; |
846 if (typeof(history.pushState) === 'function') { | |
847 console.debug("we could modify history, but we don't..."); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
848 } |
636 | 849 window.location = url; |
850 } else { | |
851 // embedded mode -- just change img src | |
852 var url = getScalerUrl(data); | |
853 data.$img.attr('src', url); | |
726 | 854 // redisplay bird img |
855 updateBirdDiv(data); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
856 } |
622 | 857 }; |
858 | |
662 | 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 | |
608 | 868 // creates HTML structure for digilib in elem |
627 | 869 var setupScalerDiv = function (data) { |
870 var settings = data.settings; | |
647 | 871 var $elem = data.$elem; |
725 | 872 $elem.addClass('digilib'); |
728 | 873 var $img; |
874 var scalerUrl; | |
608 | 875 if (settings.interactionMode === 'fullscreen') { |
728 | 876 // fullscreen |
725 | 877 $elem.addClass('dl_fullscreen'); |
609 | 878 var imgSize = getFullscreenImgSize($elem); |
650 | 879 // fitwidth/height omits destination height/width |
728 | 880 if (data.dlOpts.fitheight == null) { |
650 | 881 settings.dw = imgSize.width; |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
882 } |
728 | 883 if (data.dlOpts.fitwidth == null) { |
650 | 884 settings.dh = imgSize.height; |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
885 } |
686 | 886 scalerUrl = getScalerUrl(data); |
728 | 887 $img = $('<img/>'); |
609 | 888 } else { |
728 | 889 // embedded mode -- try to keep img tag |
725 | 890 $elem.addClass('dl_embedded'); |
728 | 891 scalerUrl = getScalerUrl(data); |
623 | 892 $img = $elem.find('img'); |
613
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
893 if ($img.length > 0) { |
728 | 894 oldUrl = $img.attr('src'); |
895 if (oldUrl === scalerUrl) { | |
896 console.debug("img detach:", $img); | |
897 $img.detach(); | |
898 } else { | |
899 $img = $('<img/>'); | |
900 } | |
613
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
901 } else { |
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
902 $img = $('<img/>'); |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
903 } |
608 | 904 } |
613
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
905 // create new html |
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
906 $elem.empty(); // TODO: should we keep stuff for customization? |
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
907 var $scaler = $('<div class="scaler"/>'); |
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
908 $elem.append($scaler); |
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
909 $scaler.append($img); |
622 | 910 $img.addClass('pic'); |
649 | 911 data.$scaler = $scaler; |
636 | 912 data.$img = $img; |
687 | 913 // setup image load handler before setting the src attribute (IE bug) |
914 $img.load(scalerImgLoadedHandler(data)); | |
915 $img.attr('src', scalerUrl); | |
608 | 916 }; |
615 | 917 |
610 | 918 // creates HTML structure for buttons in elem |
697 | 919 var createButtons = function (data, buttonSetIdx) { |
647 | 920 var $elem = data.$elem; |
628
1f077f8afc5e
changed methods to pass "data" around instead of "settings"
robcast
parents:
627
diff
changeset
|
921 var settings = data.settings; |
665 | 922 var mode = settings.interactionMode; |
672
7f7536a5b6d9
image transform works now under rotation!!! (at least for multiples of 90deg)
robcast
parents:
671
diff
changeset
|
923 var buttonSettings = settings.buttonSettings[mode]; |
682 | 924 var buttonGroup = buttonSettings.buttonSets[buttonSetIdx]; |
690 | 925 if (buttonGroup == null) { |
926 // no buttons here | |
927 return; | |
928 } | |
929 var $buttonsDiv = $('<div class="buttons"/>'); | |
682 | 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]; | |
665 | 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); | |
682 | 943 $button.addClass('button-' + buttonName); |
665 | 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); | |
690 | 965 } |
662 | 966 // make buttons div scroll if too large for window |
967 if ($buttonsDiv.height() > $(window).height() - 10) { | |
968 $buttonsDiv.css('position', 'absolute'); | |
969 } | |
697 | 970 // buttons hidden at first |
971 $buttonsDiv.hide(); | |
972 $elem.append($buttonsDiv); | |
682 | 973 if (data.$buttonSets == null) { |
697 | 974 // first button set |
682 | 975 data.$buttonSets = [$buttonsDiv]; |
976 } else { | |
690 | 977 $elem.append($buttonsDiv); |
682 | 978 data.$buttonSets[buttonSetIdx] = $buttonsDiv; |
979 } | |
612 | 980 return $buttonsDiv; |
610 | 981 }; |
615 | 982 |
983 // creates HTML structure for the bird's eye view in elem | |
638 | 984 var setupBirdDiv = function (data) { |
647 | 985 var $elem = data.$elem; |
615 | 986 // the bird's eye div |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
987 var $birdDiv = $('<div class="birdview" style="display:none"/>'); |
615 | 988 // the detail indicator frame |
726 | 989 var $birdZoom = $('<div class="birdzoom" style="display:none; background-color:transparent;"/>'); |
615 | 990 // the small image |
991 var $birdImg = $('<img class="birdimg"/>'); | |
723 | 992 data.$birdDiv = $birdDiv; |
993 data.$birdZoom = $birdZoom; | |
994 data.$birdImg = $birdImg; | |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
995 $elem.append($birdDiv); |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
996 $birdDiv.append($birdZoom); |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
997 $birdDiv.append($birdImg); |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
998 $birdZoom.css(data.settings.birdIndicatorStyle); |
723 | 999 var birdUrl = getBirdImgUrl(data); |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1000 $birdImg.load(birdImgLoadedHandler(data)); |
723 | 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); | |
730 | 1016 // enable click and drag |
732
55f2dd197ca9
really renamed birdMoveArea, really merged fix for no zoom area.
robcast
parents:
731
diff
changeset
|
1017 setupBirdDrag(data); |
723 | 1018 } |
719
3da6db751448
change birdview along with scalerUrl in embedded mode
hertzhaft
parents:
718
diff
changeset
|
1019 }; |
745
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1020 |
625 | 1021 // creates HTML structure for the about view in elem |
628
1f077f8afc5e
changed methods to pass "data" around instead of "settings"
robcast
parents:
627
diff
changeset
|
1022 var setupAboutDiv = function (data) { |
647 | 1023 var $elem = data.$elem; |
628
1f077f8afc5e
changed methods to pass "data" around instead of "settings"
robcast
parents:
627
diff
changeset
|
1024 var settings = data.settings; |
625 | 1025 var $aboutDiv = $('<div class="about" style="display:none"/>'); |
616 | 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); | |
635 | 1036 $link.attr('href', settings.homeUrl); |
616 | 1037 $content.text('Version: ' + settings.version); |
635 | 1038 // click hides |
649 | 1039 $aboutDiv.bind('click.digilib', function () { |
646 | 1040 settings.isAboutDivVisible = showDiv(settings.isAboutDivVisible, $aboutDiv, 0); |
649 | 1041 return false; |
710 | 1042 }); |
635 | 1043 data.$aboutDiv = $aboutDiv; |
634 | 1044 }; |
1045 | |
635 | 1046 // shows some window e.g. 'about' (toggle visibility if show is null) |
1047 var showDiv = function (isVisible, $div, show) { | |
645 | 1048 if (show == null) { |
635 | 1049 // toggle visibility |
1050 isVisible = !isVisible; | |
1051 } else { | |
1052 // set visibility | |
1053 isVisible = show; | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1054 } |
635 | 1055 if (isVisible) { |
1056 $div.fadeIn(); | |
1057 } else { | |
1058 $div.fadeOut(); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1059 } |
635 | 1060 return isVisible; |
634 | 1061 }; |
616 | 1062 |
697 | 1063 // display more (or less) button sets |
1064 var showButtons = function (data, more, setIdx, animated) { | |
711 | 1065 var atime = animated ? 'fast': 0; |
697 | 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); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1075 } |
697 | 1076 if ($set == null) return false; |
1077 var btnWidth = $set.width(); | |
1078 // move remaining sets left and show new set | |
711 | 1079 if ($otherSets.length > 0) { |
1080 $otherSets.animate({right : '+='+btnWidth+'px'}, atime, | |
1081 function () {$set.show();}); | |
697 | 1082 } else { |
1083 $set.show(); | |
711 | 1084 } |
697 | 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'); | |
711 | 1094 $otherSets.animate({right : '-='+btnWidth+'px'}, atime); |
1095 } | |
697 | 1096 return true; |
1097 }; | |
1098 | |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1099 // create Transform from area and $img |
675 | 1100 var getImgTrafo = function ($img, area, rot, hmir, vmir) { |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1101 var picrect = geom.rectangle($img); |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1102 var trafo = geom.transform(); |
675 | 1103 // move zoom area offset to center |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1104 trafo.concat(trafo.getTranslation(geom.position(-area.x, -area.y))); |
675 | 1105 // scale zoom area size to [1,1] |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1106 trafo.concat(trafo.getScale(geom.size(1/area.width, 1/area.height))); |
675 | 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')); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1114 } |
675 | 1115 if (vmir) { |
1116 // mirror about center | |
1117 trafo.concat(trafo.getMirror('x')); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1118 } |
675 | 1119 if (rot) { |
1120 // rotate around center | |
1121 trafo.concat(trafo.getRotation(parseFloat(rot))); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1122 } |
675 | 1123 // move back |
1124 trafo.concat(trafo.getTranslation(geom.position(0.5, 0.5))); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1125 } |
664
d5a5ee4cbf04
work on getting transformation to work with rotation (currently still doesn't)
robcast
parents:
663
diff
changeset
|
1126 // scale to screen position and size |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1127 trafo.concat(trafo.getScale(picrect)); |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1128 trafo.concat(trafo.getTranslation(picrect)); |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1129 return trafo; |
655 | 1130 }; |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1131 |
613
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
1132 // returns function for load event of scaler img |
636 | 1133 var scalerImgLoadedHandler = function (data) { |
633 | 1134 return function () { |
723 | 1135 var $img = $(this); |
738 | 1136 var $scaler = data.$scaler; |
760
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1137 // create Transform from current zoomArea and image size |
675 | 1138 data.imgTrafo = getImgTrafo($img, data.zoomArea, |
1139 data.settings.rot, data.scalerFlags.hmir, data.scalerFlags.vmir); | |
760
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1140 // console.debug("imgTrafo=", data.imgTrafo); |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1141 var imgRect = geom.rectangle($img); |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1142 // console.debug("imgrect=", imgRect); |
733 | 1143 // adjust scaler div size |
738 | 1144 imgRect.adjustDiv($scaler); |
715 | 1145 // show image in case it was hidden (for example in zoomDrag) |
733 | 1146 $img.css('visibility', 'visible'); |
741 | 1147 $scaler.css({'opacity' : '1', 'background-image' : 'none'}); |
627 | 1148 // display marks |
633 | 1149 renderMarks(data); |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1150 // enable drag-to-scroll |
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1151 setupZoomDrag(data); |
695
5c39f5dd6296
cookie control for birdview, works for fullscreen
hertzhaft
parents:
693
diff
changeset
|
1152 // TODO: digilib.showArrows(); // show arrow overlays for zoom navigation |
658
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1153 }; |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1154 }; |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1155 |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1156 // returns function for load event of bird's eye view img |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1157 var birdImgLoadedHandler = function (data) { |
9ddcf0070122
split bird's view code in two more parts, analog to scaler-img code.
robcast
parents:
656
diff
changeset
|
1158 return function () { |
755 | 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 | |
761
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1164 setTimeout(function () { $birdImg.triggerHandler('load'); }, 200); |
755 | 1165 } |
668 | 1166 // display red indicator around zoomarea |
723 | 1167 renderBirdArea(data); |
1168 // enable click and drag | |
732
55f2dd197ca9
really renamed birdMoveArea, really merged fix for no zoom area.
robcast
parents:
731
diff
changeset
|
1169 setupBirdDrag(data); |
613
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
1170 }; |
53ee659e2d00
keeping img tag for embedded mode seems to work now
robcast
parents:
612
diff
changeset
|
1171 }; |
633 | 1172 |
1173 // place marks on the image | |
1174 var renderMarks = function (data) { | |
647 | 1175 var $elem = data.$elem; |
643 | 1176 var marks = data.marks; |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1177 // clear marks |
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1178 $elem.find('div.mark').remove(); |
633 | 1179 for (var i = 0; i < marks.length; i++) { |
1180 var mark = marks[i]; | |
643 | 1181 if (data.zoomArea.containsPosition(mark)) { |
633 | 1182 var mpos = data.imgTrafo.transform(mark); |
664
d5a5ee4cbf04
work on getting transformation to work with rotation (currently still doesn't)
robcast
parents:
663
diff
changeset
|
1183 console.debug("renderMarks: mpos=",mpos); |
633 | 1184 // create mark |
1185 var html = '<div class="mark">'+(i+1)+'</div>'; | |
1186 var $mark = $(html); | |
1187 $elem.append($mark); | |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1188 mpos.adjustDiv($mark); |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1189 } |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1190 } |
633 | 1191 }; |
655 | 1192 |
677
0233e39305d3
took renderBirdArea hooks out of scalerImgLoaded into redisplay.
robcast
parents:
676
diff
changeset
|
1193 // show zoom area indicator on bird's eye view |
723 | 1194 var renderBirdArea = function (data) { |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1195 var $birdZoom = data.$birdZoom; |
659 | 1196 var zoomArea = data.zoomArea; |
723 | 1197 var normalSize = isFullArea(zoomArea); |
1198 if (normalSize) { | |
1199 $birdZoom.hide(); | |
1200 return; | |
1201 } else { | |
1202 $birdZoom.show(); | |
1203 } | |
755 | 1204 // create Transform from current area and picsize |
735
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
1205 data.birdTrafo = getImgTrafo(data.$birdImg, FULL_AREA); |
738 | 1206 var zoomRect = data.birdTrafo.transform(zoomArea); |
755 | 1207 console.debug("renderBirdArea:", zoomRect, "zoomArea:", zoomArea, "$birdTrafo:", data.birdTrafo); |
741 | 1208 // acount for border width |
1209 zoomRect.addPosition({x : -2, y : -2}); | |
670
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1210 if (data.settings.interactionMode === 'fullscreen') { |
11d96bc0ac09
birdview: nice animation for embedded mode, none for fullscreen
hertzhaft
parents:
669
diff
changeset
|
1211 // no animation for fullscreen |
738 | 1212 zoomRect.adjustDiv($birdZoom); |
723 | 1213 } else { |
1214 // nice animation for embedded mode :-) | |
741 | 1215 // correct offsetParent because animate doesn't use offset |
726 | 1216 var ppos = $birdZoom.offsetParent().offset(); |
738 | 1217 var dest = { |
755 | 1218 left : (zoomRect.x - ppos.left) + 'px', |
1219 top : (zoomRect.y - ppos.top) + 'px', | |
1220 width : zoomRect.width, | |
1221 height : zoomRect.height | |
1222 }; | |
738 | 1223 $birdZoom.animate(dest); |
723 | 1224 } |
664
d5a5ee4cbf04
work on getting transformation to work with rotation (currently still doesn't)
robcast
parents:
663
diff
changeset
|
1225 }; |
659 | 1226 |
647 | 1227 // zooms by the given factor |
643 | 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); | |
735
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
1237 newarea = FULL_AREA.fit(newarea); |
643 | 1238 data.zoomArea = newarea; |
644
ee8ccd84c5f8
reload doesn't take list of changed parameters any more
robcast
parents:
643
diff
changeset
|
1239 redisplay(data); |
643 | 1240 }; |
1241 | |
647 | 1242 // add a mark where clicked |
1243 var setMark = function (data) { | |
649 | 1244 var $scaler = data.$scaler; |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1245 // unbind other handler |
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1246 $scaler.unbind(".dlZoomDrag"); |
647 | 1247 // start event capturing |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1248 $scaler.one('mousedown.dlSetMark', function (evt) { |
647 | 1249 // event handler adding a new mark |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1250 console.log("setmark at=", evt); |
672
7f7536a5b6d9
image transform works now under rotation!!! (at least for multiples of 90deg)
robcast
parents:
671
diff
changeset
|
1251 var mpos = geom.position(evt); |
647 | 1252 var pos = data.imgTrafo.invtransform(mpos); |
1253 data.marks.push(pos); | |
1254 redisplay(data); | |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1255 return false; |
647 | 1256 }); |
1257 }; | |
668 | 1258 |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1259 // zoom to the area around two clicked points |
654 | 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); | |
668 | 1266 $zoomDiv.css(data.settings.zoomrectStyle); |
654 | 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 | |
738 | 1275 pt1.adjustDiv($zoomDiv); |
668 | 1276 $zoomDiv.width(0).height(0); |
654 | 1277 $zoomDiv.show(); |
1278 // register events | |
738 | 1279 $elem.bind("mousemove.dlZoomArea", zoomMove); |
1280 $elem.bind("mouseup.dlZoomArea", zoomEnd); | |
654 | 1281 return false; |
1282 }; | |
668 | 1283 |
741 | 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 }; | |
745
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1293 |
654 | 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); | |
710 | 1299 if (clickRect.getArea() <= 5) return false; |
654 | 1300 // hide zoom div |
1301 $zoomDiv.remove(); | |
1302 // unregister events | |
738 | 1303 $elem.unbind("mousemove.dlZoomArea", zoomMove); |
1304 $elem.unbind("mouseup.dlZoomArea", zoomEnd); | |
654 | 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; | |
738 | 1311 delete data.dlOpts.fitwidth; |
1312 delete data.dlOpts.fitheight; | |
654 | 1313 redisplay(data); |
1314 return false; | |
1315 }; | |
668 | 1316 |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1317 // clear old handler (also ZoomDrag) |
738 | 1318 $scaler.unbind('.dlZoomArea'); |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1319 $scaler.unbind(".dlZoomDrag"); |
738 | 1320 $elem.unbind('.dlZoomArea'); |
654 | 1321 // bind start zoom handler |
738 | 1322 $scaler.one('mousedown.dlZoomArea', zoomStart); |
654 | 1323 }; |
647 | 1324 |
723 | 1325 // bird's eye view zoom area click and drag handler |
732
55f2dd197ca9
really renamed birdMoveArea, really merged fix for no zoom area.
robcast
parents:
731
diff
changeset
|
1326 var setupBirdDrag = function(data) { |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1327 var $birdImg = data.$birdImg; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1328 var $birdZoom = data.$birdZoom; |
730 | 1329 var $document = $(document); |
751
00b7857f07f5
zoom-drag background follows birdZoom also in embedded mode (still imprecise)
hertzhaft
parents:
748
diff
changeset
|
1330 var $scaler = data.$scaler; |
00b7857f07f5
zoom-drag background follows birdZoom also in embedded mode (still imprecise)
hertzhaft
parents:
748
diff
changeset
|
1331 var startPos, newRect, birdImgRect, birdZoomRect, fullRect, scalerPos; |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1332 |
741 | 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); | |
751
00b7857f07f5
zoom-drag background follows birdZoom also in embedded mode (still imprecise)
hertzhaft
parents:
748
diff
changeset
|
1340 scalerPos = geom.position($scaler); |
741 | 1341 newRect = null; |
746
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1342 fullRect = setZoomBG(data); // setup zoom background image |
741 | 1343 $document.bind("mousemove.dlBirdMove", birdZoomMove); |
1344 $document.bind("mouseup.dlBirdMove", birdZoomEndDrag); | |
1345 return false; | |
1346 }; | |
1347 | |
733 | 1348 // mousemove handler: drag |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1349 var birdZoomMove = function(evt) { |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1350 var pos = geom.position(evt); |
730 | 1351 var delta = startPos.delta(pos); |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1352 // move birdZoom div, keeping size |
730 | 1353 newRect = birdZoomRect.copy(); |
733 | 1354 newRect.addPosition(delta); |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1355 newRect.stayInside(birdImgRect); |
746
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1356 // reflect birdview zoom position in scaler image |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1357 var area = data.birdTrafo.invtransform(newRect); |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1358 var imgArea = data.imgTrafo.transform(area); |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1359 var offset = imgArea.getPosition().neg(); |
751
00b7857f07f5
zoom-drag background follows birdZoom also in embedded mode (still imprecise)
hertzhaft
parents:
748
diff
changeset
|
1360 offset.add(scalerPos); |
746
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1361 if (fullRect) { |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1362 var bgPos = fullRect.getPosition().add(offset); |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1363 } else { |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1364 var bgPos = offset; |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1365 } |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1366 // move the background image to the new position |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1367 data.$scaler.css({ |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1368 'background-position' : bgPos.x + "px " + bgPos.y + "px" |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1369 }); |
751
00b7857f07f5
zoom-drag background follows birdZoom also in embedded mode (still imprecise)
hertzhaft
parents:
748
diff
changeset
|
1370 // acount for border width |
00b7857f07f5
zoom-drag background follows birdZoom also in embedded mode (still imprecise)
hertzhaft
parents:
748
diff
changeset
|
1371 newRect.addPosition({x : -2, y : -2}); |
00b7857f07f5
zoom-drag background follows birdZoom also in embedded mode (still imprecise)
hertzhaft
parents:
748
diff
changeset
|
1372 newRect.adjustDiv($birdZoom); |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1373 return false; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1374 }; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1375 |
733 | 1376 // mouseup handler: reload page |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1377 var birdZoomEndDrag = function(evt) { |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1378 var settings = data.settings; |
730 | 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 | |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1383 startPos = birdZoomRect.getCenter(); |
730 | 1384 birdZoomMove(evt); |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1385 } |
747
fd4842f0afc7
smoother birdZoom indicator movement; fixed bug in jQuery.offset()
hertzhaft
parents:
746
diff
changeset
|
1386 // ugly, but needed to prevent double border width compensation |
fd4842f0afc7
smoother birdZoom indicator movement; fixed bug in jQuery.offset()
hertzhaft
parents:
746
diff
changeset
|
1387 newRect.addPosition({x : +2, y : +2}); |
730 | 1388 var newArea = data.birdTrafo.invtransform(newRect); |
1389 data.zoomArea = newArea; | |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1390 redisplay(data); |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1391 return false; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1392 }; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1393 |
730 | 1394 // clear old handler |
1395 $document.unbind(".dlBirdMove"); | |
1396 $birdImg.unbind(".dlBirdMove"); | |
1397 $birdZoom.unbind(".dlBirdMove"); | |
732
55f2dd197ca9
really renamed birdMoveArea, really merged fix for no zoom area.
robcast
parents:
731
diff
changeset
|
1398 if (! isFullArea(data.zoomArea)) { |
55f2dd197ca9
really renamed birdMoveArea, really merged fix for no zoom area.
robcast
parents:
731
diff
changeset
|
1399 // set new handler |
55f2dd197ca9
really renamed birdMoveArea, really merged fix for no zoom area.
robcast
parents:
731
diff
changeset
|
1400 $birdImg.bind("mousedown.dlBirdMove", birdZoomStartDrag); |
55f2dd197ca9
really renamed birdMoveArea, really merged fix for no zoom area.
robcast
parents:
731
diff
changeset
|
1401 $birdZoom.bind("mousedown.dlBirdMove", birdZoomStartDrag); |
55f2dd197ca9
really renamed birdMoveArea, really merged fix for no zoom area.
robcast
parents:
731
diff
changeset
|
1402 } |
678
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1403 }; |
d50d24b7fd95
first step at dragging birdview zoom indicator around
hertzhaft
parents:
677
diff
changeset
|
1404 |
746
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1405 // move bird zoom indicator to reflect zoomed detail area |
745
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1406 var setBirdZoom = function(data, rect) { |
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1407 var part = data.imgTrafo.invtransform(rect); |
747
fd4842f0afc7
smoother birdZoom indicator movement; fixed bug in jQuery.offset()
hertzhaft
parents:
746
diff
changeset
|
1408 // area = FULL_AREA.fit(part); // no, we want to see where we transcend the borders |
745
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1409 birdTrafo = getImgTrafo(data.$birdImg, FULL_AREA); |
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1410 var birdRect = birdTrafo.transform(part); |
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1411 // acount for border width |
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1412 birdRect.addPosition({x : -2, y : -2}); |
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1413 birdRect.adjustDiv(data.$birdZoom); |
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1414 }; |
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1415 |
746
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1416 // set zoom background |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1417 var setZoomBG = function(data) { |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1418 var $scaler = data.$scaler; |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1419 var $img = data.$img; |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1420 var fullRect = null; |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1421 // hide the scaler img, show background of div instead |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1422 $img.css('visibility', 'hidden'); |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1423 var scalerCss = { |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1424 'background-image' : 'url(' + $img.attr('src') + ')', |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1425 'background-repeat' : 'no-repeat', |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1426 'background-position' : 'left top', |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1427 'opacity' : '0.5', |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1428 'cursor' : 'move' |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1429 }; |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1430 if (data.hasBgSize) { |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1431 // full-size background using CSS3-background-size |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1432 fullRect = data.imgTrafo.transform(FULL_AREA); |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1433 if (fullRect.height < data.settings.maxBgSize && fullRect.width < data.settings.maxBgSize) { |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1434 // correct offset because background is relative |
751
00b7857f07f5
zoom-drag background follows birdZoom also in embedded mode (still imprecise)
hertzhaft
parents:
748
diff
changeset
|
1435 var scalerPos = geom.position($scaler); |
00b7857f07f5
zoom-drag background follows birdZoom also in embedded mode (still imprecise)
hertzhaft
parents:
748
diff
changeset
|
1436 fullRect.addPosition(scalerPos.neg()); |
746
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1437 var url = getBirdImgUrl(data, ['rot', 'mo']); |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1438 scalerCss['background-image'] = 'url(' + url + ')'; |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1439 scalerCss[data.bgSizeName] = fullRect.width + 'px ' + fullRect.height + 'px'; |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1440 scalerCss['background-position'] = fullRect.x + 'px '+ fullRect.y + 'px'; |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1441 } else { |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1442 // too big |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1443 fullRect = null; |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1444 } |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1445 } |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1446 $scaler.css(scalerCss); |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1447 // isBgReady = true; |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1448 return fullRect; |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1449 }; |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1450 |
738 | 1451 // setup handlers for dragging the zoomed image |
705 | 1452 var setupZoomDrag = function(data) { |
746
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1453 var startPos, delta, fullRect; |
733 | 1454 var $document = $(document); |
705 | 1455 var $elem = data.$elem; |
1456 var $scaler = data.$scaler; | |
1457 var $img = data.$img; | |
710 | 1458 |
733 | 1459 // drag the image and load a new detail on mouse up |
705 | 1460 var dragStart = function (evt) { |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1461 console.debug("dragstart at=",evt); |
737
7c93bdbb5153
setup zoomdrag even when image is not initially zoomed
hertzhaft
parents:
736
diff
changeset
|
1462 // don't start dragging if not zoomed |
7c93bdbb5153
setup zoomdrag even when image is not initially zoomed
hertzhaft
parents:
736
diff
changeset
|
1463 if (isFullArea(data.zoomArea)) return false; |
733 | 1464 startPos = geom.position(evt); |
741 | 1465 delta = null; |
746
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1466 // set low res background immediately on mousedown |
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1467 fullRect = setZoomBG(data); |
733 | 1468 $document.bind("mousemove.dlZoomDrag", dragMove); |
1469 $document.bind("mouseup.dlZoomDrag", dragEnd); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1470 return false; |
705 | 1471 }; |
745
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1472 |
733 | 1473 // mousemove handler: drag zoomed image |
705 | 1474 var dragMove = function (evt) { |
1475 var pos = geom.position(evt); | |
741 | 1476 delta = startPos.delta(pos); |
1477 if (fullRect) { | |
1478 var bgPos = fullRect.getPosition().add(delta); | |
1479 } else { | |
1480 var bgPos = delta; | |
1481 } | |
705 | 1482 // move the background image to the new position |
715 | 1483 $scaler.css({ |
741 | 1484 'background-position' : bgPos.x + "px " + bgPos.y + "px" |
705 | 1485 }); |
746
2e9a48dc7a0c
move zoom-drag background along with birdview indicator
hertzhaft
parents:
745
diff
changeset
|
1486 // set birdview indicator to reflect new zoom position |
745
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1487 var za = geom.rectangle($img); |
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1488 za.addPosition(delta.neg()); |
ad483c008159
move birdview zoom indicator along with zoom drag
hertzhaft
parents:
744
diff
changeset
|
1489 setBirdZoom(data, za); |
705 | 1490 return false; |
1491 }; | |
710 | 1492 |
733 | 1493 // mouseup handler: reload zoomed image in new position |
705 | 1494 var dragEnd = function (evt) { |
739 | 1495 $scaler.css('cursor', 'auto'); |
733 | 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'); | |
741 | 1501 $scaler.css({'opacity' : '1', 'background-image' : 'none'}); |
733 | 1502 return false; |
1503 } | |
1504 // get old zoom area (screen coordinates) | |
741 | 1505 var za = geom.rectangle($img); |
733 | 1506 // move |
741 | 1507 za.addPosition(delta.neg()); |
733 | 1508 // transform back |
1509 var newArea = data.imgTrafo.invtransform(za); | |
735
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
1510 data.zoomArea = FULL_AREA.fit(newArea); |
708
120ace160386
img reload works for fullscreen, but somehow not precise
hertzhaft
parents:
707
diff
changeset
|
1511 redisplay(data); |
705 | 1512 return false; |
1513 }; | |
735
790a7673bef0
improved some embedded buttons; fixed reset function
hertzhaft
parents:
733
diff
changeset
|
1514 |
733 | 1515 // clear old handler |
1516 $document.unbind(".dlZoomDrag"); | |
741 | 1517 $scaler.unbind(".dlZoomDrag"); |
742
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1518 if (! isFullArea(data.zoomArea)) { |
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1519 // set handler |
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1520 $scaler.bind("mousedown.dlZoomDrag", dragStart); |
2b6d3ef57d68
fixed problem with setmark, zoomarea and zoomDrag handlers.
robcast
parents:
741
diff
changeset
|
1521 } |
705 | 1522 }; |
1523 | |
703 | 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); | |
706 | 1529 }; |
703 | 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]; | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1537 } |
703 | 1538 flags['q'+qual] = 'q'+qual; |
706 | 1539 }; |
710 | 1540 |
761
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1541 // get image scale mode (screen, pixel, size) |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1542 var getScaleMode = function (data) { |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1543 if (data.scalerFlags.clip != null) { |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1544 return 'pixel'; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1545 } else if (data.scalerFlags.osize != null) { |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1546 return 'size'; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1547 } |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1548 // mo=fit is default |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1549 return 'screen'; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1550 }; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1551 |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1552 // set image scale mode (screen, pixel, size) |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1553 var setScaleMode = function (data, mode) { |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1554 delete data.scalerFlags.fit; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1555 delete data.scalerFlags.clip; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1556 delete data.scalerFlags.osize; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1557 if (mode === 'pixel') { |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1558 data.scalerFlags.clip = 'clip'; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1559 } else if (mode === 'size') { |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1560 data.scalerFlags.osize = 'osize'; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1561 } |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1562 // mo=fit is default |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1563 }; |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1564 |
16778bd2de7c
added setScaleMode. no compensation for change in scaling yet.
robcast
parents:
760
diff
changeset
|
1565 // sets a key to a value (relative values with +/- if relative=true) |
650 | 1566 var setNumValue = function(settings, key, value) { |
716 | 1567 if (value == null) return null; |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1568 if (isNumber(value)) { |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1569 settings[key] = value; |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1570 return value; |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1571 } |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1572 var sign = value[0]; |
650 | 1573 if (sign === '+' || sign === '-') { |
1574 if (settings[key] == null) { | |
651
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1575 // this isn't perfect but still... |
650 | 1576 settings[key] = 0; |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1577 } |
650 | 1578 settings[key] = parseFloat(settings[key]) + parseFloat(value); |
1579 } else { | |
1580 settings[key] = value; | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1581 } |
650 | 1582 return settings[key]; |
1583 }; | |
655 | 1584 |
1585 // auxiliary function (from old dllib.js) | |
732
55f2dd197ca9
really renamed birdMoveArea, really merged fix for no zoom area.
robcast
parents:
731
diff
changeset
|
1586 var isFullArea = function(area) { |
659 | 1587 return (area.width === 1.0) && (area.height === 1.0); |
655 | 1588 }; |
1589 | |
641 | 1590 // auxiliary function (from Douglas Crockford, A.10) |
1591 var isNumber = function isNumber(value) { | |
710 | 1592 return typeof value === 'number' && isFinite(value); |
641 | 1593 }; |
655 | 1594 |
631 | 1595 // auxiliary function to crop senseless precision |
1596 var cropFloat = function (x) { | |
637 | 1597 return parseInt(10000 * x, 10) / 10000; |
631 | 1598 }; |
655 | 1599 |
692 | 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'); | |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1617 } |
692 | 1618 |
605 | 1619 // hook plugin into jquery |
760
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1620 $.fn.digilib = function(action, obj) { |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1621 // plugin extension mechanism |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1622 if (action === 'extendPlugin') { |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1623 // for each digilib $elem extend data.settings with obj.options |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1624 if (obj.options) { |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1625 this.each(function() { |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1626 var $elem = $(this); |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1627 // console.debug('extending:', $elem); |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1628 var data = $elem.data('digilib'); |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1629 if (!data) { |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1630 return console.log('cannot extend digilib plugin, element not initialised!'); |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1631 } |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1632 var settings = data.settings; |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1633 $.extend(settings, obj.options); |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1634 // console.log('settings:', settings); |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1635 }); |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1636 } |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1637 delete(obj.options); |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1638 // extend the plugin actions (to make this useful, |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1639 // maybe we need to expose some more internal functions) |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1640 $.extend(actions, obj); |
f0be4432f515
primitive plugin extension mechanism - unsure how useful this is
hertzhaft
parents:
755
diff
changeset
|
1641 } else if (actions[action]) { |
651
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1642 // call action on this with the remaining arguments (inserting data as first argument) |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1643 var $elem = $(this); |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1644 var data = $elem.data('digilib'); |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1645 var args = Array.prototype.slice.call(arguments, 1); |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1646 args.unshift(data); |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1647 return actions[action].apply(this, args); |
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1648 } else if (typeof(action) === 'object' || !action) { |
634 | 1649 // call init on this |
651
694bdb86cbad
renamed 'actions' to 'buttons' and 'methods' to 'actions'
robcast
parents:
650
diff
changeset
|
1650 return actions.init.apply(this, arguments); |
605 | 1651 } else { |
713
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1652 $.error('action ' + action + ' does not exist on jQuery.digilib'); |
c1fa722c570e
more cosmetics: added options to validate with http://www.jslint.com
robcast
parents:
711
diff
changeset
|
1653 } |
605 | 1654 }; |
692 | 1655 |
604 | 1656 })(jQuery); |