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