annotate client/digitallibrary/jquery/jquery.digilib.js @ 613:53ee659e2d00 jquery

keeping img tag for embedded mode seems to work now
author robcast
date Sun, 16 Jan 2011 00:56:59 +0100
parents fb94f1b74d59
children 0bd19b6cede4 5a7f82f10a5d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
604
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
1 /*
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
2 * digilib jQuery plugin
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
3 *
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
4 */
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
5
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
6 (function($) {
610
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
7 var buttons = {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
8 reference : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
9 onclick : "javascript:getRefWin()",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
10 tooltip : "get a reference URL",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
11 img : "reference.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
12 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
13 zoomin : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
14 onclick : "javascript:dl.zoomBy(1.4)",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
15 tooltip : "zoom in",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
16 img : "zoom-in.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
17 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
18 zoomout : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
19 onclick : "javascript:zoomBy(0.7)",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
20 tooltip : "zoom out",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
21 img : "zoom-out.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
22 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
23 zoomarea : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
24 onclick : "javascript:zoomArea()",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
25 tooltip : "zoom area",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
26 img : "zoom-area.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
27 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
28 zoomfull : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
29 onclick : "javascript:zoomFullpage()",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
30 tooltip : "view the whole image",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
31 img : "zoom-full.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
32 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
33 pagewidth : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
34 onclick : "javascript:zoomFullpage('width')",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
35 tooltip : "page width",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
36 img : "pagewidth.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
37 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
38 back : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
39 onclick : "javascript:gotoPage('-1')",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
40 tooltip : "goto previous image",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
41 img : "back.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
42 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
43 fwd : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
44 onclick : "javascript:gotoPage('+1')",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
45 tooltip : "goto next image",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
46 img : "fwd.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
47 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
48 page : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
49 onclick : "javascript:gotoPageWin()",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
50 tooltip : "specify image",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
51 img : "page.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
52 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
53 bird : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
54 onclick : "javascript:toggleBirdDiv()",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
55 tooltip : "show bird's eye view",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
56 img : "birds-eye.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
57 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
58 help : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
59 onclick : "javascript:toggleAboutDiv()",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
60 tooltip : "about Digilib",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
61 img : "help.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
62 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
63 reset : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
64 onclick : "javascript:resetImage()",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
65 tooltip : "reset image",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
66 img : "reset.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
67 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
68 mark : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
69 onclick : "javascript:setMark()",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
70 tooltip : "set a mark",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
71 img : "mark.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
72 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
73 delmark : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
74 onclick : "javascript:removeMark()",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
75 tooltip : "delete the last mark",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
76 img : "delmark.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
77 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
78 hmir : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
79 onclick : "javascript:mirror('h')",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
80 tooltip : "mirror horizontally",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
81 img : "mirror-horizontal.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
82 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
83 vmir : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
84 onclick : "javascript:mirror('v')",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
85 tooltip : "mirror vertically",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
86 img : "mirror-vertical.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
87 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
88 rot : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
89 onclick : "javascript:setParamWin('rot', 'Rotate (0..360) clockwise')",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
90 tooltip : "rotate image",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
91 img : "rotate.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
92 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
93 brgt : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
94 onclick : "javascript:setParamWin('brgt', 'Brightness (-255..255)')",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
95 tooltip : "set brightness",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
96 img : "brightness.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
97 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
98 cont : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
99 onclick : "javascript:setParamWin('cont', 'Contrast (0..8)')",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
100 tooltip : "set contrast",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
101 img : "contrast.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
102 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
103 rgb : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
104 onclick : "javascript:setParamWin('rgb', '...')",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
105 tooltip : "set rgb values",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
106 img : "rgb.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
107 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
108 quality : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
109 onclick : "javascript:setQualityWin('Quality (0..2)')",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
110 tooltip : "set image quality",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
111 img : "quality.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
112 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
113 size : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
114 onclick : "javascript:toggleSizeMenu()",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
115 tooltip : "set page size",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
116 img : "size.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
117 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
118 calibrationx : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
119 onclick : "javascript:calibrate('x')",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
120 tooltip : "calibrate screen x-ratio",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
121 img : "calibration-x.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
122 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
123 scale : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
124 onclick : "javascript:toggleScaleMenu()",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
125 tooltip : "change image scale",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
126 img : "original-size.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
127 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
128 options : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
129 onclick : "javascript:toggleOptionDiv()",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
130 tooltip : "hide options",
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
131 img : "options.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
132 },
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
133 SEP : {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
134 img : "sep.png"
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
135 }
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
136 };
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
137
605
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
138 var defaults = {
610
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
139 // base URL to Scaler servlet
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
140 'scalerBaseUrl' : 'http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler',
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
141 // list of Scaler parameters
609
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
142 'scalerParamNames' : ['fn','pn','dw','dh','ww','wh','wx','wy','ws','mo',
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
143 'rot','cont','brgt','rgbm','rgba','ddpi','ddpix','ddpiy'],
610
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
144 // mode of operation.
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
145 // fullscreen: takes parameters from page URL, keeps state in page URL
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
146 // embedded: takes parameters from Javascript options, keeps state inside object
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
147 'interactionMode' : 'fullscreen',
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
148 // buttons
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
149 'buttons' : buttons,
612
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
150 // path to button images (must end with a slash)
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
151 'buttonsImagePath' : '../greyskin/',
610
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
152 // button groups
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
153 'buttonsStandard' : ["reference","zoomin","zoomout","zoomarea","zoomfull","pagewidth","back","fwd","page","bird","SEP","help","reset","options"],
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
154 'buttonsSpecial' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","size","calibrationx","scale","SEP","options"],
611
1b6202aba26e work on button creation
robcast
parents: 610
diff changeset
155 'buttonsCustom' : []
610
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
156 };
605
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
157
608
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
158 // parameters from the query string
607
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
159 var queryParams = {};
608
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
160
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
161 // affine geometry classes
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
162 var geom = dlGeometry();
604
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
163
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
164 var methods = {
608
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
165 // digilib initialization
604
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
166 init : function(options) {
608
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
167 // settings for this digilib instance are merged from defaults and options
607
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
168 var settings = $.extend({}, defaults, options);
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
169 var isFullscreen = settings.interactionMode === 'fullscreen';
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
170 if (isFullscreen) {
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
171 queryParams = parseQueryParams();
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
172 };
604
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
173 return this.each(function() {
605
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
174 var $elem = $(this);
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
175 var data = $elem.data('digilib');
607
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
176 var elemSettings;
608
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
177 // if the plugin hasn't been initialized yet
604
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
178 if (!data) {
605
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
179 // merge query parameters
607
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
180 if (isFullscreen) {
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
181 elemSettings = $.extend({}, settings, queryParams);
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
182 } else {
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
183 elemSettings = $.extend({}, settings, parseImgParams($elem));
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
184 };
605
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
185 // store in data element
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
186 $elem.data('digilib', {
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
187 target : $elem,
607
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
188 settings : elemSettings
604
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
189 });
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
190 }
608
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
191 // create HTML structure
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
192 setupScalerDiv($elem, elemSettings);
611
1b6202aba26e work on button creation
robcast
parents: 610
diff changeset
193 setupButtons($elem, elemSettings, 'buttonsStandard');
604
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
194 });
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
195 },
608
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
196
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
197 // clean up digilib
604
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
198 destroy : function() {
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
199 return this.each(function(){
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
200 var $this = $(this);
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
201 var data = $this.data('digilib');
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
202 // Namespacing FTW
605
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
203 $(window).unbind('.digilib'); // unbinds all digilibs(?)
604
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
204 data.digilib.remove();
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
205 $this.removeData('digilib');
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
206 });
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
207 }
605
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
208 };
604
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
209
608
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
210 // returns parameters from page url
607
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
211 var parseQueryParams = function() {
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
212 return parseQueryString(location.search.slice(1));
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
213 };
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
214
608
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
215 // returns parameters taken from embedded img-element
607
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
216 var parseImgParams = function($elem) {
613
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
217 var src = $elem.find('img').first().attr('src');
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
218 if (!src) {
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
219 return null;
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
220 }
607
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
221 var pos = src.indexOf('?');
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
222 var query = (pos < 0) ? '' : src.substring(pos + 1);
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
223 var scalerUrl = src.substring(0, pos);
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
224 var hash = parseQueryString(query);
609
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
225 hash.scalerBaseUrl = scalerUrl;
607
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
226 // console.log(hash);
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
227 return hash;
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
228 };
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
229
608
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
230 // parses query parameter string into parameter object
607
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
231 var parseQueryString = function(query) {
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
232 var pairs = query.split("&");
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
233 var hash = {};
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
234 for (var i = 0; i < pairs.length; i++) {
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
235 var pair = pairs[i].split("=");
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
236 if (pair.length === 2) {
608
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
237 hash[pair[0]] = pair[1];
607
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
238 };
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
239 };
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
240 return hash;
f5d5cae64828 parameter parsing
hertzhaft
parents: 605
diff changeset
241 };
604
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
242
608
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
243 // returns URL and query string for Scaler
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
244 var getScalerString = function (settings) {
609
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
245 var url = settings.scalerBaseUrl + '?';
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
246 var i, parm, latter;
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
247 // go through param names and get values from settings
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
248 for (i = 0; i < settings.scalerParamNames.length; ++i) {
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
249 parm = settings.scalerParamNames[i];
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
250 if (settings[parm]) {
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
251 // first parm gets no '&'
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
252 url += latter ? '&' : '';
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
253 latter = 1;
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
254 // add parm=val
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
255 url += parm + '=' + settings[parm];
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
256 }
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
257 }
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
258 return url;
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
259 };
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
260
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
261 // returns maximum size for scaler img in fullscreen mode
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
262 var getFullscreenImgSize = function($elem) {
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
263 var winH = $(window).height();
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
264 var winW = $(window).width();
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
265 // TODO: account for borders?
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
266 return geom.size(winW, winH);
608
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
267 };
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
268
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
269 // creates HTML structure for digilib in elem
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
270 var setupScalerDiv = function ($elem, settings) {
613
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
271 var rewrite;
608
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
272 if (settings.interactionMode === 'fullscreen') {
609
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
273 // fullscreen
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
274 var imgSize = getFullscreenImgSize($elem);
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
275 settings.dw = imgSize.width;
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
276 settings.dh = imgSize.height;
613
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
277 $img = $('<img/>');
609
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
278 var scalerUrl = getScalerString(settings);
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
279 $img.attr('src', scalerUrl);
613
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
280 $img.addClass('pic');
609
435f81210a33 start work on scaler call
robcast
parents: 608
diff changeset
281 } else {
613
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
282 // embedded mode -- try to keep img tag
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
283 var $img = $elem.find('img');
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
284 if ($img.length > 0) {
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
285 console.debug("img detach:",$img);
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
286 $img.detach();
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
287 $img.addClass('picsi');
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
288 } else {
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
289 $img = $('<img/>');
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
290 var scalerUrl = getScalerString(settings);
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
291 $img.attr('src', scalerUrl);
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
292 $img.addClass('pic');
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
293 }
608
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
294 }
613
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
295 // create new html
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
296 $elem.empty(); // TODO: should we keep stuff for customization?
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
297 var $scaler = $('<div class="scaler"/>');
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
298 $elem.append($scaler);
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
299 $scaler.append($img);
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
300 $img.load(scalerImgLoadedFn(settings));
608
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
301 };
774a3f60efd5 start work on scaler call
robcast
parents: 607
diff changeset
302
610
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
303 // creates HTML structure for buttons in elem
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
304 var setupButtons = function ($elem, settings, buttonGroup) {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
305 if (settings.interactionMode === 'fullscreen') {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
306 // fullscreen -- create new
612
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
307 var $buttonsDiv = $('<div class="buttons"></div>');
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
308 $elem.append($buttonsDiv);
610
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
309 var buttonNames = settings[buttonGroup];
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
310 for (var i = 0; i < buttonNames.length; i++) {
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
311 var buttonName = buttonNames[i];
612
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
312 var buttonSettings = settings.buttons[buttonName];
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
313 // construct the button html
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
314 var $button = $('<div class="button"></div>');
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
315 var $a = $('<a/>');
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
316 var $img = $('<img/>');
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
317 $buttonsDiv.append($button);
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
318 $button.append($a);
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
319 $a.append($img);
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
320 // add attributes and bindings
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
321 $button.attr('title', buttonSettings.tooltip);
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
322 $button.addClass('button-' + buttonName);
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
323 // let the clicked <a> element know about the digilib context
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
324 $a.data('digilib', { 'name' : buttonName, 'settings' : settings } );
613
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
325 $a.bind('click', function() {
612
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
326 // get the context settings
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
327 var data = $(this).data('digilib');
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
328 // find the action for the clicked element
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
329 console.log(data.settings.buttons[data.name].onclick);
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
330 });
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
331 // binding mit closure
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
332 //(function(){ var action = buttonSettings.onclick;
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
333 // $a.bind('click', function(){ console.log( action )} );
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
334 //})();
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
335 $img.attr('src', settings.buttonsImagePath + buttonSettings.img);
611
1b6202aba26e work on button creation
robcast
parents: 610
diff changeset
336 };
1b6202aba26e work on button creation
robcast
parents: 610
diff changeset
337 }
612
fb94f1b74d59 bind data and actions to buttons
hertzhaft
parents: 611
diff changeset
338 return $buttonsDiv;
610
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
339 };
cd9f657d49fa code for generating the buttons
hertzhaft
parents: 609
diff changeset
340
613
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
341 // returns function for load event of scaler img
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
342 var scalerImgLoadedFn = function(settings) {
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
343 return function() {
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
344 console.debug("img loaded! settings=", settings);
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
345 };
53ee659e2d00 keeping img tag for embedded mode seems to work now
robcast
parents: 612
diff changeset
346 };
605
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
347 // hook plugin into jquery
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
348 $.fn.digilib = function(method) {
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
349 if (methods[method]) {
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
350 return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
351 } else if (typeof(method) === 'object' || !method) {
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
352 return methods.init.apply(this, arguments);
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
353 } else {
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
354 $.error( 'Method ' + method + ' does not exist on jQuery.digilib' );
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
355 }
aee94e4a8c48 next version zero of jquery.digilib
robcast
parents: 604
diff changeset
356 };
604
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
357
3a2942d2d5cd version zero of jquery.digilib
robcast
parents:
diff changeset
358 })(jQuery);