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