Mercurial > hg > digilib
comparison client/digitallibrary/jquery/jquery.digilib.regions.js @ 844:8aa2891583f1 jquery
fixed region position bug in embedded mode, sigh
author | hertzhaft |
---|---|
date | Mon, 07 Mar 2011 09:30:55 +0100 |
parents | 76c23870ac0b |
children | a2b90ad772a0 |
comparison
equal
deleted
inserted
replaced
843:76c23870ac0b | 844:8aa2891583f1 |
---|---|
57 // class name for content divs (must additionally be marked with class "keep") | 57 // class name for content divs (must additionally be marked with class "keep") |
58 'regionContentSelector' : 'div.regioncontent', | 58 'regionContentSelector' : 'div.regioncontent', |
59 // buttonset of this plugin | 59 // buttonset of this plugin |
60 'regionSet' : ['regions', 'addregion', 'delregion', 'regionhtml', 'lessoptions'], | 60 'regionSet' : ['regions', 'addregion', 'delregion', 'regionhtml', 'lessoptions'], |
61 // url param for regions | 61 // url param for regions |
62 'rg' : null, | 62 'rg' : null |
63 }; | 63 }; |
64 | 64 |
65 var actions = { | 65 var actions = { |
66 | 66 |
67 // define a region interactively with two clicked points | 67 // define a region interactively with two clicked points |
190 regions.push(regionRect); | 190 regions.push(regionRect); |
191 console.debug("regions", data.regions, "regionRect", regionRect); | 191 console.debug("regions", data.regions, "regionRect", regionRect); |
192 }; | 192 }; |
193 | 193 |
194 // add a region to data.$elem | 194 // add a region to data.$elem |
195 var addRegionDiv = function (data, index) { | 195 var addRegionDiv = function (data, index, url) { |
196 var nr = index + 1; // we count regions from 1 | 196 var nr = index + 1; // we count regions from 1 |
197 // create a digilib URL for this detail | 197 // create a digilib URL for this detail |
198 var regionUrl = getRegionUrl(data, index); | 198 url = url || getRegionUrl(data, index); |
199 var $regionDiv = $('<div class="region overlay" style="display:none"/>'); | 199 var $regionDiv = $('<div class="region overlay" style="display:none"/>'); |
200 $regionDiv.attr("id", ID_PREFIX + nr); | 200 $regionDiv.attr("id", ID_PREFIX + nr); |
201 data.$elem.append($regionDiv); | 201 data.$elem.append($regionDiv); |
202 if (data.settings.showRegionNumbers) { | 202 if (data.settings.showRegionNumbers) { |
203 var $regionNr = $('<div class="regionnumber"/>'); | 203 var $regionLink = $('<a class="regionnumber"/>'); |
204 var $regionLink = $('<a/>'); | 204 $regionLink.attr('href', url); |
205 $regionLink.attr('href', regionUrl); | |
206 $regionLink.text(nr); | 205 $regionLink.text(nr); |
207 $regionNr.append($regionLink); | 206 $regionDiv.append($regionLink); |
208 $regionDiv.append($regionNr); | |
209 } | 207 } |
210 if (data.settings.autoRegionLinks) { | 208 if (data.settings.autoRegionLinks) { |
211 $regionDiv.bind('click.dlRegion', function() { | 209 $regionDiv.bind('click.dlRegion', function() { |
212 window.location = regionUrl; | 210 window.location = url; |
213 }) | 211 }); |
214 } | 212 } |
215 return $regionDiv; | 213 return $regionDiv; |
216 }; | 214 }; |
217 | 215 |
218 // add region content | 216 // create a region div from the data.regions array |
219 var addRegionContent = function (region, $elem) { | 217 var createRegionDiv = function (regions, index, url) { |
220 var $regionDiv = region.$div; | 218 var $regionDiv = addRegionDiv(data, index, url); |
221 $regionDiv.append($elem); | |
222 } | |
223 | |
224 // create a region div from the data.regions collection | |
225 var createRegionDiv = function (regions, index) { | |
226 var region = regions[index]; | 219 var region = regions[index]; |
227 var $regionDiv = addRegionDiv(data, index); | |
228 region.$div = $regionDiv; | 220 region.$div = $regionDiv; |
229 return $regionDiv; | 221 return $regionDiv; |
230 }; | 222 }; |
231 | 223 |
232 // create regions | 224 // create regions from URL parameters |
233 var createRegionDivs = function (data) { | 225 var createRegionsFromURL = function (data) { |
226 unpackRegions(data); | |
234 var regions = data.regions; | 227 var regions = data.regions; |
235 $.each(regions, function(i) { | 228 $.each(regions, function(i) { |
236 createRegionDiv(regions, i); | 229 createRegionDiv(regions, i); |
237 }); | 230 }); |
238 }; | 231 }; |
241 var createRegionsFromHTML = function (data) { | 234 var createRegionsFromHTML = function (data) { |
242 var regions = data.regions; | 235 var regions = data.regions; |
243 var selector = data.settings.regionContentSelector; | 236 var selector = data.settings.regionContentSelector; |
244 // regions are defined in "a" tags | 237 // regions are defined in "a" tags |
245 var $content = data.$elem.contents(selector).contents('a'); | 238 var $content = data.$elem.contents(selector).contents('a'); |
246 console.debug("createRegionsFromHTML", $content); | 239 console.debug("createRegionsFromHTML. elems: ", $content); |
247 $content.each(function(index, a) { | 240 $content.each(function(index, a) { |
248 var $a = $(a); | 241 var $a = $(a); |
249 // the "rel" attribute has area coords | 242 // the "rel" attribute contains the region coords |
250 var rel = $a.attr('rel'); | 243 var rel = $a.attr('rel'); |
251 var area = rel.replace(/^area:/i, ''); | 244 var area = rel.replace(/^area:/i, ''); |
252 var pos = area.split("/", 4); | 245 var pos = area.split("/", 4); |
253 var rect = geom.rectangle(pos[0], pos[1], pos[2], pos[3]); | 246 var rect = geom.rectangle(pos[0], pos[1], pos[2], pos[3]); |
254 regions.push(rect); | 247 regions.push(rect); |
255 var $regionDiv = createRegionDiv(regions, index); | 248 // create the div |
256 var href = $a.attr('href'); | 249 var href = $a.attr('href'); |
257 var text = $a.text(); | 250 var $regionDiv = createRegionDiv(regions, index, href); |
258 $regionDiv.append($a.clone()); | 251 var $contents = $a.contents().clone(); |
259 // $a.show(); | 252 $regionDiv.append($contents); |
260 }); | 253 }); |
261 }; | 254 }; |
262 | 255 |
263 // show a region on top of the scaler image | 256 // show a region on top of the scaler image |
264 var renderRegion = function (data, index, anim) { | 257 var renderRegion = function (data, index, anim) { |
265 if (!data.imgTrafo) return; | 258 if (!data.imgTrafo) return; |
266 var $elem = data.$elem; | 259 var $elem = data.$elem; |
267 var regions = data.regions; | 260 var regions = data.regions; |
268 if (index > regions.length) return; | 261 if (index > regions.length) return; |
269 var region = regions[index] | 262 var region = regions[index]; |
270 var $regionDiv = region.$div; | 263 var $regionDiv = region.$div; |
271 if (!$regionDiv) { | 264 if (!$regionDiv) { |
272 console.debug("renderRegion: region has no $div", region); | 265 console.debug("renderRegion: region has no $div", region); |
273 // alert("renderRegion: region has no $div to show"); | 266 // alert("renderRegion: region has no $div to show"); |
274 return; | 267 return; |
276 var regionRect = region.copy(); | 269 var regionRect = region.copy(); |
277 var show = data.settings.isRegionVisible; | 270 var show = data.settings.isRegionVisible; |
278 if (show && data.zoomArea.overlapsRect(regionRect)) { | 271 if (show && data.zoomArea.overlapsRect(regionRect)) { |
279 regionRect.clipTo(data.zoomArea); | 272 regionRect.clipTo(data.zoomArea); |
280 var screenRect = data.imgTrafo.transform(regionRect); | 273 var screenRect = data.imgTrafo.transform(regionRect); |
281 // console.debug('renderRegion:', screenRect, regionRect, "imgTrafo=", data.imgTrafo); | 274 console.debug("renderRegion: pos=",geom.position(screenRect)); |
282 console.debug("renderRegion: mpos=",geom.position(screenRect)); | |
283 screenRect.adjustDiv($regionDiv); | |
284 if (anim) { | 275 if (anim) { |
285 $regionDiv.fadeIn(); | 276 $regionDiv.fadeIn(); |
286 } else{ | 277 } else{ |
287 $regionDiv.show(); | 278 $regionDiv.show(); |
288 } | 279 } |
280 // for some reason adjustDiv sets wrong coords when called BEFORE show()? | |
281 screenRect.adjustDiv($regionDiv); | |
289 } else { | 282 } else { |
290 if (anim) { | 283 if (anim) { |
291 $regionDiv.fadeOut(); | 284 $regionDiv.fadeOut(); |
292 } else{ | 285 } else{ |
293 $regionDiv.hide(); | 286 $regionDiv.hide(); |
371 // regions with content are given in HTML divs | 364 // regions with content are given in HTML divs |
372 if (data.settings.hasRegionContent) { | 365 if (data.settings.hasRegionContent) { |
373 createRegionsFromHTML(data); | 366 createRegionsFromHTML(data); |
374 // regions are defined in the URL | 367 // regions are defined in the URL |
375 } else { | 368 } else { |
376 unpackRegions(data); | 369 createRegionsFromURL(data); |
377 createRegionDivs(data); | |
378 fn.highlightButtons(data, 'regionhtml', data.settings.showRegionHTML); | 370 fn.highlightButtons(data, 'regionhtml', data.settings.showRegionHTML); |
379 } | 371 } |
380 }; | 372 }; |
381 | 373 |
382 // event handler, sets buttons and shows regions | 374 // event handler, sets buttons and shows regions when scaler img is reloaded |
383 var handleUpdate = function (evt) { | 375 var handleUpdate = function (evt) { |
384 data = this; | 376 data = this; |
385 console.debug("regions: handleUpdate"); | 377 console.debug("regions: handleUpdate"); |
386 var settings = data.settings; | 378 var settings = data.settings; |
387 fn.highlightButtons(data, 'regions' , settings.isRegionVisible); | 379 fn.highlightButtons(data, 'regions' , settings.isRegionVisible); |
391 | 383 |
392 // event handler, redisplays regions (e.g. in a new position) | 384 // event handler, redisplays regions (e.g. in a new position) |
393 var handleRedisplay = function (evt) { | 385 var handleRedisplay = function (evt) { |
394 data = this; | 386 data = this; |
395 console.debug("regions: handleRedisplay"); | 387 console.debug("regions: handleRedisplay"); |
396 renderRegions(data); | 388 // renderRegions(data); |
397 }; | 389 }; |
398 | 390 |
399 // event handler | 391 // event handler |
400 var handleDragZoom = function (evt, zoomArea) { | 392 var handleDragZoom = function (evt, zoomArea) { |
401 // console.debug("regions: handleDragZoom, zoomArea:", zoomArea); | 393 // console.debug("regions: handleDragZoom, zoomArea:", zoomArea); |
444 var buttonSettings = settings.buttonSettings[mode]; | 436 var buttonSettings = settings.buttonSettings[mode]; |
445 // configure buttons through digilib "regionSet" option | 437 // configure buttons through digilib "regionSet" option |
446 var buttonSet = settings.regionSet || regionSet; | 438 var buttonSet = settings.regionSet || regionSet; |
447 // set regionSet to [] or '' for no buttons (when showing regions only) | 439 // set regionSet to [] or '' for no buttons (when showing regions only) |
448 if (buttonSet.length && buttonSet.length > 0) { | 440 if (buttonSet.length && buttonSet.length > 0) { |
449 buttonSettings['regionSet'] = buttonSet; | 441 buttonSettings.regionSet = buttonSet; |
450 buttonSettings.buttonSets.push('regionSet'); | 442 buttonSettings.buttonSets.push('regionSet'); |
451 } | 443 } |
452 } | 444 } |
453 }; | 445 }; |
454 | 446 |