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