Mercurial > hg > digilib-old
annotate client/digitallibrary/jquery/jquery.digilib.regions.js @ 858:da4938dac521 stream
don't prestart threads.
doesn't really matter for tomcat since we need no-memory-leak-test for ImageIO anyway.
author | robcast |
---|---|
date | Tue, 08 Mar 2011 13:15:12 +0100 |
parents | 9fa078dcb493 |
children | 77248c6d2a5f |
rev | line source |
---|---|
792 | 1 /** optional digilib regions plugin |
2 | |
3 markup a digilib image with rectangular regions | |
4 | |
5 TODO: | |
6 - store region in params/cookie, regarding zoom, mirror, rotation (like marks) | |
7 - set regions programmatically | |
8 - read regions from params/cookie and display | |
9 - backlink mechanism | |
10 - don't write to data.settings? | |
11 */ | |
12 | |
13 (function($) { | |
813 | 14 // the digilib object |
15 var digilib; | |
792 | 16 // the data object passed by digilib |
17 var data; | |
813 | 18 // the functions made available by digilib |
792 | 19 var fn; |
813 | 20 // affine geometry plugin |
792 | 21 var geom; |
22 | |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
23 var FULL_AREA; |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
24 |
813 | 25 var ID_PREFIX = "digilib-region-"; |
26 | |
792 | 27 var buttons = { |
28 addregion : { | |
813 | 29 onclick : "defineRegion", |
30 tooltip : "define a region", | |
792 | 31 icon : "addregion.png" |
32 }, | |
33 delregion : { | |
34 onclick : "removeRegion", | |
35 tooltip : "delete the last region", | |
36 icon : "delregion.png" | |
37 }, | |
38 regions : { | |
39 onclick : "toggleRegions", | |
40 tooltip : "show or hide regions", | |
41 icon : "regions.png" | |
42 }, | |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
43 regionhtml : { |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
44 onclick : "showRegionHTML", |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
45 tooltip : "show information about regions", |
792 | 46 icon : "regioninfo.png" |
47 } | |
48 }; | |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
49 |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
50 var defaults = { |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
51 // are regions shown? |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
52 'isRegionVisible' : true, |
813 | 53 // are region numbers shown? |
54 'showRegionNumbers' : false, | |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
55 // is window with region HTML shown? |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
56 'showRegionHTML' : false, |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
57 // should digilib look for region content in the page? |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
58 'includeRegionContent' : false, |
823 | 59 // turn any region into a clickable link to its detail view |
60 'autoRegionLinks' : false, | |
61 // class name for content divs (must additionally be marked with class "keep") | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
62 'regionContentSelector' : 'div.regioncontent', |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
63 // buttonset of this plugin |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
64 'regionSet' : ['regions', 'addregion', 'delregion', 'regionhtml', 'lessoptions'], |
813 | 65 // url param for regions |
66 'rg' : null, | |
67 }; | |
792 | 68 |
69 var actions = { | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
70 |
792 | 71 // define a region interactively with two clicked points |
813 | 72 "defineRegion" : function(data) { |
73 if (!data.settings.isRegionVisible) { | |
74 alert("Please turn on regions visibility!"); | |
75 return; | |
76 } | |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
77 var $elem = data.$elem; |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
78 var $body = $('body'); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
79 var bodyRect = geom.rectangle($body); |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
80 var $scaler = data.$scaler; |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
81 var scalerRect = geom.rectangle($scaler); |
792 | 82 var pt1, pt2; |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
83 // overlay prevents other elements from reacting to mouse events |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
84 var $overlay = $('<div class="digilib-overlay"/>'); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
85 $body.append($overlay); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
86 bodyRect.adjustDiv($overlay); |
823 | 87 var $regionDiv = addRegionDiv(data, data.regions.length); |
792 | 88 |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
89 // mousedown handler: start sizing |
792 | 90 var regionStart = function (evt) { |
91 pt1 = geom.position(evt); | |
92 // setup and show zoom div | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
93 pt1.adjustDiv($regionDiv); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
94 $regionDiv.width(0).height(0); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
95 $regionDiv.show(); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
96 // register mouse events |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
97 $overlay.bind("mousemove.dlRegion", regionMove); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
98 $overlay.bind("mouseup.dlRegion", regionEnd); |
792 | 99 return false; |
100 }; | |
101 | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
102 // mousemove handler: size region |
792 | 103 var regionMove = function (evt) { |
104 pt2 = geom.position(evt); | |
105 var rect = geom.rectangle(pt1, pt2); | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
106 rect.clipTo(scalerRect); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
107 // update region |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
108 rect.adjustDiv($regionDiv); |
792 | 109 return false; |
110 }; | |
111 | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
112 // mouseup handler: end sizing |
792 | 113 var regionEnd = function (evt) { |
114 pt2 = geom.position(evt); | |
115 // assume a click and continue if the area is too small | |
116 var clickRect = geom.rectangle(pt1, pt2); | |
117 if (clickRect.getArea() <= 5) return false; | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
118 // unregister mouse events and get rid of overlay |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
119 $overlay.unbind("mousemove.dlRegion", regionMove); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
120 $overlay.unbind("mouseup.dlRegion", regionEnd); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
121 $overlay.remove(); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
122 // clip region |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
123 clickRect.clipTo(scalerRect); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
124 clickRect.adjustDiv($regionDiv); |
813 | 125 storeRegion(data, $regionDiv); |
792 | 126 // fn.redisplay(data); |
813 | 127 fn.highlightButtons(data, 'addregion', 0); |
128 redisplay(data); | |
792 | 129 return false; |
130 }; | |
131 | |
132 // bind start zoom handler | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
133 $overlay.one('mousedown.dlRegion', regionStart); |
813 | 134 fn.highlightButtons(data, 'addregion', 1); |
792 | 135 }, |
136 | |
137 // remove the last added region | |
138 "removeRegion" : function (data) { | |
813 | 139 if (!data.settings.isRegionVisible) { |
140 alert("Please turn on regions visibility!"); | |
141 return; | |
142 } | |
143 var region = data.regions.pop(); | |
144 if (region == null) return; | |
145 var $regionDiv = region.$div; | |
792 | 146 $regionDiv.remove(); |
813 | 147 redisplay(data); |
792 | 148 }, |
149 | |
813 | 150 // show/hide regions |
151 "toggleRegions" : function (data) { | |
152 var show = !data.settings.isRegionVisible; | |
153 data.settings.isRegionVisible = show; | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
154 fn.highlightButtons(data, 'regions', show); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
155 showRegionDivs(data, 1); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
156 }, |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
157 |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
158 // show/hide region HTML code |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
159 "showRegionHTML" : function (data) { |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
160 var show = !data.settings.showRegionHTML; |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
161 data.settings.showRegionHTML = show; |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
162 fn.highlightButtons(data, 'regionhtml', show); |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
163 var $html = data.$htmlDiv; |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
164 if (!show) { |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
165 $html.fadeOut(function () { |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
166 $html.contents().remove(); |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
167 }); |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
168 return; |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
169 } |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
170 // empty the div for HTML display |
835 | 171 $html.append($('<div/>').text('<div class="keep regioncontent">')); |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
172 $.each(data.regions, function(index, region) { |
835 | 173 var area = "area:" |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
174 + region.x + "/" + region.y + "/" |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
175 + region.width + "/" + region.height; |
835 | 176 $html.append($('<div/>').text('<a href="" rel="' + area + '">')); |
177 $html.append($('<div/>').text('</a>')); | |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
178 }); |
835 | 179 $html.append($('<div/>').text('</div>')); |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
180 $html.fadeIn(); |
792 | 181 } |
182 }; | |
183 | |
813 | 184 // store a region div |
185 var storeRegion = function (data, $regionDiv) { | |
186 var regions = data.regions; | |
187 var rect = geom.rectangle($regionDiv); | |
188 var regionRect = data.imgTrafo.invtransform(rect); | |
189 regionRect.$div = $regionDiv; | |
190 regions.push(regionRect); | |
191 console.debug("regions", data.regions, "regionRect", regionRect); | |
192 }; | |
193 | |
194 // add a region to data.$elem | |
823 | 195 var addRegionDiv = function (data, index) { |
196 var nr = index + 1; // we count regions from 1 | |
197 // create a digilib URL for this detail | |
198 var regionUrl = getRegionUrl(data, index); | |
813 | 199 var $regionDiv = $('<div class="region overlay" style="display:none"/>'); |
200 $regionDiv.attr("id", ID_PREFIX + nr); | |
201 data.$elem.append($regionDiv); | |
202 if (data.settings.showRegionNumbers) { | |
823 | 203 var $regionNr = $('<div class="regionnumber"/>'); |
204 var $regionLink = $('<a/>'); | |
205 $regionLink.attr('href', regionUrl); | |
206 $regionLink.text(nr); | |
207 $regionNr.append($regionLink); | |
813 | 208 $regionDiv.append($regionNr); |
209 } | |
823 | 210 if (data.settings.autoRegionLinks) { |
211 $regionDiv.bind('click.dlRegion', function() { | |
212 window.location = regionUrl; | |
213 }) | |
214 } | |
813 | 215 return $regionDiv; |
216 }; | |
217 | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
218 // add region content |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
219 var addRegionContent = function (region, $elem) { |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
220 var $regionDiv = region.$div; |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
221 $regionDiv.append($elem); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
222 } |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
223 |
813 | 224 // create a region div from the data.regions collection |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
225 var createRegionDiv = function (regions, index) { |
813 | 226 var region = regions[index]; |
823 | 227 var $regionDiv = addRegionDiv(data, index); |
813 | 228 region.$div = $regionDiv; |
229 return $regionDiv; | |
230 }; | |
231 | |
232 // create regions | |
233 var createRegionDivs = function (data) { | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
234 var regions = data.regions; |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
235 $.each(regions, function(i) { |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
236 createRegionDiv(regions, i); |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
237 }); |
792 | 238 }; |
239 | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
240 // create regions from HTML |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
241 var createRegionsFromHTML = function (data) { |
823 | 242 var regions = data.regions; |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
243 var selector = data.settings.regionContentSelector; |
835 | 244 var $content = data.$elem.contents(selector).contents('a'); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
245 console.debug("createRegionsFromHTML", $content); |
835 | 246 $content.each(function(index, a) { |
247 var $a = $(a); | |
248 var href = $a.attr('href'); | |
249 var rel = $a.attr('rel'); | |
250 var area = rel.replace(/^area:/i, ''); | |
251 var pos = area.split("/", 4); | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
252 var rect = geom.rectangle(pos[0], pos[1], pos[2], pos[3]); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
253 regions.push(rect); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
254 var $regionDiv = createRegionDiv(regions, index); |
835 | 255 $regionDiv.append($a.clone()); |
256 // $a.show(); | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
257 }); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
258 }; |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
259 |
813 | 260 // show a region on top of the scaler image |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
261 var showRegionDiv = function (data, index, anim) { |
813 | 262 if (!data.imgTrafo) return; |
263 var $elem = data.$elem; | |
792 | 264 var regions = data.regions; |
813 | 265 if (index > regions.length) return; |
266 var region = regions[index] | |
267 var $regionDiv = region.$div; | |
268 if (!$regionDiv) { | |
269 console.debug("showRegionDiv: region has no $div", region); | |
270 // alert("showRegionDiv: region has no $div to show"); | |
271 return; | |
272 } | |
273 var regionRect = region.copy(); | |
274 var show = data.settings.isRegionVisible; | |
275 if (show && data.zoomArea.overlapsRect(regionRect)) { | |
276 regionRect.clipTo(data.zoomArea); | |
277 var screenRect = data.imgTrafo.transform(regionRect); | |
278 screenRect.adjustDiv($regionDiv); | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
279 if (anim) { |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
280 $regionDiv.fadeIn(); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
281 } else{ |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
282 $regionDiv.show(); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
283 } |
813 | 284 } else { |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
285 if (anim) { |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
286 $regionDiv.fadeOut(); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
287 } else{ |
824 | 288 $regionDiv.hide(); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
289 } |
813 | 290 } |
291 }; | |
292 | |
293 // show regions | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
294 var showRegionDivs = function (data, anim) { |
813 | 295 for (var i = 0; i < data.regions.length ; i++) { |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
296 showRegionDiv(data, i, anim); |
813 | 297 } |
298 }; | |
299 | |
300 var unpackRegions = function (data) { | |
301 // create regions from parameters | |
302 var rg = data.settings.rg; | |
303 if (rg == null) return; | |
304 var regions = data.regions; | |
305 var rs = rg.split(","); | |
306 for (var i = 0; i < rs.length; i++) { | |
307 var r = rs[i]; | |
308 var pos = r.split("/", 4); | |
309 var rect = geom.rectangle(pos[0], pos[1], pos[2], pos[3]); | |
310 regions.push(rect); | |
792 | 311 } |
312 }; | |
313 | |
813 | 314 // pack regions array into a parameter string |
315 var packRegions = function (data) { | |
316 var regions = data.regions; | |
815 | 317 if (!regions.length) { |
318 data.settings.rg = null; | |
319 return; | |
320 } | |
813 | 321 var rg = ''; |
322 for (var i = 0; i < regions.length; i++) { | |
323 region = regions[i]; | |
324 if (i) { | |
325 rg += ','; | |
792 | 326 } |
813 | 327 rg += [ |
328 fn.cropFloatStr(region.x), | |
329 fn.cropFloatStr(region.y), | |
330 fn.cropFloatStr(region.width), | |
331 fn.cropFloatStr(region.height) | |
332 ].join('/'); | |
333 } | |
334 data.settings.rg = rg; | |
792 | 335 }; |
336 | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
337 // reload display after a region has been added or removed |
813 | 338 var redisplay = function (data) { |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
339 if (!data.settings.includeRegionContent) { |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
340 packRegions(data); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
341 } |
813 | 342 fn.redisplay(data); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
343 }; |
813 | 344 |
823 | 345 // for turning region numbers/region divs into links to zoomed details |
346 var getRegionUrl = function (data, index) { | |
347 var region = data.regions[index]; | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
348 var settings = data.settings; |
823 | 349 var params = { |
350 "fn" : settings.fn, | |
351 "pn" : settings.pn | |
352 }; | |
353 fn.packArea(params, region); | |
354 fn.packMarks(params, data.marks); | |
355 fn.packScalerFlags(params, data.scalerFlags); | |
356 var paramNames = digilib.defaults.digilibParamNames; | |
357 // build our own digilib URL without storing anything | |
358 var queryString = fn.getParamString(params, paramNames, digilib.defaults); | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
359 return settings.digilibBaseUrl + '?' + queryString; |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
360 }; |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
361 |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
362 // event handler, reads region parameter and creates region divs |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
363 var handleSetup = function (evt) { |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
364 data = this; |
813 | 365 console.debug("regions: handleSetup", data.settings.rg); |
823 | 366 // regions with content are given in HTML divs |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
367 if (data.settings.includeRegionContent) { |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
368 createRegionsFromHTML(data); |
823 | 369 // regions are defined in the URL |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
370 } else { |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
371 unpackRegions(data); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
372 createRegionDivs(data); |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
373 fn.highlightButtons(data, 'regionhtml', data.settings.showRegionHTML); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
374 } |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
375 }; |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
376 |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
377 // event handler, sets buttons and shows regions |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
378 var handleUpdate = function (evt) { |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
379 data = this; |
813 | 380 fn.highlightButtons(data, 'regions' , data.settings.isRegionVisible); |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
381 fn.highlightButtons(data, 'regionhtml' , data.settings.showRegionHTML); |
813 | 382 showRegionDivs(data); |
383 console.debug("regions: handleUpdate", data.settings.rg); | |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
384 }; |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
385 |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
386 // event handler, redisplays regions (e.g. in a new position) |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
387 var handleRedisplay = function (evt) { |
813 | 388 data = this; |
389 showRegionDivs(data); | |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
390 console.debug("regions: handleRedisplay"); |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
391 }; |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
392 |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
393 // event handler |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
394 var handleDragZoom = function (evt, zoomArea) { |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
395 // console.debug("regions: handleDragZoom, zoomArea:", zoomArea); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
396 // data = this; |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
397 }; |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
398 |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
399 // plugin installation called by digilib on plugin object. |
813 | 400 var install = function(plugin) { |
401 digilib = plugin; | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
402 console.debug('installing regions plugin. digilib:', digilib); |
813 | 403 fn = digilib.fn; |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
404 // import geometry classes |
813 | 405 geom = fn.geometry; |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
406 FULL_AREA = geom.rectangle(0,0,1,1); |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
407 // add defaults, actions, buttons |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
408 $.extend(digilib.defaults, defaults); |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
409 $.extend(digilib.actions, actions); |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
410 $.extend(digilib.buttons, buttons); |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
411 }; |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
412 |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
413 // plugin initialization |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
414 var init = function (data) { |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
415 console.debug('initialising regions plugin. data:', data); |
835 | 416 var $elem = data.$elem; |
823 | 417 // regions array |
418 data.regions = []; | |
835 | 419 // regions div |
420 var $html = $('<div class="keep regionHTML"/>'); | |
421 $elem.append($html); | |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
422 data.$htmlDiv = $html; |
823 | 423 // no URL-defined regions, no buttons when regions are predefined in HTML |
835 | 424 var hasRegionContent = data.settings.includeRegionContent; |
425 if (!hasRegionContent) { | |
823 | 426 // add "rg" to digilibParamNames |
427 data.settings.digilibParamNames.push('rg'); | |
428 // additional buttons | |
429 var buttonSettings = data.settings.buttonSettings.fullscreen; | |
430 // configure buttons through digilib "regionSet" option | |
431 var buttonSet = data.settings.regionSet || regionSet; | |
432 // set regionSet to [] or '' for no buttons (when showing regions only) | |
433 if (buttonSet.length && buttonSet.length > 0) { | |
434 buttonSettings['regionSet'] = buttonSet; | |
435 buttonSettings.buttonSets.push('regionSet'); | |
436 } | |
813 | 437 } |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
438 // install event handler |
835 | 439 var $data = $(data); |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
440 $data.bind('setup', handleSetup); |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
441 $data.bind('update', handleUpdate); |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
442 $data.bind('redisplay', handleRedisplay); |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
443 $data.bind('dragZoom', handleDragZoom); |
792 | 444 }; |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
445 |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
446 // plugin object with name and install/init methods |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
447 // shared objects filled by digilib on registration |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
448 var pluginProperties = { |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
449 name : 'region', |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
450 install : install, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
451 init : init, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
452 buttons : {}, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
453 actions : {}, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
454 fn : {}, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
455 plugins : {} |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
456 }; |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
457 |
792 | 458 if ($.fn.digilib == null) { |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
459 $.error("jquery.digilib.regions must be loaded after jquery.digilib!"); |
792 | 460 } else { |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
461 $.fn.digilib('plugin', pluginProperties); |
792 | 462 } |
463 })(jQuery); |