annotate webapp/src/main/webapp/jquery/jquery.digilib.js @ 948:cd8c1fe97607

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