Mercurial > hg > digilib
annotate client/digitallibrary/jquery/jquery.digilib.regions.js @ 816:36fbccbaf413 jquery
fixed automatic region links and region content
| author | hertzhaft |
|---|---|
| date | Wed, 23 Feb 2011 02:06:41 +0100 |
| parents | 29de310ed4f3 |
| children | 874d781dd7ec |
| rev | line source |
|---|---|
| 785 | 1 /** optional digilib regions plugin |
| 2 | |
| 3 markup a digilib image with rectangular regions | |
| 4 | |
| 5 TODO: | |
| 6 - store region in params/cookie, regarding zoom, mirror, rotation (like marks) | |
| 7 - set regions programmatically | |
| 8 - read regions from params/cookie and display | |
| 9 - backlink mechanism | |
| 10 - don't write to data.settings? | |
| 11 */ | |
| 12 | |
| 13 (function($) { | |
| 806 | 14 // the digilib object |
| 15 var digilib; | |
| 785 | 16 // the data object passed by digilib |
| 17 var data; | |
| 806 | 18 // the functions made available by digilib |
| 785 | 19 var fn; |
| 806 | 20 // affine geometry plugin |
| 785 | 21 var geom; |
| 22 | |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
23 var FULL_AREA; |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
24 |
| 806 | 25 var ID_PREFIX = "digilib-region-"; |
| 26 | |
| 785 | 27 var buttons = { |
| 28 addregion : { | |
| 806 | 29 onclick : "defineRegion", |
| 30 tooltip : "define a region", | |
| 785 | 31 icon : "addregion.png" |
| 32 }, | |
| 33 delregion : { | |
| 34 onclick : "removeRegion", | |
| 35 tooltip : "delete the last region", | |
| 36 icon : "delregion.png" | |
| 37 }, | |
| 38 regions : { | |
| 39 onclick : "toggleRegions", | |
| 40 tooltip : "show or hide regions", | |
| 41 icon : "regions.png" | |
| 42 }, | |
| 43 regioninfo : { | |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
44 onclick : "toggleRegionInfo", |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
45 tooltip : "show information about regions", |
| 785 | 46 icon : "regioninfo.png" |
| 47 } | |
| 48 }; | |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
49 |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
50 var defaults = { |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
51 // are regions shown? |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
52 'isRegionVisible' : true, |
| 806 | 53 // are region numbers shown? |
| 54 'showRegionNumbers' : false, | |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
55 // is region info shown? |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
56 'showRegionInfo' : false, |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
57 // should digilib look for region content in the page? |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
58 'includeRegionContent' : false, |
| 816 | 59 // turn any region into a clickable link to its detail view |
| 60 'autoRegionLinks' : false, | |
| 61 // class name for content divs (must additionally be marked with class "keep") | |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
62 'regionContentSelector' : 'div.regioncontent', |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
63 // buttonset of this plugin |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
64 'regionSet' : ['regions', 'addregion', 'delregion', 'regioninfo', 'lessoptions'], |
| 806 | 65 // url param for regions |
| 66 'rg' : null, | |
| 67 }; | |
| 785 | 68 |
| 69 var actions = { | |
|
801
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
70 |
| 785 | 71 // define a region interactively with two clicked points |
| 806 | 72 "defineRegion" : function(data) { |
| 73 if (!data.settings.isRegionVisible) { | |
| 74 alert("Please turn on regions visibility!"); | |
| 75 return; | |
| 76 } | |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
77 var $elem = data.$elem; |
|
801
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
78 var $body = $('body'); |
|
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
79 var bodyRect = geom.rectangle($body); |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
80 var $scaler = data.$scaler; |
|
801
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
81 var scalerRect = geom.rectangle($scaler); |
| 785 | 82 var pt1, pt2; |
|
801
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
83 // overlay prevents other elements from reacting to mouse events |
|
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
84 var $overlay = $('<div class="digilib-overlay"/>'); |
|
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
85 $body.append($overlay); |
|
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
86 bodyRect.adjustDiv($overlay); |
| 816 | 87 var $regionDiv = addRegionDiv(data, data.regions.length); |
| 785 | 88 |
|
801
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
89 // mousedown handler: start sizing |
| 785 | 90 var regionStart = function (evt) { |
| 91 pt1 = geom.position(evt); | |
| 92 // setup and show zoom div | |
|
801
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
93 pt1.adjustDiv($regionDiv); |
|
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
94 $regionDiv.width(0).height(0); |
|
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
95 $regionDiv.show(); |
|
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
96 // register mouse events |
|
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
97 $overlay.bind("mousemove.dlRegion", regionMove); |
|
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
98 $overlay.bind("mouseup.dlRegion", regionEnd); |
| 785 | 99 return false; |
| 100 }; | |
| 101 | |
|
801
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
102 // mousemove handler: size region |
| 785 | 103 var regionMove = function (evt) { |
| 104 pt2 = geom.position(evt); | |
| 105 var rect = geom.rectangle(pt1, pt2); | |
|
801
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
106 rect.clipTo(scalerRect); |
|
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
107 // update region |
|
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
108 rect.adjustDiv($regionDiv); |
| 785 | 109 return false; |
| 110 }; | |
| 111 | |
|
801
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
112 // mouseup handler: end sizing |
| 785 | 113 var regionEnd = function (evt) { |
| 114 pt2 = geom.position(evt); | |
| 115 // assume a click and continue if the area is too small | |
| 116 var clickRect = geom.rectangle(pt1, pt2); | |
| 117 if (clickRect.getArea() <= 5) return false; | |
|
801
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
118 // unregister mouse events and get rid of overlay |
|
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
119 $overlay.unbind("mousemove.dlRegion", regionMove); |
|
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
120 $overlay.unbind("mouseup.dlRegion", regionEnd); |
|
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
121 $overlay.remove(); |
|
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
122 // clip region |
|
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
123 clickRect.clipTo(scalerRect); |
|
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
124 clickRect.adjustDiv($regionDiv); |
| 806 | 125 storeRegion(data, $regionDiv); |
| 785 | 126 // fn.redisplay(data); |
| 806 | 127 fn.highlightButtons(data, 'addregion', 0); |
| 128 redisplay(data); | |
| 785 | 129 return false; |
| 130 }; | |
| 131 | |
| 132 // bind start zoom handler | |
|
801
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
133 $overlay.one('mousedown.dlRegion', regionStart); |
| 806 | 134 fn.highlightButtons(data, 'addregion', 1); |
| 785 | 135 }, |
| 136 | |
| 137 // remove the last added region | |
| 138 "removeRegion" : function (data) { | |
| 806 | 139 if (!data.settings.isRegionVisible) { |
| 140 alert("Please turn on regions visibility!"); | |
| 141 return; | |
| 142 } | |
| 143 var region = data.regions.pop(); | |
| 144 if (region == null) return; | |
| 145 var $regionDiv = region.$div; | |
| 785 | 146 $regionDiv.remove(); |
| 806 | 147 redisplay(data); |
| 785 | 148 }, |
| 149 | |
| 806 | 150 // show/hide regions |
| 151 "toggleRegions" : function (data) { | |
| 152 var show = !data.settings.isRegionVisible; | |
| 153 data.settings.isRegionVisible = show; | |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
154 fn.highlightButtons(data, 'regions', show); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
155 showRegionDivs(data, 1); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
156 }, |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
157 |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
158 // show/hide region info |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
159 "toggleRegionInfo" : function (data) { |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
160 var show = !data.settings.showRegionInfo; |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
161 data.settings.showRegionInfo = show; |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
162 fn.highlightButtons(data, 'regioninfo', show); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
163 var $info = $('.regioninfo'); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
164 if (show) { |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
165 $info.fadeIn(); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
166 } else { |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
167 $info.fadeOut(); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
168 } |
| 785 | 169 } |
| 170 }; | |
| 171 | |
| 172 var addRegion = actions.addRegion; | |
| 173 | |
| 806 | 174 // store a region div |
| 175 var storeRegion = function (data, $regionDiv) { | |
| 176 var regions = data.regions; | |
| 177 var rect = geom.rectangle($regionDiv); | |
| 178 var regionRect = data.imgTrafo.invtransform(rect); | |
| 179 regionRect.$div = $regionDiv; | |
| 180 regions.push(regionRect); | |
| 181 console.debug("regions", data.regions, "regionRect", regionRect); | |
| 182 }; | |
| 183 | |
| 184 // add a region to data.$elem | |
| 816 | 185 var addRegionDiv = function (data, index) { |
| 186 var nr = index + 1; // we count regions from 1 | |
| 187 // create a digilib URL for this detail | |
| 188 var regionUrl = getRegionUrl(data, index); | |
| 806 | 189 var $regionDiv = $('<div class="region overlay" style="display:none"/>'); |
| 190 $regionDiv.attr("id", ID_PREFIX + nr); | |
| 191 data.$elem.append($regionDiv); | |
| 192 if (data.settings.showRegionNumbers) { | |
| 816 | 193 var $regionNr = $('<div class="regionnumber"/>'); |
| 194 var $regionLink = $('<a/>'); | |
| 195 $regionLink.attr('href', regionUrl); | |
| 196 $regionLink.text(nr); | |
| 197 $regionNr.append($regionLink); | |
| 806 | 198 $regionDiv.append($regionNr); |
| 199 } | |
| 816 | 200 if (data.settings.autoRegionLinks) { |
| 201 $regionDiv.bind('click.dlRegion', function() { | |
| 202 window.location = regionUrl; | |
| 203 }) | |
| 204 } | |
| 806 | 205 return $regionDiv; |
| 206 }; | |
| 207 | |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
208 // add region info |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
209 var addRegionInfo = function (region) { |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
210 var $regionDiv = region.$div; |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
211 var $regionInfoDiv = $('<div class="regioninfo" />'); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
212 $regionInfoDiv.text(region.toString()); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
213 $regionDiv.append($regionInfoDiv); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
214 } |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
215 |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
216 // add region content |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
217 var addRegionContent = function (region, $elem) { |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
218 var $regionDiv = region.$div; |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
219 $regionDiv.append($elem); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
220 } |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
221 |
| 806 | 222 // create a region div from the data.regions collection |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
223 var createRegionDiv = function (regions, index) { |
| 806 | 224 var region = regions[index]; |
| 816 | 225 var $regionDiv = addRegionDiv(data, index); |
| 806 | 226 region.$div = $regionDiv; |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
227 addRegionInfo(region); |
| 806 | 228 return $regionDiv; |
| 229 }; | |
| 230 | |
| 231 // create regions | |
| 232 var createRegionDivs = function (data) { | |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
233 var regions = data.regions; |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
234 for (var i = 0; i < regions.length ; i++) { |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
235 createRegionDiv(regions, i); |
| 806 | 236 } |
| 785 | 237 }; |
| 238 | |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
239 // create regions from HTML |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
240 var createRegionsFromHTML = function (data) { |
| 816 | 241 var regions = data.regions; |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
242 var selector = data.settings.regionContentSelector; |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
243 var $content = data.$elem.find(selector); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
244 console.debug("createRegionsFromHTML", $content); |
| 816 | 245 $content.each(function(index, elem) { |
| 246 var $div = $(elem); | |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
247 var r = $div.attr('title'); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
248 var pos = r.split("/", 4); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
249 var rect = geom.rectangle(pos[0], pos[1], pos[2], pos[3]); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
250 regions.push(rect); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
251 var $regionDiv = createRegionDiv(regions, index); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
252 $regionDiv.append($div); |
| 816 | 253 $div.show(); |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
254 }); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
255 }; |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
256 |
| 806 | 257 // show a region on top of the scaler image |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
258 var showRegionDiv = function (data, index, anim) { |
| 806 | 259 if (!data.imgTrafo) return; |
| 260 var $elem = data.$elem; | |
| 785 | 261 var regions = data.regions; |
| 806 | 262 if (index > regions.length) return; |
| 263 var region = regions[index] | |
| 264 var $regionDiv = region.$div; | |
| 265 if (!$regionDiv) { | |
| 266 console.debug("showRegionDiv: region has no $div", region); | |
| 267 // alert("showRegionDiv: region has no $div to show"); | |
| 268 return; | |
| 269 } | |
| 270 var regionRect = region.copy(); | |
| 271 var show = data.settings.isRegionVisible; | |
| 272 if (show && data.zoomArea.overlapsRect(regionRect)) { | |
| 273 regionRect.clipTo(data.zoomArea); | |
| 274 var screenRect = data.imgTrafo.transform(regionRect); | |
| 275 screenRect.adjustDiv($regionDiv); | |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
276 if (anim) { |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
277 $regionDiv.fadeIn(); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
278 } else{ |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
279 $regionDiv.show(); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
280 } |
| 806 | 281 } else { |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
282 if (anim) { |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
283 $regionDiv.fadeOut(); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
284 } else{ |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
285 $regionDiv.show(); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
286 } |
| 806 | 287 } |
| 288 }; | |
| 289 | |
| 290 // show regions | |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
291 var showRegionDivs = function (data, anim) { |
| 806 | 292 for (var i = 0; i < data.regions.length ; i++) { |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
293 showRegionDiv(data, i, anim); |
| 806 | 294 } |
| 295 }; | |
| 296 | |
| 297 var unpackRegions = function (data) { | |
| 298 // create regions from parameters | |
| 299 var rg = data.settings.rg; | |
| 300 if (rg == null) return; | |
| 301 var regions = data.regions; | |
| 302 var rs = rg.split(","); | |
| 303 for (var i = 0; i < rs.length; i++) { | |
| 304 var r = rs[i]; | |
| 305 var pos = r.split("/", 4); | |
| 306 var rect = geom.rectangle(pos[0], pos[1], pos[2], pos[3]); | |
| 307 regions.push(rect); | |
| 308 // TODO: backlink mechanism | |
| 309 // var url = paramString.match(/http.*$/); | |
| 785 | 310 } |
| 311 }; | |
| 312 | |
| 806 | 313 // pack regions array into a parameter string |
| 314 var packRegions = function (data) { | |
| 315 var regions = data.regions; | |
| 808 | 316 if (!regions.length) { |
| 317 data.settings.rg = null; | |
| 318 return; | |
| 319 } | |
| 806 | 320 var rg = ''; |
| 321 for (var i = 0; i < regions.length; i++) { | |
| 322 region = regions[i]; | |
| 323 if (i) { | |
| 324 rg += ','; | |
| 785 | 325 } |
| 806 | 326 rg += [ |
| 327 fn.cropFloatStr(region.x), | |
| 328 fn.cropFloatStr(region.y), | |
| 329 fn.cropFloatStr(region.width), | |
| 330 fn.cropFloatStr(region.height) | |
| 331 ].join('/'); | |
| 332 } | |
| 333 data.settings.rg = rg; | |
| 785 | 334 }; |
| 335 | |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
336 // reload display after a region has been added or removed |
| 806 | 337 var redisplay = function (data) { |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
338 if (!data.settings.includeRegionContent) { |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
339 packRegions(data); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
340 } |
| 806 | 341 fn.redisplay(data); |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
342 }; |
| 806 | 343 |
| 816 | 344 // for turning region numbers/region divs into links to zoomed details |
| 345 var getRegionUrl = function (data, index) { | |
| 346 var region = data.regions[index]; | |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
347 var settings = data.settings; |
| 816 | 348 var params = { |
| 349 "fn" : settings.fn, | |
| 350 "pn" : settings.pn | |
| 351 }; | |
| 352 fn.packArea(params, region); | |
| 353 fn.packMarks(params, data.marks); | |
| 354 fn.packScalerFlags(params, data.scalerFlags); | |
| 355 var paramNames = digilib.defaults.digilibParamNames; | |
| 356 // build our own digilib URL without storing anything | |
| 357 var queryString = fn.getParamString(params, paramNames, digilib.defaults); | |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
358 return settings.digilibBaseUrl + '?' + queryString; |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
359 }; |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
360 |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
361 // event handler, reads region parameter and creates region divs |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
362 var handleSetup = function (evt) { |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
363 data = this; |
| 806 | 364 console.debug("regions: handleSetup", data.settings.rg); |
| 816 | 365 // regions with content are given in HTML divs |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
366 if (data.settings.includeRegionContent) { |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
367 createRegionsFromHTML(data); |
| 816 | 368 // regions are defined in the URL |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
369 } else { |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
370 unpackRegions(data); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
371 createRegionDivs(data); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
372 } |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
373 }; |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
374 |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
375 // event handler, sets buttons and shows regions |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
376 var handleUpdate = function (evt) { |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
377 data = this; |
| 806 | 378 fn.highlightButtons(data, 'regions' , data.settings.isRegionVisible); |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
379 fn.highlightButtons(data, 'regioninfo' , data.settings.showRegionInfo); |
| 806 | 380 showRegionDivs(data); |
| 381 console.debug("regions: handleUpdate", data.settings.rg); | |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
382 }; |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
383 |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
384 // event handler, redisplays regions (e.g. in a new position) |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
385 var handleRedisplay = function (evt) { |
| 806 | 386 data = this; |
| 387 showRegionDivs(data); | |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
388 console.debug("regions: handleRedisplay"); |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
389 }; |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
390 |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
391 // event handler |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
392 var handleDragZoom = function (evt, zoomArea) { |
|
811
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
393 // console.debug("regions: handleDragZoom, zoomArea:", zoomArea); |
|
29de310ed4f3
read regions from HTML (not working yet), show info
hertzhaft
parents:
808
diff
changeset
|
394 // data = this; |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
395 }; |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
396 |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
397 // plugin installation called by digilib on plugin object. |
| 806 | 398 var install = function(plugin) { |
| 399 digilib = plugin; | |
|
801
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
400 console.debug('installing regions plugin. digilib:', digilib); |
| 806 | 401 fn = digilib.fn; |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
402 // import geometry classes |
| 806 | 403 geom = fn.geometry; |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
404 FULL_AREA = geom.rectangle(0,0,1,1); |
|
801
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
405 // add defaults, actions, buttons |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
406 $.extend(digilib.defaults, defaults); |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
407 $.extend(digilib.actions, actions); |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
408 $.extend(digilib.buttons, buttons); |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
409 }; |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
410 |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
411 // plugin initialization |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
412 var init = function (data) { |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
413 console.debug('initialising regions plugin. data:', data); |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
414 var $data = $(data); |
| 816 | 415 // regions array |
| 416 data.regions = []; | |
| 417 // no URL-defined regions, no buttons when regions are predefined in HTML | |
| 418 if (!data.settings.includeRegionContent) { | |
| 419 // add "rg" to digilibParamNames | |
| 420 data.settings.digilibParamNames.push('rg'); | |
| 421 // additional buttons | |
| 422 var buttonSettings = data.settings.buttonSettings.fullscreen; | |
| 423 // configure buttons through digilib "regionSet" option | |
| 424 var buttonSet = data.settings.regionSet || regionSet; | |
| 425 // set regionSet to [] or '' for no buttons (when showing regions only) | |
| 426 if (buttonSet.length && buttonSet.length > 0) { | |
| 427 buttonSettings['regionSet'] = buttonSet; | |
| 428 buttonSettings.buttonSets.push('regionSet'); | |
| 429 } | |
| 806 | 430 } |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
431 // install event handler |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
432 $data.bind('setup', handleSetup); |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
433 $data.bind('update', handleUpdate); |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
434 $data.bind('redisplay', handleRedisplay); |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
435 $data.bind('dragZoom', handleDragZoom); |
| 785 | 436 }; |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
437 |
|
801
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
438 // plugin object with name and install/init methods |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
439 // shared objects filled by digilib on registration |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
440 var pluginProperties = { |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
441 name : 'region', |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
442 install : install, |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
443 init : init, |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
444 buttons : {}, |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
445 actions : {}, |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
446 fn : {}, |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
447 plugins : {} |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
448 }; |
|
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
449 |
| 785 | 450 if ($.fn.digilib == null) { |
|
801
2fb1f576375d
stub for new plugins; overlay div for regions plugin
hertzhaft
parents:
792
diff
changeset
|
451 $.error("jquery.digilib.regions must be loaded after jquery.digilib!"); |
| 785 | 452 } else { |
|
792
52c5595af03e
started to adapt regions plugin to new plugin mechanism
hertzhaft
parents:
785
diff
changeset
|
453 $.fn.digilib('plugin', pluginProperties); |
| 785 | 454 } |
| 455 })(jQuery); |
