Mercurial > hg > digilib-old
annotate webapp/src/main/webapp/jquery/jquery.digilib.regions.js @ 1023:8e3462a753f0
small clean ups.
honor hasRegionContent from options.
author | robcast |
---|---|
date | Tue, 06 Mar 2012 17:58:14 +0100 |
parents | 0b63093d598e |
children | 4ee43243a6a0 |
rev | line source |
---|---|
792 | 1 /** optional digilib regions plugin |
2 | |
1023 | 3 Mark up a digilib image with rectangular regions. |
4 | |
5 If hasRegionInfo=true reads regions from page HTML. | |
6 Element with regions has to be in digilib element, e.g. | |
792 | 7 |
1023 | 8 <div class="dl-keep dl-regioncontent"> |
9 <a href="http://www.mpiwg-berlin.mpg.de" coords="0.1,0.1,0.4,0.1">MPI fuer Wissenschaftsgeschichte</a> | |
10 <a href="http://www.biblhertz.it" coords="0.5,0.8,0.4,0.1">Bibliotheca Hertziana</a> | |
11 <a coords="0.3,0.5,0.15,0.1" /> | |
12 </div> | |
13 | |
792 | 14 */ |
15 | |
16 (function($) { | |
813 | 17 // the digilib object |
996 | 18 var digilib = null; |
813 | 19 // the functions made available by digilib |
996 | 20 var fn = null; |
813 | 21 // affine geometry plugin |
996 | 22 var geom = null; |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
23 |
813 | 24 var ID_PREFIX = "digilib-region-"; |
25 | |
792 | 26 var buttons = { |
27 addregion : { | |
813 | 28 onclick : "defineRegion", |
29 tooltip : "define a region", | |
792 | 30 icon : "addregion.png" |
31 }, | |
32 delregion : { | |
33 onclick : "removeRegion", | |
34 tooltip : "delete the last region", | |
35 icon : "delregion.png" | |
36 }, | |
37 regions : { | |
38 onclick : "toggleRegions", | |
39 tooltip : "show or hide regions", | |
40 icon : "regions.png" | |
41 }, | |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
42 regionhtml : { |
855 | 43 onclick : "showRegionInfo", |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
44 tooltip : "show information about regions", |
792 | 45 icon : "regioninfo.png" |
46 } | |
47 }; | |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
48 |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
49 var defaults = { |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
50 // are regions shown? |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
51 'isRegionVisible' : true, |
813 | 52 // are region numbers shown? |
1023 | 53 'showRegionNumbers' : true, |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
54 // is window with region HTML shown? |
855 | 55 'showRegionInfo' : false, |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
56 // is there region content in the page? |
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
57 'hasRegionContent' : false, |
823 | 58 // turn any region into a clickable link to its detail view |
59 'autoRegionLinks' : false, | |
60 // class name for content divs (must additionally be marked with class "keep") | |
1023 | 61 'regionContentSelector' : 'div.dl-regioncontent', |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
62 // buttonset of this plugin |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
63 'regionSet' : ['regions', 'addregion', 'delregion', 'regionhtml', 'lessoptions'], |
813 | 64 // url param for regions |
851 | 65 'rg' : null |
813 | 66 }; |
792 | 67 |
68 var actions = { | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
69 |
792 | 70 // define a region interactively with two clicked points |
813 | 71 "defineRegion" : function(data) { |
72 if (!data.settings.isRegionVisible) { | |
73 alert("Please turn on regions visibility!"); | |
74 return; | |
75 } | |
996 | 76 var cssPrefix = data.settings.cssPrefix; |
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 |
996 | 84 var $overlay = $('<div class="'+cssPrefix+'overlay" style="position:absolute"/>'); |
808
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 |
920 | 97 $overlay.on("mousemove.dlRegion", regionMove); |
98 $overlay.on("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 |
920 | 119 $overlay.off("mousemove.dlRegion", regionMove); |
120 $overlay.off("mouseup.dlRegion", regionEnd); | |
808
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); |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
155 renderRegions(data, 1); |
818
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 |
855 | 159 "showRegionInfo" : function (data) { |
160 var show = !data.settings.showRegionInfo; | |
161 data.settings.showRegionInfo = show; | |
832
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) { |
855 | 165 // empty the div |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
166 $html.fadeOut(function () { |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
167 $html.contents().remove(); |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
168 }); |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
169 return; |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
170 } |
855 | 171 regionInfo(data); |
991
497ab03868ab
moved marks to separate plugin. (pack and unpack is still in digilib.js)
robcast
parents:
969
diff
changeset
|
172 } |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
173 |
792 | 174 }; |
175 | |
813 | 176 // store a region div |
177 var storeRegion = function (data, $regionDiv) { | |
178 var regions = data.regions; | |
179 var rect = geom.rectangle($regionDiv); | |
180 var regionRect = data.imgTrafo.invtransform(rect); | |
181 regionRect.$div = $regionDiv; | |
182 regions.push(regionRect); | |
183 console.debug("regions", data.regions, "regionRect", regionRect); | |
184 }; | |
185 | |
855 | 186 // clickable header |
187 var regionInfoHeader = function (data) { | |
996 | 188 var cssPrefix = data.settings.cssPrefix; |
189 var $infoDiv = $('<div class="'+cssPrefix+'infoheader"/>'); | |
190 var $h01 = $('<div class="'+cssPrefix+'infobutton">HTML</div>'); | |
191 var $h02 = $('<div class="'+cssPrefix+'infobutton">SVG</div>'); | |
192 var $h03 = $('<div class="'+cssPrefix+'infobutton">Digilib</div>'); | |
193 var $h04 = $('<div class="'+cssPrefix+'infobutton">X</div>'); | |
855 | 194 var bind = function($div, name) { |
920 | 195 $div.on('click.regioninfo', function () { |
855 | 196 var $top = $(this).parent().parent(); |
996 | 197 $top.find('.'+cssPrefix+'info').hide(); |
198 $top.find('.'+cssPrefix+ name).show(); | |
855 | 199 }); |
200 }; | |
201 bind($h01, 'html'); | |
202 bind($h02, 'svgattr'); | |
203 bind($h03, 'digilib'); | |
204 var $html = data.$htmlDiv; | |
920 | 205 $h04.on('click.regioninfo', function () { |
855 | 206 data.settings.showRegionInfo = false; |
207 fn.highlightButtons(data, 'regionhtml', false); | |
208 $html.fadeOut(function () { | |
209 $html.contents().remove(); | |
210 }); | |
211 }); | |
212 $infoDiv.append($h01, $h02, $h03, $h04); | |
213 return $infoDiv; | |
214 }; | |
215 | |
216 // html for later insertion | |
217 var regionInfoHTML = function (data) { | |
996 | 218 var cssPrefix = data.settings.cssPrefix; |
219 var $infoDiv = $('<div class="'+cssPrefix+'info '+cssPrefix+'html"/>'); | |
220 $infoDiv.append($('<div/>').text('<div class="'+cssPrefix+'keep '+cssPrefix+'regioncontent">')); | |
855 | 221 $.each(data.regions, function(index, r) { |
872 | 222 var area = [ |
223 fn.cropFloatStr(r.x), | |
224 fn.cropFloatStr(r.y), | |
225 fn.cropFloatStr(r.width), | |
226 fn.cropFloatStr(r.height)].join(','); | |
855 | 227 $infoDiv.append($('<div/>').text('<a coords="' + area + '" >')); |
228 }); | |
229 $infoDiv.append($('<div/>').text('</div>')); | |
230 return $infoDiv; | |
231 }; | |
232 | |
233 // SVG-style | |
234 var regionInfoSVG = function (data) { | |
996 | 235 var cssPrefix = data.settings.cssPrefix; |
236 var $infoDiv = $('<div class="'+cssPrefix+'info '+cssPrefix+'svgattr"/>'); | |
855 | 237 $.each(data.regions, function(index, r) { |
872 | 238 var area = [ |
239 fn.cropFloatStr(r.x), | |
240 fn.cropFloatStr(r.y), | |
241 fn.cropFloatStr(r.width), | |
242 fn.cropFloatStr(r.height)].join(' '); | |
855 | 243 $infoDiv.append($('<div/>').text('"' + area + '"')); |
244 }); | |
245 return $infoDiv; | |
246 }; | |
247 | |
248 // digilib-style | |
249 var regionInfoDigilib = function (data) { | |
996 | 250 var cssPrefix = data.settings.cssPrefix; |
251 var $infoDiv = $('<div class="'+cssPrefix+'info '+cssPrefix+'digilib"/>'); | |
855 | 252 $.each(data.regions, function(index, r) { |
862 | 253 var area = r.toString(); |
855 | 254 $infoDiv.append($('<div/>').text(area)); |
255 }); | |
256 return $infoDiv; | |
257 }; | |
258 | |
259 // show region info in a window | |
260 var regionInfo = function (data) { | |
261 var $html = data.$htmlDiv; | |
874 | 262 $html.append(regionInfoHeader(data)); |
855 | 263 $html.append(regionInfoHTML(data)); |
264 $html.append(regionInfoSVG(data)); | |
265 $html.append(regionInfoDigilib(data)); | |
266 $html.fadeIn(); | |
267 }; | |
268 | |
813 | 269 // add a region to data.$elem |
873 | 270 var addRegionDiv = function (data, index, attributes) { |
996 | 271 var cssPrefix = data.settings.cssPrefix; |
823 | 272 var nr = index + 1; // we count regions from 1 |
273 // create a digilib URL for this detail | |
874 | 274 var url = attributes ? attributes.href : getRegionUrl(data, index); |
996 | 275 var $regionDiv = $('<div class="'+cssPrefix+'region '+cssPrefix+'overlay" style="display:none"/>'); |
813 | 276 $regionDiv.attr("id", ID_PREFIX + nr); |
277 data.$elem.append($regionDiv); | |
278 if (data.settings.showRegionNumbers) { | |
996 | 279 var $regionLink = $('<a class="'+cssPrefix+'regionnumber"/>'); |
920 | 280 if (attributes) $regionLink.attr(attributes); |
823 | 281 $regionLink.text(nr); |
851 | 282 $regionDiv.append($regionLink); |
813 | 283 } |
823 | 284 if (data.settings.autoRegionLinks) { |
875 | 285 if (attributes) { |
286 delete attributes.href; | |
287 $regionDiv.attr(attributes); | |
1023 | 288 } |
920 | 289 $regionDiv.on('click.dlRegion', function() { |
851 | 290 window.location = url; |
291 }); | |
823 | 292 } |
813 | 293 return $regionDiv; |
294 }; | |
295 | |
851 | 296 // create a region div from the data.regions array |
947 | 297 var createRegionDiv = function (data, regions, index, attributes) { |
873 | 298 var $regionDiv = addRegionDiv(data, index, attributes); |
813 | 299 var region = regions[index]; |
300 region.$div = $regionDiv; | |
301 return $regionDiv; | |
302 }; | |
303 | |
851 | 304 // create regions from URL parameters |
305 var createRegionsFromURL = function (data) { | |
306 unpackRegions(data); | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
307 var regions = data.regions; |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
308 $.each(regions, function(i) { |
947 | 309 createRegionDiv(data, regions, i); |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
310 }); |
792 | 311 }; |
312 | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
313 // create regions from HTML |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
314 var createRegionsFromHTML = function (data) { |
823 | 315 var regions = data.regions; |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
316 var selector = data.settings.regionContentSelector; |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
317 // regions are defined in "a" tags |
835 | 318 var $content = data.$elem.contents(selector).contents('a'); |
851 | 319 console.debug("createRegionsFromHTML. elems: ", $content); |
835 | 320 $content.each(function(index, a) { |
321 var $a = $(a); | |
852 | 322 // the "coords" attribute contains the region coords (0..1) |
323 var coords = $a.attr('coords'); | |
324 var pos = coords.split(",", 4); | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
325 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
|
326 regions.push(rect); |
873 | 327 // save the attributes |
328 var attributes = {}; | |
874 | 329 if ($a.attr('id')) { attributes.id = $a.attr('id'); } |
330 if ($a.attr('href')) { attributes.href = $a.attr('href'); } | |
331 if ($a.attr('title')) { attributes.title = $a.attr('title'); } | |
851 | 332 // create the div |
947 | 333 var $regionDiv = createRegionDiv(data, regions, index, attributes); |
851 | 334 var $contents = $a.contents().clone(); |
335 $regionDiv.append($contents); | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
336 }); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
337 }; |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
338 |
813 | 339 // show a region on top of the scaler image |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
340 var renderRegion = function (data, index, anim) { |
813 | 341 if (!data.imgTrafo) return; |
342 var $elem = data.$elem; | |
792 | 343 var regions = data.regions; |
950
164d69e2c481
much nicer implementation of preview for scrolling and zooming.
robcast
parents:
947
diff
changeset
|
344 var zoomArea = data.zoomArea; |
813 | 345 if (index > regions.length) return; |
851 | 346 var region = regions[index]; |
813 | 347 var $regionDiv = region.$div; |
348 if (!$regionDiv) { | |
950
164d69e2c481
much nicer implementation of preview for scrolling and zooming.
robcast
parents:
947
diff
changeset
|
349 console.error("renderRegion: region has no $div", region); |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
350 // alert("renderRegion: region has no $div to show"); |
813 | 351 return; |
352 } | |
353 var regionRect = region.copy(); | |
354 var show = data.settings.isRegionVisible; | |
950
164d69e2c481
much nicer implementation of preview for scrolling and zooming.
robcast
parents:
947
diff
changeset
|
355 if (show && zoomArea.overlapsRect(regionRect)) { |
164d69e2c481
much nicer implementation of preview for scrolling and zooming.
robcast
parents:
947
diff
changeset
|
356 regionRect.clipTo(zoomArea); |
813 | 357 var screenRect = data.imgTrafo.transform(regionRect); |
851 | 358 console.debug("renderRegion: pos=",geom.position(screenRect)); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
359 if (anim) { |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
360 $regionDiv.fadeIn(); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
361 } else{ |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
362 $regionDiv.show(); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
363 } |
851 | 364 // for some reason adjustDiv sets wrong coords when called BEFORE show()? |
365 screenRect.adjustDiv($regionDiv); | |
813 | 366 } else { |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
367 if (anim) { |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
368 $regionDiv.fadeOut(); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
369 } else{ |
824 | 370 $regionDiv.hide(); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
371 } |
813 | 372 } |
373 }; | |
374 | |
375 // show regions | |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
376 var renderRegions = function (data, anim) { |
813 | 377 for (var i = 0; i < data.regions.length ; i++) { |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
378 renderRegion(data, i, anim); |
813 | 379 } |
380 }; | |
381 | |
382 var unpackRegions = function (data) { | |
383 // create regions from parameters | |
384 var rg = data.settings.rg; | |
385 if (rg == null) return; | |
386 var regions = data.regions; | |
958
2a2e8c039c29
changed regions parameter separator to the same as for marks
hertzhaft
parents:
950
diff
changeset
|
387 var rs = rg.split(","); |
813 | 388 for (var i = 0; i < rs.length; i++) { |
389 var r = rs[i]; | |
958
2a2e8c039c29
changed regions parameter separator to the same as for marks
hertzhaft
parents:
950
diff
changeset
|
390 var pos = r.split("/", 4); |
813 | 391 var rect = geom.rectangle(pos[0], pos[1], pos[2], pos[3]); |
392 regions.push(rect); | |
792 | 393 } |
394 }; | |
395 | |
813 | 396 // pack regions array into a parameter string |
397 var packRegions = function (data) { | |
398 var regions = data.regions; | |
815 | 399 if (!regions.length) { |
400 data.settings.rg = null; | |
401 return; | |
402 } | |
813 | 403 var rg = ''; |
404 for (var i = 0; i < regions.length; i++) { | |
405 region = regions[i]; | |
406 if (i) { | |
958
2a2e8c039c29
changed regions parameter separator to the same as for marks
hertzhaft
parents:
950
diff
changeset
|
407 rg += ','; |
792 | 408 } |
813 | 409 rg += [ |
410 fn.cropFloatStr(region.x), | |
411 fn.cropFloatStr(region.y), | |
412 fn.cropFloatStr(region.width), | |
413 fn.cropFloatStr(region.height) | |
958
2a2e8c039c29
changed regions parameter separator to the same as for marks
hertzhaft
parents:
950
diff
changeset
|
414 ].join('/'); |
813 | 415 } |
416 data.settings.rg = rg; | |
792 | 417 }; |
418 | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
419 // reload display after a region has been added or removed |
813 | 420 var redisplay = function (data) { |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
421 if (!data.settings.hasRegionContent) { |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
422 packRegions(data); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
423 } |
813 | 424 fn.redisplay(data); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
425 }; |
813 | 426 |
823 | 427 // for turning region numbers/region divs into links to zoomed details |
428 var getRegionUrl = function (data, index) { | |
429 var region = data.regions[index]; | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
430 var settings = data.settings; |
823 | 431 var params = { |
432 "fn" : settings.fn, | |
433 "pn" : settings.pn | |
434 }; | |
435 fn.packArea(params, region); | |
436 fn.packMarks(params, data.marks); | |
437 fn.packScalerFlags(params, data.scalerFlags); | |
438 var paramNames = digilib.defaults.digilibParamNames; | |
439 // build our own digilib URL without storing anything | |
440 var queryString = fn.getParamString(params, paramNames, digilib.defaults); | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
441 return settings.digilibBaseUrl + '?' + queryString; |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
442 }; |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
443 |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
444 // 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
|
445 var handleSetup = function (evt) { |
941 | 446 var data = this; |
813 | 447 console.debug("regions: handleSetup", data.settings.rg); |
823 | 448 // regions with content are given in HTML divs |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
449 if (data.settings.hasRegionContent) { |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
450 createRegionsFromHTML(data); |
823 | 451 // regions are defined in the URL |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
452 } else { |
851 | 453 createRegionsFromURL(data); |
855 | 454 fn.highlightButtons(data, 'regionhtml', data.settings.showRegionInfo); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
455 } |
799
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 |
851 | 458 // event handler, sets buttons and shows regions when scaler img is reloaded |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
459 var handleUpdate = function (evt) { |
941 | 460 var data = this; |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
461 console.debug("regions: handleUpdate"); |
848 | 462 var settings = data.settings; |
463 fn.highlightButtons(data, 'regions' , settings.isRegionVisible); | |
855 | 464 fn.highlightButtons(data, 'regionhtml' , settings.showRegionInfo); |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
465 renderRegions(data); |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
466 }; |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
467 |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
468 // plugin installation called by digilib on plugin object. |
813 | 469 var install = function(plugin) { |
470 digilib = plugin; | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
471 console.debug('installing regions plugin. digilib:', digilib); |
813 | 472 fn = digilib.fn; |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
473 // import geometry classes |
813 | 474 geom = fn.geometry; |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
475 // add defaults, actions, buttons |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
476 $.extend(digilib.defaults, defaults); |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
477 $.extend(digilib.actions, actions); |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
478 $.extend(digilib.buttons, buttons); |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
479 }; |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
480 |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
481 // plugin initialization |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
482 var init = function (data) { |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
483 console.debug('initialising regions plugin. data:', data); |
835 | 484 var $elem = data.$elem; |
996 | 485 var cssPrefix = data.settings.cssPrefix; |
823 | 486 // regions array |
487 data.regions = []; | |
835 | 488 // regions div |
996 | 489 var $html = $('<div class="'+cssPrefix+'keep '+cssPrefix+'regionHTML"/>'); |
835 | 490 $elem.append($html); |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
491 data.$htmlDiv = $html; |
848 | 492 // install event handler |
493 var $data = $(data); | |
920 | 494 $data.on('setup', handleSetup); |
495 $data.on('update', handleUpdate); | |
848 | 496 var settings = data.settings; |
947 | 497 var selector = settings.regionContentSelector; |
1023 | 498 //settings.hasRegionContent = $elem.has(selector).length > 0; |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
499 // neither URL-defined regions nor buttons when regions are predefined in HTML |
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
500 if (!settings.hasRegionContent) { |
848 | 501 var mode = settings.interactionMode; |
823 | 502 // add "rg" to digilibParamNames |
848 | 503 settings.digilibParamNames.push('rg'); |
823 | 504 // additional buttons |
848 | 505 var buttonSettings = settings.buttonSettings[mode]; |
823 | 506 // configure buttons through digilib "regionSet" option |
848 | 507 var buttonSet = settings.regionSet || regionSet; |
823 | 508 // set regionSet to [] or '' for no buttons (when showing regions only) |
509 if (buttonSet.length && buttonSet.length > 0) { | |
851 | 510 buttonSettings.regionSet = buttonSet; |
823 | 511 buttonSettings.buttonSets.push('regionSet'); |
512 } | |
813 | 513 } |
792 | 514 }; |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
515 |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
516 // plugin object with name and install/init methods |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
517 // shared objects filled by digilib on registration |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
518 var pluginProperties = { |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
519 name : 'region', |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
520 install : install, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
521 init : init, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
522 buttons : {}, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
523 actions : {}, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
524 fn : {}, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
525 plugins : {} |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
526 }; |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
527 |
792 | 528 if ($.fn.digilib == null) { |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
529 $.error("jquery.digilib.regions must be loaded after jquery.digilib!"); |
792 | 530 } else { |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
531 $.fn.digilib('plugin', pluginProperties); |
792 | 532 } |
533 })(jQuery); |