Mercurial > hg > digilib-old
comparison client/digitallibrary/jquery/jquery.digilib.regions.js @ 799:12f790cb30de jquery
started to adapt regions plugin to new plugin mechanism
author | hertzhaft |
---|---|
date | Fri, 18 Feb 2011 23:13:26 +0100 |
parents | d742bd92b05a |
children | ae8e98c479d5 |
comparison
equal
deleted
inserted
replaced
798:b07d1824ca2a | 799:12f790cb30de |
---|---|
13 (function($) { | 13 (function($) { |
14 // the data object passed by digilib | 14 // the data object passed by digilib |
15 var data; | 15 var data; |
16 var buttons; | 16 var buttons; |
17 var fn; | 17 var fn; |
18 // affine geometry plugin stub | |
18 var geom; | 19 var geom; |
20 | |
21 var FULL_AREA; | |
19 | 22 |
20 var buttons = { | 23 var buttons = { |
21 addregion : { | 24 addregion : { |
22 onclick : "setRegion", | 25 onclick : "setRegion", |
23 tooltip : "set a region", | 26 tooltip : "set a region", |
37 onclick : "infoRegions", | 40 onclick : "infoRegions", |
38 tooltip : "information about regions", | 41 tooltip : "information about regions", |
39 icon : "regioninfo.png" | 42 icon : "regioninfo.png" |
40 } | 43 } |
41 }; | 44 }; |
42 var regionSet = ['addregion', 'delregion', 'regions', 'regioninfo', 'lessoptions']; | 45 |
46 var defaults = { | |
47 // are regions shown? | |
48 'isRegionVisible' : true, | |
49 // buttonset of this plugin | |
50 'regionSet' : ['addregion', 'delregion', 'regions', 'regioninfo', 'lessoptions'], | |
51 // array of defined regions | |
52 'regions' : [] | |
53 }; | |
43 | 54 |
44 var actions = { | 55 var actions = { |
45 // define a region interactively with two clicked points | 56 // define a region interactively with two clicked points |
46 "setRegion" : function(data) { | 57 "setRegion" : function(data) { |
47 $elem = data.$elem; | 58 var $elem = data.$elem; |
48 $scaler = data.$scaler; | 59 var $scaler = data.$scaler; |
60 var picRect = geom.rectangle($scaler); | |
49 var pt1, pt2; | 61 var pt1, pt2; |
50 var $regionDiv = $('<div class="region" style="display:none"/>'); | 62 // TODO: temporary rectangle only, pass values to "addRegion" factory |
51 $regionDiv.attr("id", "region" + data.regions.length); | 63 var $tempDiv = $('<div class="region" style="display:none"/>'); |
52 $elem.append($regionDiv); | 64 $elem.append($tempDiv); |
53 var picRect = geom.rectangle($scaler); | |
54 | 65 |
55 var regionStart = function (evt) { | 66 var regionStart = function (evt) { |
56 pt1 = geom.position(evt); | 67 pt1 = geom.position(evt); |
57 // setup and show zoom div | 68 // setup and show zoom div |
58 pt1.adjustDiv($regionDiv); | 69 pt1.adjustDiv($tempDiv); |
59 $regionDiv.width(0).height(0); | 70 $tempDiv.width(0).height(0); |
60 $regionDiv.show(); | 71 $tempDiv.show(); |
61 // register events | 72 // register events |
62 $elem.bind("mousemove.dlRegion", regionMove); | 73 $elem.bind("mousemove.dlRegion", regionMove); |
63 $elem.bind("mouseup.dlRegion", regionEnd); | 74 $elem.bind("mouseup.dlRegion", regionEnd); |
64 return false; | 75 return false; |
65 }; | 76 }; |
68 var regionMove = function (evt) { | 79 var regionMove = function (evt) { |
69 pt2 = geom.position(evt); | 80 pt2 = geom.position(evt); |
70 var rect = geom.rectangle(pt1, pt2); | 81 var rect = geom.rectangle(pt1, pt2); |
71 rect.clipTo(picRect); | 82 rect.clipTo(picRect); |
72 // update zoom div | 83 // update zoom div |
73 rect.adjustDiv($regionDiv); | 84 rect.adjustDiv($tempDiv); |
74 return false; | 85 return false; |
75 }; | 86 }; |
76 | 87 |
77 // mouseup handler: end moving | 88 // mouseup handler: end moving |
78 var regionEnd = function (evt) { | 89 var regionEnd = function (evt) { |
83 // unregister events | 94 // unregister events |
84 $elem.unbind("mousemove.dlRegion", regionMove); | 95 $elem.unbind("mousemove.dlRegion", regionMove); |
85 $elem.unbind("mouseup.dlRegion", regionEnd); | 96 $elem.unbind("mouseup.dlRegion", regionEnd); |
86 // clip and transform | 97 // clip and transform |
87 clickRect.clipTo(picRect); | 98 clickRect.clipTo(picRect); |
88 clickRect.adjustDiv($regionDiv); | 99 clickRect.adjustDiv($tempDiv); |
89 data.regions.push($regionDiv); | 100 $tempDiv.remove(); |
101 data.settings.regions.push(clickRect); | |
90 // fn.redisplay(data); | 102 // fn.redisplay(data); |
91 return false; | 103 return false; |
92 }; | 104 }; |
93 | 105 |
94 // clear old handler (also ZoomDrag) | 106 // clear old handler (also ZoomDrag) |
98 $scaler.one('mousedown.dlRegion', regionStart); | 110 $scaler.one('mousedown.dlRegion', regionStart); |
99 }, | 111 }, |
100 | 112 |
101 // remove the last added region | 113 // remove the last added region |
102 "removeRegion" : function (data) { | 114 "removeRegion" : function (data) { |
103 var $regionDiv = data.regions.pop(); | 115 var $regionDiv = data.settings.regions.pop(); |
104 $regionDiv.remove(); | 116 $regionDiv.remove(); |
105 // fn.redisplay(data); | 117 // fn.redisplay(data); |
106 }, | 118 }, |
107 | 119 |
108 // add a region programmatically | 120 // add a region programmatically |
168 cropFloat(data.regions[i].height).toString(); | 180 cropFloat(data.regions[i].height).toString(); |
169 } | 181 } |
170 } | 182 } |
171 }; | 183 }; |
172 | 184 |
173 // export constructor functions to digilib plugin | 185 var handleSetup = function (evt) { |
174 var init = function (digilibdata) { | 186 console.debug("regions: handleSetup"); |
175 console.log('initialising regions plugin. data:', digilibdata); | 187 data = this; |
176 data = digilibdata; | 188 // if (data.settings.isBirdDivVisible) { |
177 data.regions = []; | 189 // setupBirdDiv(data); |
178 // setup geometry object | 190 // data.$birdDiv.show(); |
179 geom = data.plugins.geometry.init(); | 191 // } |
180 // add buttons and actions from this plugin | 192 }; |
181 $.extend(this.buttons, buttons); | 193 |
182 $.extend(this.actions, actions); | 194 var handleUpdate = function (evt) { |
195 console.debug("regions: handleUpdate"); | |
196 data = this; | |
197 // if (data.settings.isBirdDivVisible) { | |
198 // renderBirdArea(data); | |
199 // setupBirdDrag(data); | |
200 // } | |
201 }; | |
202 | |
203 var handleRedisplay = function (evt) { | |
204 console.debug("regions: handleRedisplay"); | |
205 data = this; | |
206 // if (data.settings.isBirdDivVisible) { | |
207 // updateBirdDiv(data); | |
208 // } | |
209 }; | |
210 | |
211 var handleDragZoom = function (evt, zoomArea) { | |
212 console.debug("regions: handleDragZoom, zoomArea:", zoomArea); | |
213 data = this; | |
214 // if (data.settings.isBirdDivVisible) { | |
215 // setBirdZoom(data, zoomArea); | |
216 // } | |
217 }; | |
218 | |
219 // plugin installation called by digilib on plugin object. | |
220 var install = function(digilib) { | |
221 // import geometry classes | |
222 geom = digilib.fn.geometry; | |
223 FULL_AREA = geom.rectangle(0,0,1,1); | |
224 // add defaults | |
225 $.extend(digilib.defaults, defaults); | |
226 // add actions | |
227 $.extend(digilib.actions, actions); | |
228 // add buttons | |
229 $.extend(digilib.buttons, buttons); | |
230 }; | |
231 | |
232 // plugin initialization | |
233 var init = function (data) { | |
234 console.debug('initialising regions plugin. data:', data); | |
235 var $data = $(data); | |
183 var buttonSettings = data.settings.buttonSettings.fullscreen; | 236 var buttonSettings = data.settings.buttonSettings.fullscreen; |
184 // configure buttons through digilib "regionSet" option | 237 // configure buttons through digilib "regionSet" option |
185 var buttonSet = data.settings.regionSet || regionSet; | 238 var buttonSet = data.settings.regionSet || regionSet; |
186 // set regionSet to [] or '' for no buttons (when showing regions only) | 239 // set regionSet to [] or '' for no buttons (when showing regions only) |
187 if (buttonSet.length && buttonSet.length > 0) { | 240 if (buttonSet.length && buttonSet.length > 0) { |
188 buttonSettings['regionSet'] = buttonSet; | 241 buttonSettings['regionSet'] = buttonSet; |
189 buttonSettings.buttonSets.push('regionSet'); | 242 buttonSettings.buttonSets.push('regionSet'); |
190 } | 243 } |
191 fn = this.fn; | 244 // install event handler |
192 // console.log(data.settings.buttonSettings.fullscreen.buttonSets); | 245 $data.bind('setup', handleSetup); |
193 return { | 246 $data.bind('update', handleUpdate); |
194 }; | 247 $data.bind('redisplay', handleRedisplay); |
195 }; | 248 $data.bind('dragZoom', handleDragZoom); |
249 }; | |
250 | |
251 // plugin object with name and init | |
252 // shared objects filled by digilib on registration | |
253 var pluginProperties = { | |
254 name : 'region', | |
255 install : install, | |
256 init : init, | |
257 buttons : {}, | |
258 actions : {}, | |
259 fn : {}, | |
260 plugins : {} | |
261 }; | |
262 | |
196 if ($.fn.digilib == null) { | 263 if ($.fn.digilib == null) { |
197 $.error("jquery.digilib.regions must be loaded after jquery.digilib!"); | 264 $.error("jquery.digilib.birdview must be loaded after jquery.digilib!"); |
198 } else { | 265 } else { |
199 $.fn.digilib('plugin', {name : 'regions', init : init}); | 266 $.fn.digilib('plugin', pluginProperties); |
200 } | 267 } |
201 })(jQuery); | 268 })(jQuery); |