Mercurial > hg > digilib-old
annotate webapp/src/main/webapp/jquery/jquery.digilib.regions.js @ 1093:75a54db031dd
move found region into view, keep zoom factor if possible
author | hertzhaft |
---|---|
date | Thu, 18 Oct 2012 18:49:05 +0200 |
parents | 4964a1e252eb |
children | 8d6bc18f7145 |
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 |
1025 | 8 <map class="dl-keep dl-regioncontent"> |
9 <area href="http://www.mpiwg-berlin.mpg.de" coords="0.1,0.1,0.4,0.1" alt="MPI fuer Wissenschaftsgeschichte"/> | |
10 <area href="http://www.biblhertz.it" coords="0.5,0.8,0.4,0.1" alt="Bibliotheca Hertziana"/> | |
11 <area coords="0.3,0.5,0.15,0.1" /> | |
12 </map> | |
1023 | 13 |
1067 | 14 According to the HTML specs, "area" and "a" elements are allowed inside of a "map". |
15 Both can have a "coords" attribute, but "area" elements can't contain child nodes. | |
16 To have regions with content use "a" tags, e.g. | |
17 | |
18 <map class="dl-keep dl-regioncontent"> | |
19 <a href="http://www.mpiwg-berlin.mpg.de" coords="0.4907,0.3521,0.1458,0.107"> | |
20 MPI fuer Wissenschaftsgeschichte | |
21 </a> | |
22 <a href="http://www.biblhertz.it" coords="0.3413,0.2912,0.4345,0.2945"> | |
23 Bibliotheca Hertziana | |
24 </a> | |
25 <area coords="0.3,0.5,0.15,0.1" /> | |
26 </map> | |
27 | |
792 | 28 */ |
29 | |
30 (function($) { | |
813 | 31 // the digilib object |
996 | 32 var digilib = null; |
813 | 33 // the functions made available by digilib |
1093
75a54db031dd
move found region into view, keep zoom factor if possible
hertzhaft
parents:
1092
diff
changeset
|
34 var FULL_AREA = null; |
1048 | 35 var fn = { |
36 // dummy function to avoid errors, gets overwritten by buttons plugin | |
37 highlightButtons : function () { | |
38 console.debug('regions: dummy function - highlightButtons'); | |
39 } | |
40 }; | |
813 | 41 // affine geometry plugin |
996 | 42 var geom = null; |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
43 |
792 | 44 var buttons = { |
1091 | 45 defineregion : { |
46 onclick : "defineUserRegion", | |
813 | 47 tooltip : "define a region", |
792 | 48 icon : "addregion.png" |
49 }, | |
1091 | 50 removeregion : { |
51 onclick : "removeUserRegion", | |
52 tooltip : "delete the last user defined region", | |
792 | 53 icon : "delregion.png" |
54 }, | |
1091 | 55 removeallregions : { |
56 onclick : "removeAllUserRegions", | |
57 tooltip : "delete all user defined regions", | |
1067 | 58 icon : "delallregions.png" |
59 }, | |
792 | 60 regions : { |
61 onclick : "toggleRegions", | |
62 tooltip : "show or hide regions", | |
63 icon : "regions.png" | |
64 }, | |
1092 | 65 findcoords : { |
66 onclick : "findCoords", | |
67 tooltip : "find coords and display as a new region", | |
68 icon : "regions.png" | |
69 }, | |
1048 | 70 regioninfo : { |
855 | 71 onclick : "showRegionInfo", |
1091 | 72 tooltip : "show information about user defined regions", |
792 | 73 icon : "regioninfo.png" |
74 } | |
75 }; | |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
76 |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
77 var defaults = { |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
78 // are regions being edited? |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
79 'editRegions' : false, |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
80 // are regions shown? |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
81 'isRegionVisible' : true, |
813 | 82 // are region numbers shown? |
1023 | 83 'showRegionNumbers' : true, |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
84 // is there region content in the page? |
1027
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
85 'processHtmlRegions' : false, |
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
86 // region defined by users and in the URL |
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
87 'processUserRegions' : true, |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
88 // callback for click on region |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
89 'onClickRegion' : null, |
1091 | 90 // callback when new user region is defined |
91 'onNewRegion' : null, | |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
92 // turn any region into a clickable link to its detail view (DEPRECATED) |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
93 'autoZoomOnClick' : false, |
1091 | 94 // css selector for area/a elements (must also be marked with class "dl-keep") |
1067 | 95 'htmlRegionsSelector' : 'map.dl-regioncontent area, map.dl-regioncontent a', |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
96 // buttonset of this plugin |
1092 | 97 'regionSet' : ['regions', 'defineregion', 'removeregion', 'removeallregions', 'regioninfo', 'findcoords', 'lessoptions'], |
813 | 98 // url param for regions |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
99 'rg' : null, |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
100 // region attributes to copy from HTML |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
101 'regionAttributes' : { |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
102 'id' :1, |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
103 'href' :1, |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
104 'title' :1, |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
105 'target':1, |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
106 'style' :1, |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
107 'class' :1 |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
108 } |
813 | 109 }; |
792 | 110 |
111 var actions = { | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
112 |
792 | 113 // define a region interactively with two clicked points |
1091 | 114 defineUserRegion : function(data) { |
813 | 115 if (!data.settings.isRegionVisible) { |
116 alert("Please turn on regions visibility!"); | |
117 return; | |
118 } | |
996 | 119 var cssPrefix = data.settings.cssPrefix; |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
120 var $elem = data.$elem; |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
121 var $body = $('body'); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
122 var bodyRect = geom.rectangle($body); |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
123 var $scaler = data.$scaler; |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
124 var scalerRect = geom.rectangle($scaler); |
792 | 125 var pt1, pt2; |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
126 // overlay prevents other elements from reacting to mouse events |
996 | 127 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
|
128 $body.append($overlay); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
129 bodyRect.adjustDiv($overlay); |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
130 var attr = {'class' : cssPrefix+"regionURL"}; |
1091 | 131 var $regionDiv = addRegionDiv(data, data.userRegions, data.userRegions.length, attr); |
792 | 132 |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
133 // mousedown handler: start sizing |
792 | 134 var regionStart = function (evt) { |
135 pt1 = geom.position(evt); | |
136 // setup and show zoom div | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
137 pt1.adjustDiv($regionDiv); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
138 $regionDiv.width(0).height(0); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
139 $regionDiv.show(); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
140 // register mouse events |
920 | 141 $overlay.on("mousemove.dlRegion", regionMove); |
142 $overlay.on("mouseup.dlRegion", regionEnd); | |
792 | 143 return false; |
144 }; | |
145 | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
146 // mousemove handler: size region |
792 | 147 var regionMove = function (evt) { |
148 pt2 = geom.position(evt); | |
149 var rect = geom.rectangle(pt1, pt2); | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
150 rect.clipTo(scalerRect); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
151 // update region |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
152 rect.adjustDiv($regionDiv); |
792 | 153 return false; |
154 }; | |
155 | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
156 // mouseup handler: end sizing |
792 | 157 var regionEnd = function (evt) { |
158 pt2 = geom.position(evt); | |
159 // assume a click and continue if the area is too small | |
160 var clickRect = geom.rectangle(pt1, pt2); | |
161 if (clickRect.getArea() <= 5) return false; | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
162 // unregister mouse events and get rid of overlay |
920 | 163 $overlay.off("mousemove.dlRegion", regionMove); |
164 $overlay.off("mouseup.dlRegion", regionEnd); | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
165 $overlay.remove(); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
166 // clip region |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
167 clickRect.clipTo(scalerRect); |
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
168 clickRect.adjustDiv($regionDiv); |
1091 | 169 var region = storeUserRegion(data, $regionDiv); |
792 | 170 // fn.redisplay(data); |
1091 | 171 fn.highlightButtons(data, 'defineregion', 0); |
813 | 172 redisplay(data); |
1091 | 173 $(data).trigger('newRegion', region); |
792 | 174 return false; |
175 }; | |
176 | |
177 // bind start zoom handler | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
178 $overlay.one('mousedown.dlRegion', regionStart); |
1091 | 179 fn.highlightButtons(data, 'defineregion', 1); |
792 | 180 }, |
181 | |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
182 // remove the last added URL region |
1091 | 183 removeUserRegion : function (data) { |
813 | 184 if (!data.settings.isRegionVisible) { |
185 alert("Please turn on regions visibility!"); | |
186 return; | |
187 } | |
1091 | 188 var r = data.userRegions.pop(); |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
189 // no more URL regions to delete |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
190 if (r == null) return; |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
191 var $regionDiv = r.$div; |
792 | 192 $regionDiv.remove(); |
813 | 193 redisplay(data); |
792 | 194 }, |
195 | |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
196 // remove all manually added regions (defined through URL "rg" parameter) |
1091 | 197 removeAllUserRegions : function (data) { |
1067 | 198 if (!data.settings.isRegionVisible) { |
199 alert("Please turn on regions visibility!"); | |
200 return; | |
201 } | |
202 var cssPrefix = data.settings.cssPrefix; | |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
203 var $regions = data.$elem.find('div.'+cssPrefix+'regionURL'); |
1067 | 204 $regions.remove(); |
1091 | 205 data.userRegions = []; // remove only URL regions |
1067 | 206 redisplay(data); |
207 }, | |
208 | |
813 | 209 // show/hide regions |
1060 | 210 toggleRegions : function (data) { |
813 | 211 var show = !data.settings.isRegionVisible; |
212 data.settings.isRegionVisible = show; | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
213 fn.highlightButtons(data, 'regions', show); |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
214 renderRegions(data, 1); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
215 }, |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
216 |
1048 | 217 // show region info in a window |
1060 | 218 showRegionInfo : function (data) { |
1048 | 219 var $elem = data.$elem; |
220 var cssPrefix = data.settings.cssPrefix; | |
1060 | 221 var infoselector = '#'+cssPrefix+'regionInfo'; |
222 if (fn.find(data, infoselector)) { | |
1048 | 223 fn.withdraw($info); |
224 return; | |
225 } | |
226 var html = '\ | |
227 <div id="'+cssPrefix+'regionInfo" class="'+cssPrefix+'keep '+cssPrefix+'regionInfo">\ | |
1060 | 228 <table class="'+cssPrefix+'infoheader">\ |
229 <tr>\ | |
230 <td class="'+cssPrefix+'infobutton html">HTML</td>\ | |
231 <td class="'+cssPrefix+'infobutton svgattr">SVG</td>\ | |
232 <td class="'+cssPrefix+'infobutton csv">CSV</td>\ | |
233 <td class="'+cssPrefix+'infobutton digilib">Digilib</td>\ | |
234 <td class="'+cssPrefix+'infobutton x">X</td>\ | |
235 </tr>\ | |
236 </table>\ | |
1048 | 237 </div>'; |
238 $info = $(html); | |
239 $info.appendTo($elem); | |
240 $info.append(regionInfoHTML(data)); | |
241 $info.append(regionInfoSVG(data)); | |
1060 | 242 $info.append(regionInfoCSV(data)); |
1048 | 243 $info.append(regionInfoDigilib(data)); |
244 var bind = function(name) { | |
1060 | 245 $info.find('.'+name).on('click.regioninfo', function () { |
1048 | 246 $info.find('div.'+cssPrefix+'info').hide(); |
247 $info.find('div.'+cssPrefix+name).show(); | |
1060 | 248 fn.centerOnScreen(data, $info); |
832
e4133946a9ad
display regions as HTML for use in digilib element
hertzhaft
parents:
824
diff
changeset
|
249 }); |
1048 | 250 }; |
251 bind('html'); | |
252 bind('svgattr'); | |
1060 | 253 bind('csv'); |
1048 | 254 bind('digilib'); |
255 $info.find('.x').on('click.regioninfo', function () { | |
256 fn.withdraw($info); | |
257 }); | |
258 $info.fadeIn(); | |
1060 | 259 fn.centerOnScreen(data, $info); |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
260 }, |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
261 |
1091 | 262 // display region coordinates in an edit line |
263 showRegionCoords : function (data, region) { | |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
264 var $elem = data.$elem; |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
265 var cssPrefix = data.settings.cssPrefix; |
1091 | 266 // var infoselector = '#'+cssPrefix+'regionInfo'; |
267 // var $info = fn.find(data, infoselector); | |
268 var coords = regionCoordsString(region, ','); | |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
269 var html = '\ |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
270 <div id="'+cssPrefix+'regionInfo" class="'+cssPrefix+'keep '+cssPrefix+'regionInfo">\ |
1091 | 271 <input name="coords" type="text" size="30" maxlength="40" value="'+coords+'"/>\ |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
272 </div>'; |
1091 | 273 var $info = $(html); |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
274 $info.appendTo($elem); |
1091 | 275 $input = $info.find('input'); |
276 $input.on('focus.regioninfo', function (event) { | |
277 this.select(); | |
278 }); | |
279 $input.on('blur.regioninfo', function (event) { | |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
280 fn.withdraw($info); |
1091 | 281 return false; |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
282 }); |
1091 | 283 $input.on('keypress.regioninfo', function (event) { |
1092 | 284 fn.withdraw($info); // OBS: "return false" disables copy! |
1091 | 285 }); |
286 $input.prop("readonly",true); | |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
287 $info.fadeIn(); |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
288 fn.centerOnScreen(data, $info); |
1091 | 289 $input.focus(); |
290 console.debug('showRegionCoords', coords); | |
1092 | 291 }, |
1091 | 292 |
1092 | 293 // find coordinates and display as new region |
294 findCoords : function (data) { | |
295 var $elem = data.$elem; | |
296 var cssPrefix = data.settings.cssPrefix; | |
297 var html = '\ | |
298 <div id="'+cssPrefix+'regionInfo" class="'+cssPrefix+'keep '+cssPrefix+'regionInfo">\ | |
299 <form class="'+cssPrefix+'form">\ | |
300 <div>\ | |
301 <input class="'+cssPrefix+'input" name="coords" type="text" size="30" maxlength="40"/> \ | |
302 </div>\ | |
303 <input class="'+cssPrefix+'submit" type="submit" name="sub" value="Ok"/>\ | |
304 <input class="'+cssPrefix+'cancel" type="button" value="Cancel"/>\ | |
305 </form>\ | |
306 </div>'; | |
307 var $info = $(html); | |
308 $info.appendTo($elem); | |
309 var $form = $info.find('form'); | |
310 var $input = $info.find('input.'+cssPrefix+'input'); | |
311 // handle submit | |
312 $form.on('submit', function () { | |
313 var coords = $input.val(); | |
314 var attr = { 'class' : cssPrefix+'regionURL '+cssPrefix+'findregion' }; | |
315 console.debug('findCoords', coords); | |
1093
75a54db031dd
move found region into view, keep zoom factor if possible
hertzhaft
parents:
1092
diff
changeset
|
316 var rect = createRegionFromCoords(data, data.userRegions, coords, attr); |
75a54db031dd
move found region into view, keep zoom factor if possible
hertzhaft
parents:
1092
diff
changeset
|
317 var za = data.zoomArea; |
75a54db031dd
move found region into view, keep zoom factor if possible
hertzhaft
parents:
1092
diff
changeset
|
318 if (!fn.isFullArea(za)) { |
75a54db031dd
move found region into view, keep zoom factor if possible
hertzhaft
parents:
1092
diff
changeset
|
319 za.setCenter(rect.getCenter()); |
75a54db031dd
move found region into view, keep zoom factor if possible
hertzhaft
parents:
1092
diff
changeset
|
320 za.clipTo(FULL_AREA); |
75a54db031dd
move found region into view, keep zoom factor if possible
hertzhaft
parents:
1092
diff
changeset
|
321 if (!za.containsRect(rect)) { |
75a54db031dd
move found region into view, keep zoom factor if possible
hertzhaft
parents:
1092
diff
changeset
|
322 fn.setZoomArea(data, FULL_AREA.copy()); |
75a54db031dd
move found region into view, keep zoom factor if possible
hertzhaft
parents:
1092
diff
changeset
|
323 } else { |
75a54db031dd
move found region into view, keep zoom factor if possible
hertzhaft
parents:
1092
diff
changeset
|
324 fn.setZoomArea(data, za); |
75a54db031dd
move found region into view, keep zoom factor if possible
hertzhaft
parents:
1092
diff
changeset
|
325 } |
75a54db031dd
move found region into view, keep zoom factor if possible
hertzhaft
parents:
1092
diff
changeset
|
326 } |
1092 | 327 fn.withdraw($info); |
328 redisplay(data); | |
329 return false; | |
330 }); | |
331 // handle cancel | |
332 $form.find('.'+cssPrefix+'cancel').on('click', function () { | |
333 fn.withdraw($info); | |
334 }); | |
335 $info.fadeIn(); | |
336 fn.centerOnScreen(data, $info); | |
337 $input.focus(); | |
338 }, | |
792 | 339 }; |
340 | |
813 | 341 // store a region div |
1091 | 342 var storeUserRegion = function (data, $regionDiv) { |
343 var regions = data.userRegions; | |
813 | 344 var rect = geom.rectangle($regionDiv); |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
345 var rectangle = data.imgTrafo.invtransform(rect); |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
346 rectangle.$div = $regionDiv; |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
347 regions.push(rectangle); |
1091 | 348 console.debug("storeUserRegion", data.userRegions, "rectangle", rectangle); |
349 return rectangle; | |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
350 }; |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
351 |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
352 // open region as detail |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
353 var openDetail = function (data, region) { |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
354 digilib.actions.zoomArea(data, region); |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
355 }; |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
356 |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
357 // make a coords string |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
358 var regionCoordsString = function (rect, sep) { |
1091 | 359 if (sep == null) sep = ','; // comma as default separator |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
360 return [ |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
361 fn.cropFloatStr(rect.x), |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
362 fn.cropFloatStr(rect.y), |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
363 fn.cropFloatStr(rect.width), |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
364 fn.cropFloatStr(rect.height) |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
365 ].join(sep); |
813 | 366 }; |
367 | |
855 | 368 // html for later insertion |
369 var regionInfoHTML = function (data) { | |
996 | 370 var cssPrefix = data.settings.cssPrefix; |
371 var $infoDiv = $('<div class="'+cssPrefix+'info '+cssPrefix+'html"/>'); | |
1027
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
372 $infoDiv.append($('<div/>').text('<map class="'+cssPrefix+'keep '+cssPrefix+'regioncontent">')); |
1091 | 373 $.each(data.userRegions, function(index, r) { |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
374 var coords = regionCoordsString(r, ','); |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
375 $infoDiv.append($('<div/>').text('<area coords="' + coords + '"/>')); |
855 | 376 }); |
1027
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
377 $infoDiv.append($('<div/>').text('</map>')); |
855 | 378 return $infoDiv; |
379 }; | |
380 | |
381 // SVG-style | |
382 var regionInfoSVG = function (data) { | |
996 | 383 var cssPrefix = data.settings.cssPrefix; |
384 var $infoDiv = $('<div class="'+cssPrefix+'info '+cssPrefix+'svgattr"/>'); | |
1091 | 385 $.each(data.userRegions, function(index, r) { |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
386 var coords = regionCoordsString(r, ' '); |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
387 $infoDiv.append($('<div/>').text('"' + coords + '"')); |
855 | 388 }); |
389 return $infoDiv; | |
390 }; | |
391 | |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
392 // CSV-style |
1060 | 393 var regionInfoCSV = function (data) { |
394 var cssPrefix = data.settings.cssPrefix; | |
395 var $infoDiv = $('<div class="'+cssPrefix+'info '+cssPrefix+'csv"/>'); | |
1091 | 396 $.each(data.userRegions, function(index, r) { |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
397 var coords = regionCoordsString(r, ','); |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
398 $infoDiv.append($('<div/>').text(index+1 + ": " + coords)); |
1060 | 399 }); |
400 return $infoDiv; | |
401 }; | |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
402 |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
403 // digilib-style (h,w@x,y) |
855 | 404 var regionInfoDigilib = function (data) { |
996 | 405 var cssPrefix = data.settings.cssPrefix; |
406 var $infoDiv = $('<div class="'+cssPrefix+'info '+cssPrefix+'digilib"/>'); | |
1091 | 407 $.each(data.userRegions, function(index, r) { |
1067 | 408 if (r.fromHtml) return; |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
409 var coords = r.toString(); |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
410 $infoDiv.append($('<div/>').text(coords)); |
855 | 411 }); |
412 return $infoDiv; | |
413 }; | |
414 | |
813 | 415 // add a region to data.$elem |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
416 var addRegionDiv = function (data, regions, index, attributes) { |
1025 | 417 var settings = data.settings; |
418 var cssPrefix = settings.cssPrefix; | |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
419 // var nr = regions.length; // we count regions from 1 |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
420 var cls = cssPrefix+'region '+cssPrefix+'overlay'; |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
421 if (attributes && attributes['class']) { |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
422 cls = cls+' '+attributes['class']; |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
423 delete attributes['class']; |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
424 } |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
425 var $regionDiv = $('<div class="'+cls+'" style="display:none"/>'); |
813 | 426 data.$elem.append($regionDiv); |
1025 | 427 if (settings.showRegionNumbers) { |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
428 var $regionLink = $('<a class="'+cssPrefix+'regionnumber">'+index+'</a>'); |
920 | 429 if (attributes) $regionLink.attr(attributes); |
851 | 430 $regionDiv.append($regionLink); |
813 | 431 } |
1025 | 432 if (attributes) { |
1027
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
433 // copy attributes to div except href |
1025 | 434 if (attributes.href) { |
1091 | 435 region.href = attributes.href; |
1027
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
436 // copy attributes |
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
437 var attrs = $.extend({}, attributes); |
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
438 delete attrs.href; |
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
439 $regionDiv.attr(attrs); |
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
440 } else { |
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
441 $regionDiv.attr(attributes); |
1025 | 442 } |
443 } | |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
444 // DEPRECATED |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
445 if (settings.autoZoomOnClick) { |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
446 if (settings.onClickRegion == null) settings.onClickRegion = openDetail; |
823 | 447 } |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
448 // handle click events on div |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
449 var region = regions[index]; |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
450 $regionDiv.on('click.dlRegion', function(evt) { |
1091 | 451 $(data).trigger('regionClick', region); |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
452 }); |
813 | 453 return $regionDiv; |
454 }; | |
455 | |
851 | 456 // create a region div from the data.regions array |
947 | 457 var createRegionDiv = function (data, regions, index, attributes) { |
1027
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
458 var region = regions[index]; |
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
459 // check if div exists |
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
460 if (region.$div != null) return region.$div; |
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
461 // create and add div |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
462 var $regionDiv = addRegionDiv(data, regions, index, attributes); |
813 | 463 region.$div = $regionDiv; |
464 return $regionDiv; | |
465 }; | |
466 | |
1092 | 467 // create regions from a string with coordinates |
468 var createRegionFromCoords = function (data, regions, coords, attributes) { | |
469 var pos = coords.split(/[,\/ ]+/, 4); // TODO: check validity? | |
470 var rect = geom.rectangle(pos[0], pos[1], pos[2], pos[3]); | |
471 if (rect == null) { | |
472 console.debug('createRegionsFromCoords: bad coords:', coords); | |
473 return null; | |
474 } | |
475 var index = regions.length; | |
476 regions.push(rect); | |
477 var $regionDiv = createRegionDiv(data, regions, index, attributes); | |
478 return rect; | |
479 }; | |
480 | |
851 | 481 // create regions from URL parameters |
482 var createRegionsFromURL = function (data) { | |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
483 var cssPrefix = data.settings.cssPrefix; |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
484 var attr = {'class' : cssPrefix+"regionURL"}; |
851 | 485 unpackRegions(data); |
1091 | 486 var regions = data.userRegions; |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
487 $.each(regions, function(index, region) { |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
488 createRegionDiv(data, regions, index, attr); |
1027
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
489 }); |
792 | 490 }; |
491 | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
492 // create regions from HTML |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
493 var createRegionsFromHTML = function (data) { |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
494 var cssPrefix = data.settings.cssPrefix; |
1091 | 495 var regions = data.htmlRegions; |
1025 | 496 // regions are defined in "area" tags |
1067 | 497 var $content = data.$elem.find(data.settings.htmlRegionsSelector); |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
498 console.debug("createRegionsFromHTML. Number of elems: ", $content.length); |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
499 $content.each(function(index, area) { |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
500 var $area = $(area); |
852 | 501 // the "coords" attribute contains the region coords (0..1) |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
502 var coords = $area.attr('coords'); |
1024 | 503 // copy some attributes |
873 | 504 var attributes = {}; |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
505 for (var n in data.settings.regionAttributes) { |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
506 attributes[n] = $area.attr(n); |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
507 } |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
508 // mark div as regionHTML |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
509 regionClass = cssPrefix+'regionHTML'; |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
510 if (attributes['class']) { |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
511 attributes['class'] += ' ' + regionClass |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
512 } else { |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
513 attributes['class'] = regionClass |
1024 | 514 } |
1092 | 515 // create the region |
516 var rect = createRegionFromCoords(data, regions, coords, attributes); | |
517 if (rect == null) return; | |
518 rect.fromHtml = true; | |
519 var $regionDiv = rect.$div; | |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
520 var $contents = $area.contents().clone(); |
1025 | 521 if (attributes.href != null) { |
522 // wrap contents in a-tag | |
523 var $ca = $('<a href="'+attributes.href+'"/>'); | |
524 $ca.append($contents); | |
1027
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
525 // alt attribute is also content (BTW: area-tag has no content()) |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
526 $ca.append($area.attr('alt')); |
1025 | 527 $regionDiv.append($ca); |
528 } else { | |
529 $regionDiv.append($contents); | |
530 // alt attribute is also content (BTW: area-tag has no content()) | |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
531 $regionDiv.append($area.attr('alt')); |
1025 | 532 } |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
533 }); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
534 }; |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
535 |
813 | 536 // show a region on top of the scaler image |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
537 var renderRegion = function (data, region, anim) { |
813 | 538 if (!data.imgTrafo) return; |
950
164d69e2c481
much nicer implementation of preview for scrolling and zooming.
robcast
parents:
947
diff
changeset
|
539 var zoomArea = data.zoomArea; |
813 | 540 var $regionDiv = region.$div; |
541 if (!$regionDiv) { | |
950
164d69e2c481
much nicer implementation of preview for scrolling and zooming.
robcast
parents:
947
diff
changeset
|
542 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
|
543 // alert("renderRegion: region has no $div to show"); |
813 | 544 return; |
545 } | |
546 var regionRect = region.copy(); | |
547 var show = data.settings.isRegionVisible; | |
1067 | 548 if (show && zoomArea.overlapsRect(regionRect) && !regionRect.containsRect(zoomArea)) { |
950
164d69e2c481
much nicer implementation of preview for scrolling and zooming.
robcast
parents:
947
diff
changeset
|
549 regionRect.clipTo(zoomArea); |
813 | 550 var screenRect = data.imgTrafo.transform(regionRect); |
1067 | 551 // console.debug("renderRegion: pos=",geom.position(screenRect)); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
552 if (anim) { |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
553 $regionDiv.fadeIn(); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
554 } else{ |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
555 $regionDiv.show(); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
556 } |
1024 | 557 // adjustDiv sets wrong coords when called BEFORE show() |
851 | 558 screenRect.adjustDiv($regionDiv); |
813 | 559 } else { |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
560 if (anim) { |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
561 $regionDiv.fadeOut(); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
562 } else{ |
824 | 563 $regionDiv.hide(); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
564 } |
813 | 565 } |
566 }; | |
567 | |
568 // show regions | |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
569 var renderRegions = function (data, anim) { |
1091 | 570 $.each(data.htmlRegions, function(index, region) { |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
571 renderRegion(data, region, anim); |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
572 }); |
1091 | 573 $.each(data.userRegions, function(index, region) { |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
574 renderRegion(data, region, anim); |
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
575 }); |
813 | 576 }; |
577 | |
1091 | 578 // read region data from URL parameters |
813 | 579 var unpackRegions = function (data) { |
580 var rg = data.settings.rg; | |
581 if (rg == null) return; | |
1091 | 582 var regions = data.userRegions; |
958
2a2e8c039c29
changed regions parameter separator to the same as for marks
hertzhaft
parents:
950
diff
changeset
|
583 var rs = rg.split(","); |
813 | 584 for (var i = 0; i < rs.length; i++) { |
585 var r = rs[i]; | |
958
2a2e8c039c29
changed regions parameter separator to the same as for marks
hertzhaft
parents:
950
diff
changeset
|
586 var pos = r.split("/", 4); |
813 | 587 var rect = geom.rectangle(pos[0], pos[1], pos[2], pos[3]); |
588 regions.push(rect); | |
792 | 589 } |
590 }; | |
591 | |
1091 | 592 // pack user regions array into a URL parameter string |
813 | 593 var packRegions = function (data) { |
1091 | 594 var regions = data.userRegions; |
815 | 595 if (!regions.length) { |
596 data.settings.rg = null; | |
597 return; | |
598 } | |
813 | 599 var rg = ''; |
600 for (var i = 0; i < regions.length; i++) { | |
1024 | 601 var region = regions[i]; |
1027
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
602 if (rg) { |
958
2a2e8c039c29
changed regions parameter separator to the same as for marks
hertzhaft
parents:
950
diff
changeset
|
603 rg += ','; |
792 | 604 } |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
605 rg += regionCoordsString(region, '/'); |
813 | 606 } |
607 data.settings.rg = rg; | |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
608 console.debug('pack regions:', rg); |
792 | 609 }; |
610 | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
611 // reload display after a region has been added or removed |
813 | 612 var redisplay = function (data) { |
1027
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
613 if (data.settings.processUserRegions) { |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
614 packRegions(data); |
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
615 } |
813 | 616 fn.redisplay(data); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
617 }; |
813 | 618 |
1091 | 619 // event handler, gets called when a newRegion event is triggered |
620 var handleNewRegion = function (evt, region) { | |
621 var data = this; | |
622 var settings = data.settings; | |
623 console.debug("regions: handleNewRegion", region); | |
624 if (typeof settings.onNewRegion === 'function') { | |
625 // execute callback | |
626 return settings.onNewRegion(data, region); | |
627 } | |
628 if (typeof settings.onNewRegion === 'string') { | |
629 // execute action | |
630 return actions[settings.onNewRegion](data, region); | |
631 } | |
632 }; | |
633 | |
634 // event handler, gets called when a regionClick event is triggered | |
635 var handleRegionClick = function (evt, region) { | |
636 var data = this; | |
637 var settings = data.settings; | |
638 console.debug("regions: handleRegionClick", region); | |
639 if (region.href) { | |
640 // follow the href attribute of the region area | |
641 window.location = region.href; //TODO: how about target? | |
642 } | |
643 if (typeof settings.onClickRegion === 'function') { | |
644 // execute callback | |
645 return settings.onClickRegion(data, region); | |
646 } | |
647 if (typeof settings.onClickRegion === 'string') { | |
648 // execute action | |
649 return actions[settings.onClickRegion](data, region); | |
650 } | |
651 }; | |
652 | |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
653 // 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
|
654 var handleSetup = function (evt) { |
941 | 655 var data = this; |
1027
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
656 var settings = data.settings; |
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
657 console.debug("regions: handleSetup", settings.rg); |
1048 | 658 // regions with content are given in HTML divs |
1027
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
659 if (settings.processHtmlRegions) { |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
660 createRegionsFromHTML(data); |
1027
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
661 } |
1048 | 662 // regions are defined in the URL |
1027
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
663 if (settings.processUserRegions) { |
851 | 664 createRegionsFromURL(data); |
818
eff74cfaaf97
read regions from HTML (not working yet), show info
hertzhaft
parents:
815
diff
changeset
|
665 } |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
666 }; |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
667 |
851 | 668 // 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
|
669 var handleUpdate = function (evt) { |
941 | 670 var data = this; |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
671 console.debug("regions: handleUpdate"); |
848 | 672 var settings = data.settings; |
673 fn.highlightButtons(data, 'regions' , settings.isRegionVisible); | |
850
47a6b93bde43
always show html-defined regions. wrong pos still not fixed
hertzhaft
parents:
848
diff
changeset
|
674 renderRegions(data); |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
675 }; |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
676 |
1048 | 677 // additional buttons |
678 var installButtons = function (data) { | |
679 var settings = data.settings; | |
680 var mode = settings.interactionMode; | |
681 var buttonSettings = settings.buttonSettings[mode]; | |
682 // configure buttons through digilib "regionSet" option | |
683 var buttonSet = settings.regionSet || regionSet; | |
684 // set regionSet to [] or '' for no buttons (when showing regions only) | |
685 if (buttonSet.length && buttonSet.length > 0) { | |
686 buttonSettings.regionSet = buttonSet; | |
687 buttonSettings.buttonSets.push('regionSet'); | |
688 } | |
689 }; | |
690 | |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
691 // plugin installation called by digilib on plugin object. |
813 | 692 var install = function(plugin) { |
693 digilib = plugin; | |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
694 console.debug('installing regions plugin. digilib:', digilib); |
1048 | 695 // import digilib functions |
696 $.extend(fn, digilib.fn); | |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
697 // import geometry classes |
813 | 698 geom = fn.geometry; |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
699 // add defaults, actions, buttons |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
700 $.extend(digilib.defaults, defaults); |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
701 $.extend(digilib.actions, actions); |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
702 $.extend(digilib.buttons, buttons); |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
703 }; |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
704 |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
705 // plugin initialization |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
706 var init = function (data) { |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
707 console.debug('initialising regions plugin. data:', data); |
835 | 708 var $elem = data.$elem; |
1027
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
709 var settings = data.settings; |
996 | 710 var cssPrefix = data.settings.cssPrefix; |
1093
75a54db031dd
move found region into view, keep zoom factor if possible
hertzhaft
parents:
1092
diff
changeset
|
711 FULL_AREA = geom.rectangle(0, 0, 1, 1); |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
712 // region arrays |
1091 | 713 data.userRegions = []; |
714 data.htmlRegions = []; | |
1048 | 715 // install event handlers |
848 | 716 var $data = $(data); |
920 | 717 $data.on('setup', handleSetup); |
718 $data.on('update', handleUpdate); | |
1091 | 719 $data.on('newRegion', handleNewRegion); |
720 $data.on('regionClick', handleRegionClick); | |
1048 | 721 // install buttons |
1027
ff19b9e936d3
allow predefined and user regions at the same time.
robcast
parents:
1025
diff
changeset
|
722 if (settings.processUserRegions) { |
1091 | 723 // add "rg" to digilibParamNames |
1088
16215fc22fbf
better separation of HTML and user defined regions
hertzhaft
parents:
1067
diff
changeset
|
724 // settings.digilibParamNames.push('rg'); |
1091 | 725 // TODO: this leads double params, because |
726 // settings.additionalParamNames is created earlier than this plugin's init() action | |
1048 | 727 if (digilib.plugins.buttons != null) { |
728 installButtons(data); | |
823 | 729 } |
813 | 730 } |
792 | 731 }; |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
732 |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
733 // plugin object with name and install/init methods |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
734 // shared objects filled by digilib on registration |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
735 var pluginProperties = { |
1048 | 736 name : 'regions', |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
737 install : install, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
738 init : init, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
739 buttons : {}, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
740 actions : {}, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
741 fn : {}, |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
742 plugins : {} |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
743 }; |
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
744 |
792 | 745 if ($.fn.digilib == null) { |
808
ae8e98c479d5
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
799
diff
changeset
|
746 $.error("jquery.digilib.regions must be loaded after jquery.digilib!"); |
792 | 747 } else { |
799
12f790cb30de
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
792
diff
changeset
|
748 $.fn.digilib('plugin', pluginProperties); |
792 | 749 } |
750 })(jQuery); |