Mercurial > hg > digilib-old
annotate webapp/src/main/webapp/jquery/jquery.digilib.regions.js @ 1024:4ee43243a6a0
more clean up.
new hover-style for regions.
clicking on region to zoom uses zoomArea action.
author | robcast |
---|---|
date | Tue, 06 Mar 2012 21:32:20 +0100 |
parents | 8e3462a753f0 |
children | c75858ee4452 |
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 |
792 | 24 var buttons = { |
25 addregion : { | |
813 | 26 onclick : "defineRegion", |
27 tooltip : "define a region", | |
792 | 28 icon : "addregion.png" |
29 }, | |
30 delregion : { | |
31 onclick : "removeRegion", | |
32 tooltip : "delete the last region", | |
33 icon : "delregion.png" | |
34 }, | |
35 regions : { | |
36 onclick : "toggleRegions", | |
37 tooltip : "show or hide regions", | |
38 icon : "regions.png" | |
39 }, | |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
40 regionhtml : { |
855 | 41 onclick : "showRegionInfo", |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
42 tooltip : "show information about regions", |
792 | 43 icon : "regioninfo.png" |
44 } | |
45 }; | |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
46 |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
47 var defaults = { |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
48 // are regions shown? |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
49 'isRegionVisible' : true, |
813 | 50 // are region numbers shown? |
1023 | 51 'showRegionNumbers' : true, |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
52 // is window with region HTML shown? |
855 | 53 'showRegionInfo' : false, |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
54 // is there region content in the page? |
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
55 'hasRegionContent' : false, |
823 | 56 // turn any region into a clickable link to its detail view |
57 'autoRegionLinks' : false, | |
58 // class name for content divs (must additionally be marked with class "keep") | |
1023 | 59 'regionContentSelector' : 'div.dl-regioncontent', |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
60 // buttonset of this plugin |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
61 'regionSet' : ['regions', 'addregion', 'delregion', 'regionhtml', 'lessoptions'], |
813 | 62 // url param for regions |
851 | 63 'rg' : null |
813 | 64 }; |
792 | 65 |
66 var actions = { | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
67 |
792 | 68 // define a region interactively with two clicked points |
813 | 69 "defineRegion" : function(data) { |
70 if (!data.settings.isRegionVisible) { | |
71 alert("Please turn on regions visibility!"); | |
72 return; | |
73 } | |
996 | 74 var cssPrefix = data.settings.cssPrefix; |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
75 var $elem = data.$elem; |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
76 var $body = $('body'); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
77 var bodyRect = geom.rectangle($body); |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
78 var $scaler = data.$scaler; |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
79 var scalerRect = geom.rectangle($scaler); |
792 | 80 var pt1, pt2; |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
81 // overlay prevents other elements from reacting to mouse events |
996 | 82 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
|
83 $body.append($overlay); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
84 bodyRect.adjustDiv($overlay); |
823 | 85 var $regionDiv = addRegionDiv(data, data.regions.length); |
792 | 86 |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
87 // mousedown handler: start sizing |
792 | 88 var regionStart = function (evt) { |
89 pt1 = geom.position(evt); | |
90 // setup and show zoom div | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
91 pt1.adjustDiv($regionDiv); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
92 $regionDiv.width(0).height(0); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
93 $regionDiv.show(); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
94 // register mouse events |
920 | 95 $overlay.on("mousemove.dlRegion", regionMove); |
96 $overlay.on("mouseup.dlRegion", regionEnd); | |
792 | 97 return false; |
98 }; | |
99 | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
100 // mousemove handler: size region |
792 | 101 var regionMove = function (evt) { |
102 pt2 = geom.position(evt); | |
103 var rect = geom.rectangle(pt1, pt2); | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
104 rect.clipTo(scalerRect); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
105 // update region |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
106 rect.adjustDiv($regionDiv); |
792 | 107 return false; |
108 }; | |
109 | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
110 // mouseup handler: end sizing |
792 | 111 var regionEnd = function (evt) { |
112 pt2 = geom.position(evt); | |
113 // assume a click and continue if the area is too small | |
114 var clickRect = geom.rectangle(pt1, pt2); | |
115 if (clickRect.getArea() <= 5) return false; | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
116 // unregister mouse events and get rid of overlay |
920 | 117 $overlay.off("mousemove.dlRegion", regionMove); |
118 $overlay.off("mouseup.dlRegion", regionEnd); | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
119 $overlay.remove(); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
120 // clip region |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
121 clickRect.clipTo(scalerRect); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
122 clickRect.adjustDiv($regionDiv); |
813 | 123 storeRegion(data, $regionDiv); |
792 | 124 // fn.redisplay(data); |
813 | 125 fn.highlightButtons(data, 'addregion', 0); |
126 redisplay(data); | |
792 | 127 return false; |
128 }; | |
129 | |
130 // bind start zoom handler | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
131 $overlay.one('mousedown.dlRegion', regionStart); |
813 | 132 fn.highlightButtons(data, 'addregion', 1); |
792 | 133 }, |
134 | |
135 // remove the last added region | |
136 "removeRegion" : function (data) { | |
813 | 137 if (!data.settings.isRegionVisible) { |
138 alert("Please turn on regions visibility!"); | |
139 return; | |
140 } | |
141 var region = data.regions.pop(); | |
142 if (region == null) return; | |
143 var $regionDiv = region.$div; | |
792 | 144 $regionDiv.remove(); |
813 | 145 redisplay(data); |
792 | 146 }, |
147 | |
813 | 148 // show/hide regions |
149 "toggleRegions" : function (data) { | |
150 var show = !data.settings.isRegionVisible; | |
151 data.settings.isRegionVisible = show; | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
152 fn.highlightButtons(data, 'regions', show); |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
153 renderRegions(data, 1); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
154 }, |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
155 |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
156 // show/hide region HTML code |
855 | 157 "showRegionInfo" : function (data) { |
158 var show = !data.settings.showRegionInfo; | |
159 data.settings.showRegionInfo = show; | |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
160 fn.highlightButtons(data, 'regionhtml', show); |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
161 var $html = data.$htmlDiv; |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
162 if (!show) { |
855 | 163 // empty the div |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
164 $html.fadeOut(function () { |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
165 $html.contents().remove(); |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
166 }); |
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
167 return; |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
168 } |
855 | 169 regionInfo(data); |
991
497ab03868ab
moved marks to separate plugin. (pack and unpack is still in digilib.js)
robcast
parents:
969
diff
changeset
|
170 } |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
171 |
792 | 172 }; |
173 | |
813 | 174 // store a region div |
175 var storeRegion = function (data, $regionDiv) { | |
176 var regions = data.regions; | |
177 var rect = geom.rectangle($regionDiv); | |
178 var regionRect = data.imgTrafo.invtransform(rect); | |
179 regionRect.$div = $regionDiv; | |
180 regions.push(regionRect); | |
181 console.debug("regions", data.regions, "regionRect", regionRect); | |
182 }; | |
183 | |
855 | 184 // clickable header |
185 var regionInfoHeader = function (data) { | |
996 | 186 var cssPrefix = data.settings.cssPrefix; |
187 var $infoDiv = $('<div class="'+cssPrefix+'infoheader"/>'); | |
188 var $h01 = $('<div class="'+cssPrefix+'infobutton">HTML</div>'); | |
189 var $h02 = $('<div class="'+cssPrefix+'infobutton">SVG</div>'); | |
190 var $h03 = $('<div class="'+cssPrefix+'infobutton">Digilib</div>'); | |
191 var $h04 = $('<div class="'+cssPrefix+'infobutton">X</div>'); | |
855 | 192 var bind = function($div, name) { |
920 | 193 $div.on('click.regioninfo', function () { |
855 | 194 var $top = $(this).parent().parent(); |
996 | 195 $top.find('.'+cssPrefix+'info').hide(); |
196 $top.find('.'+cssPrefix+ name).show(); | |
855 | 197 }); |
198 }; | |
199 bind($h01, 'html'); | |
200 bind($h02, 'svgattr'); | |
201 bind($h03, 'digilib'); | |
202 var $html = data.$htmlDiv; | |
920 | 203 $h04.on('click.regioninfo', function () { |
855 | 204 data.settings.showRegionInfo = false; |
205 fn.highlightButtons(data, 'regionhtml', false); | |
206 $html.fadeOut(function () { | |
207 $html.contents().remove(); | |
208 }); | |
209 }); | |
210 $infoDiv.append($h01, $h02, $h03, $h04); | |
211 return $infoDiv; | |
212 }; | |
213 | |
214 // html for later insertion | |
215 var regionInfoHTML = function (data) { | |
996 | 216 var cssPrefix = data.settings.cssPrefix; |
217 var $infoDiv = $('<div class="'+cssPrefix+'info '+cssPrefix+'html"/>'); | |
218 $infoDiv.append($('<div/>').text('<div class="'+cssPrefix+'keep '+cssPrefix+'regioncontent">')); | |
855 | 219 $.each(data.regions, function(index, r) { |
872 | 220 var area = [ |
221 fn.cropFloatStr(r.x), | |
222 fn.cropFloatStr(r.y), | |
223 fn.cropFloatStr(r.width), | |
224 fn.cropFloatStr(r.height)].join(','); | |
855 | 225 $infoDiv.append($('<div/>').text('<a coords="' + area + '" >')); |
226 }); | |
227 $infoDiv.append($('<div/>').text('</div>')); | |
228 return $infoDiv; | |
229 }; | |
230 | |
231 // SVG-style | |
232 var regionInfoSVG = function (data) { | |
996 | 233 var cssPrefix = data.settings.cssPrefix; |
234 var $infoDiv = $('<div class="'+cssPrefix+'info '+cssPrefix+'svgattr"/>'); | |
855 | 235 $.each(data.regions, function(index, r) { |
872 | 236 var area = [ |
237 fn.cropFloatStr(r.x), | |
238 fn.cropFloatStr(r.y), | |
239 fn.cropFloatStr(r.width), | |
240 fn.cropFloatStr(r.height)].join(' '); | |
855 | 241 $infoDiv.append($('<div/>').text('"' + area + '"')); |
242 }); | |
243 return $infoDiv; | |
244 }; | |
245 | |
246 // digilib-style | |
247 var regionInfoDigilib = function (data) { | |
996 | 248 var cssPrefix = data.settings.cssPrefix; |
249 var $infoDiv = $('<div class="'+cssPrefix+'info '+cssPrefix+'digilib"/>'); | |
855 | 250 $.each(data.regions, function(index, r) { |
862 | 251 var area = r.toString(); |
855 | 252 $infoDiv.append($('<div/>').text(area)); |
253 }); | |
254 return $infoDiv; | |
255 }; | |
256 | |
257 // show region info in a window | |
258 var regionInfo = function (data) { | |
259 var $html = data.$htmlDiv; | |
874 | 260 $html.append(regionInfoHeader(data)); |
855 | 261 $html.append(regionInfoHTML(data)); |
262 $html.append(regionInfoSVG(data)); | |
263 $html.append(regionInfoDigilib(data)); | |
264 $html.fadeIn(); | |
265 }; | |
266 | |
813 | 267 // add a region to data.$elem |
873 | 268 var addRegionDiv = function (data, index, attributes) { |
996 | 269 var cssPrefix = data.settings.cssPrefix; |
823 | 270 var nr = index + 1; // we count regions from 1 |
996 | 271 var $regionDiv = $('<div class="'+cssPrefix+'region '+cssPrefix+'overlay" style="display:none"/>'); |
813 | 272 data.$elem.append($regionDiv); |
273 if (data.settings.showRegionNumbers) { | |
1024 | 274 var $regionLink = $('<a class="'+cssPrefix+'regionnumber">'+nr+'</a>'); |
920 | 275 if (attributes) $regionLink.attr(attributes); |
851 | 276 $regionDiv.append($regionLink); |
813 | 277 } |
823 | 278 if (data.settings.autoRegionLinks) { |
1024 | 279 var url = null; |
875 | 280 if (attributes) { |
1024 | 281 if (attributes.href != null) { |
282 url = attributes.href; | |
283 } | |
875 | 284 delete attributes.href; |
285 $regionDiv.attr(attributes); | |
1023 | 286 } |
1024 | 287 var region = data.regions[index]; |
920 | 288 $regionDiv.on('click.dlRegion', function() { |
1024 | 289 if (url != null) { |
290 window.location = url; | |
291 } else { | |
292 digilib.actions['zoomArea'](data, region); | |
293 } | |
851 | 294 }); |
823 | 295 } |
813 | 296 return $regionDiv; |
297 }; | |
298 | |
851 | 299 // create a region div from the data.regions array |
947 | 300 var createRegionDiv = function (data, regions, index, attributes) { |
873 | 301 var $regionDiv = addRegionDiv(data, index, attributes); |
813 | 302 var region = regions[index]; |
303 region.$div = $regionDiv; | |
304 return $regionDiv; | |
305 }; | |
306 | |
851 | 307 // create regions from URL parameters |
308 var createRegionsFromURL = function (data) { | |
309 unpackRegions(data); | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
310 var regions = data.regions; |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
311 $.each(regions, function(i) { |
947 | 312 createRegionDiv(data, regions, i); |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
313 }); |
792 | 314 }; |
315 | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
316 // create regions from HTML |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
317 var createRegionsFromHTML = function (data) { |
823 | 318 var regions = data.regions; |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
319 var selector = data.settings.regionContentSelector; |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
320 // regions are defined in "a" tags |
835 | 321 var $content = data.$elem.contents(selector).contents('a'); |
851 | 322 console.debug("createRegionsFromHTML. elems: ", $content); |
835 | 323 $content.each(function(index, a) { |
324 var $a = $(a); | |
852 | 325 // the "coords" attribute contains the region coords (0..1) |
326 var coords = $a.attr('coords'); | |
327 var pos = coords.split(",", 4); | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
328 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
|
329 regions.push(rect); |
1024 | 330 // copy some attributes |
873 | 331 var attributes = {}; |
1024 | 332 for (var n in {'id':1, 'href':1, 'title':1, 'target':1, 'style':1}) { |
333 attributes[n] = $a.attr(n); | |
334 } | |
851 | 335 // create the div |
947 | 336 var $regionDiv = createRegionDiv(data, regions, index, attributes); |
851 | 337 var $contents = $a.contents().clone(); |
338 $regionDiv.append($contents); | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
339 }); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
340 }; |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
341 |
813 | 342 // 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
|
343 var renderRegion = function (data, index, anim) { |
813 | 344 if (!data.imgTrafo) return; |
345 var $elem = data.$elem; | |
792 | 346 var regions = data.regions; |
950
164d69e2c481
much nicer implementation of preview for scrolling and zooming.
robcast
parents:
947
diff
changeset
|
347 var zoomArea = data.zoomArea; |
813 | 348 if (index > regions.length) return; |
851 | 349 var region = regions[index]; |
813 | 350 var $regionDiv = region.$div; |
351 if (!$regionDiv) { | |
950
164d69e2c481
much nicer implementation of preview for scrolling and zooming.
robcast
parents:
947
diff
changeset
|
352 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
|
353 // alert("renderRegion: region has no $div to show"); |
813 | 354 return; |
355 } | |
356 var regionRect = region.copy(); | |
357 var show = data.settings.isRegionVisible; | |
950
164d69e2c481
much nicer implementation of preview for scrolling and zooming.
robcast
parents:
947
diff
changeset
|
358 if (show && zoomArea.overlapsRect(regionRect)) { |
164d69e2c481
much nicer implementation of preview for scrolling and zooming.
robcast
parents:
947
diff
changeset
|
359 regionRect.clipTo(zoomArea); |
813 | 360 var screenRect = data.imgTrafo.transform(regionRect); |
851 | 361 console.debug("renderRegion: pos=",geom.position(screenRect)); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
362 if (anim) { |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
363 $regionDiv.fadeIn(); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
364 } else{ |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
365 $regionDiv.show(); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
366 } |
1024 | 367 // adjustDiv sets wrong coords when called BEFORE show() |
851 | 368 screenRect.adjustDiv($regionDiv); |
813 | 369 } else { |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
370 if (anim) { |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
371 $regionDiv.fadeOut(); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
372 } else{ |
824 | 373 $regionDiv.hide(); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
374 } |
813 | 375 } |
376 }; | |
377 | |
378 // show regions | |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
379 var renderRegions = function (data, anim) { |
813 | 380 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
|
381 renderRegion(data, i, anim); |
813 | 382 } |
383 }; | |
384 | |
385 var unpackRegions = function (data) { | |
386 // create regions from parameters | |
387 var rg = data.settings.rg; | |
388 if (rg == null) return; | |
389 var regions = data.regions; | |
958
2a2e8c039c29
changed regions parameter separator to the same as for marks
hertzhaft
parents:
950
diff
changeset
|
390 var rs = rg.split(","); |
813 | 391 for (var i = 0; i < rs.length; i++) { |
392 var r = rs[i]; | |
958
2a2e8c039c29
changed regions parameter separator to the same as for marks
hertzhaft
parents:
950
diff
changeset
|
393 var pos = r.split("/", 4); |
813 | 394 var rect = geom.rectangle(pos[0], pos[1], pos[2], pos[3]); |
395 regions.push(rect); | |
792 | 396 } |
397 }; | |
398 | |
813 | 399 // pack regions array into a parameter string |
400 var packRegions = function (data) { | |
401 var regions = data.regions; | |
815 | 402 if (!regions.length) { |
403 data.settings.rg = null; | |
404 return; | |
405 } | |
813 | 406 var rg = ''; |
407 for (var i = 0; i < regions.length; i++) { | |
1024 | 408 var region = regions[i]; |
813 | 409 if (i) { |
958
2a2e8c039c29
changed regions parameter separator to the same as for marks
hertzhaft
parents:
950
diff
changeset
|
410 rg += ','; |
792 | 411 } |
813 | 412 rg += [ |
413 fn.cropFloatStr(region.x), | |
414 fn.cropFloatStr(region.y), | |
415 fn.cropFloatStr(region.width), | |
416 fn.cropFloatStr(region.height) | |
958
2a2e8c039c29
changed regions parameter separator to the same as for marks
hertzhaft
parents:
950
diff
changeset
|
417 ].join('/'); |
813 | 418 } |
419 data.settings.rg = rg; | |
792 | 420 }; |
421 | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
422 // reload display after a region has been added or removed |
813 | 423 var redisplay = function (data) { |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
424 if (!data.settings.hasRegionContent) { |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
425 packRegions(data); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
426 } |
813 | 427 fn.redisplay(data); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
428 }; |
813 | 429 |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
430 // 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
|
431 var handleSetup = function (evt) { |
941 | 432 var data = this; |
813 | 433 console.debug("regions: handleSetup", data.settings.rg); |
823 | 434 // 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
|
435 if (data.settings.hasRegionContent) { |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
436 createRegionsFromHTML(data); |
823 | 437 // regions are defined in the URL |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
438 } else { |
851 | 439 createRegionsFromURL(data); |
855 | 440 fn.highlightButtons(data, 'regionhtml', data.settings.showRegionInfo); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
441 } |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
442 }; |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
443 |
851 | 444 // 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
|
445 var handleUpdate = function (evt) { |
941 | 446 var data = this; |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
447 console.debug("regions: handleUpdate"); |
848 | 448 var settings = data.settings; |
449 fn.highlightButtons(data, 'regions' , settings.isRegionVisible); | |
855 | 450 fn.highlightButtons(data, 'regionhtml' , settings.showRegionInfo); |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
451 renderRegions(data); |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
452 }; |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
453 |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
454 // plugin installation called by digilib on plugin object. |
813 | 455 var install = function(plugin) { |
456 digilib = plugin; | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
457 console.debug('installing regions plugin. digilib:', digilib); |
813 | 458 fn = digilib.fn; |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
459 // import geometry classes |
813 | 460 geom = fn.geometry; |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
461 // add defaults, actions, buttons |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
462 $.extend(digilib.defaults, defaults); |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
463 $.extend(digilib.actions, actions); |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
464 $.extend(digilib.buttons, buttons); |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
465 }; |
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 // plugin initialization |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
468 var init = function (data) { |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
469 console.debug('initialising regions plugin. data:', data); |
835 | 470 var $elem = data.$elem; |
996 | 471 var cssPrefix = data.settings.cssPrefix; |
823 | 472 // regions array |
473 data.regions = []; | |
835 | 474 // regions div |
996 | 475 var $html = $('<div class="'+cssPrefix+'keep '+cssPrefix+'regionHTML"/>'); |
835 | 476 $elem.append($html); |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
477 data.$htmlDiv = $html; |
848 | 478 // install event handler |
479 var $data = $(data); | |
920 | 480 $data.on('setup', handleSetup); |
481 $data.on('update', handleUpdate); | |
848 | 482 var settings = data.settings; |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
483 // 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
|
484 if (!settings.hasRegionContent) { |
848 | 485 var mode = settings.interactionMode; |
823 | 486 // add "rg" to digilibParamNames |
848 | 487 settings.digilibParamNames.push('rg'); |
823 | 488 // additional buttons |
848 | 489 var buttonSettings = settings.buttonSettings[mode]; |
823 | 490 // configure buttons through digilib "regionSet" option |
848 | 491 var buttonSet = settings.regionSet || regionSet; |
823 | 492 // set regionSet to [] or '' for no buttons (when showing regions only) |
493 if (buttonSet.length && buttonSet.length > 0) { | |
851 | 494 buttonSettings.regionSet = buttonSet; |
823 | 495 buttonSettings.buttonSets.push('regionSet'); |
496 } | |
813 | 497 } |
792 | 498 }; |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
499 |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
500 // plugin object with name and install/init methods |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
501 // shared objects filled by digilib on registration |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
502 var pluginProperties = { |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
503 name : 'region', |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
504 install : install, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
505 init : init, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
506 buttons : {}, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
507 actions : {}, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
508 fn : {}, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
509 plugins : {} |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
510 }; |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
511 |
792 | 512 if ($.fn.digilib == null) { |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
513 $.error("jquery.digilib.regions must be loaded after jquery.digilib!"); |
792 | 514 } else { |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
515 $.fn.digilib('plugin', pluginProperties); |
792 | 516 } |
517 })(jQuery); |