annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
1 /** optional digilib regions plugin
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
2
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
3 markup a digilib image with rectangular regions
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
4
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
5 TODO:
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
6 - store region in params/cookie, regarding zoom, mirror, rotation (like marks)
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
7 - set regions programmatically
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
8 - read regions from params/cookie and display
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
9 - backlink mechanism
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
10 - don't write to data.settings?
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
11 */
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
12
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
13 (function($) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
14 // the data object passed by digilib
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
15 var data;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
16 var buttons;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
17 var fn;
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
18 // affine geometry plugin stub
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
19 var geom;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
20
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
21 var FULL_AREA;
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
22
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
23 var buttons = {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
24 addregion : {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
25 onclick : "setRegion",
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
26 tooltip : "set a region",
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
27 icon : "addregion.png"
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
28 },
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
29 delregion : {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
30 onclick : "removeRegion",
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
31 tooltip : "delete the last region",
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
32 icon : "delregion.png"
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
33 },
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
34 regions : {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
35 onclick : "toggleRegions",
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
36 tooltip : "show or hide regions",
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
37 icon : "regions.png"
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
38 },
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
39 regioninfo : {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
40 onclick : "infoRegions",
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
41 tooltip : "information about regions",
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
42 icon : "regioninfo.png"
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
43 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
44 };
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
45
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
46 var defaults = {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
47 // are regions shown?
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
48 'isRegionVisible' : true,
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
49 // buttonset of this plugin
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
50 'regionSet' : ['addregion', 'delregion', 'regions', 'regioninfo', 'lessoptions'],
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
51 // array of defined regions
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
52 'regions' : []
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
53 };
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
54
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
55 var actions = {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
56 // define a region interactively with two clicked points
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
57 "setRegion" : function(data) {
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
58 var $elem = data.$elem;
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
59 var $scaler = data.$scaler;
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
60 var picRect = geom.rectangle($scaler);
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
61 var pt1, pt2;
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
62 // TODO: temporary rectangle only, pass values to "addRegion" factory
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
63 var $tempDiv = $('<div class="region" style="display:none"/>');
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
64 $elem.append($tempDiv);
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
65
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
66 var regionStart = function (evt) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
67 pt1 = geom.position(evt);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
68 // setup and show zoom div
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
69 pt1.adjustDiv($tempDiv);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
70 $tempDiv.width(0).height(0);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
71 $tempDiv.show();
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
72 // register events
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
73 $elem.bind("mousemove.dlRegion", regionMove);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
74 $elem.bind("mouseup.dlRegion", regionEnd);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
75 return false;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
76 };
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
77
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
78 // mouse move handler
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
79 var regionMove = function (evt) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
80 pt2 = geom.position(evt);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
81 var rect = geom.rectangle(pt1, pt2);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
82 rect.clipTo(picRect);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
83 // update zoom div
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
84 rect.adjustDiv($tempDiv);
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
85 return false;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
86 };
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
87
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
88 // mouseup handler: end moving
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
89 var regionEnd = function (evt) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
90 pt2 = geom.position(evt);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
91 // assume a click and continue if the area is too small
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
92 var clickRect = geom.rectangle(pt1, pt2);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
93 if (clickRect.getArea() <= 5) return false;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
94 // unregister events
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
95 $elem.unbind("mousemove.dlRegion", regionMove);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
96 $elem.unbind("mouseup.dlRegion", regionEnd);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
97 // clip and transform
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
98 clickRect.clipTo(picRect);
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
99 clickRect.adjustDiv($tempDiv);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
100 $tempDiv.remove();
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
101 data.settings.regions.push(clickRect);
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
102 // fn.redisplay(data);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
103 return false;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
104 };
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
105
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
106 // clear old handler (also ZoomDrag)
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
107 $scaler.unbind('.dlRegion');
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
108 $elem.unbind('.dlRegion');
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
109 // bind start zoom handler
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
110 $scaler.one('mousedown.dlRegion', regionStart);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
111 },
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
112
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
113 // remove the last added region
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
114 "removeRegion" : function (data) {
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
115 var $regionDiv = data.settings.regions.pop();
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
116 $regionDiv.remove();
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
117 // fn.redisplay(data);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
118 },
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
119
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
120 // add a region programmatically
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
121 "addRegion" : function(data, pos, url) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
122 // TODO: backlink mechanism
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
123 if (pos.length === 4) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
124 // TODO: trafo
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
125 var $regionDiv = $('<div class="region" style="display:none"/>');
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
126 $regionDiv.attr("id", "region" + i);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
127 var regionRect = geom.rectangle(pos[0], pos[1], pos[2], pos[3]);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
128 regionRect.adjustDiv($regionDiv);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
129 if (!data.regions) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
130 data.regions = [];
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
131 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
132 data.regions.push($regionDiv);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
133 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
134 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
135 };
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
136
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
137 var addRegion = actions.addRegion;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
138
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
139 var realizeRegions = function (data) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
140 // create regions from parameters
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
141 var settings = data.settings;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
142 var rg = settings.rg;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
143 var regions = rg.split(",");
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
144 for (var i = 0; i < regions.length ; i++) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
145 var pos = regions.split("/", 4);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
146 // TODO: backlink mechanism
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
147 var url = paramString.match(/http.*$/);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
148 addRegion(data, pos, url);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
149 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
150 };
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
151
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
152 // display current regions
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
153 var renderRegions = function (data) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
154 var regions = data.regions;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
155 for (var i = 0; i < regions.length; i++) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
156 var region = regions[i];
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
157 if (data.zoomArea.containsPosition(region)) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
158 var rpos = data.imgTrafo.transform(region);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
159 console.debug("renderRegions: rpos=", rpos);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
160 // create region
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
161 var $regionDiv = $('<div class="region" style="display:none"/>');
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
162 $regionDiv.attr("id", "region" + data.regions.length);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
163 $elem.append($regionDiv);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
164 rpos.adjustDiv($regionDiv);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
165 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
166 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
167 };
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
168
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
169 var serializeRegions = function (data) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
170 if (data.regions) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
171 settings.rg = '';
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
172 for (var i = 0; i < data.regions.length; i++) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
173 if (i) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
174 settings.rg += ',';
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
175 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
176 settings.rg +=
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
177 cropFloat(data.regions[i].x).toString() + '/' +
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
178 cropFloat(data.regions[i].y).toString() + '/' +
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
179 cropFloat(data.regions[i].width).toString() + '/' +
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
180 cropFloat(data.regions[i].height).toString();
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
181 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
182 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
183 };
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
184
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
185 var handleSetup = function (evt) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
186 console.debug("regions: handleSetup");
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
187 data = this;
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
188 // if (data.settings.isBirdDivVisible) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
189 // setupBirdDiv(data);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
190 // data.$birdDiv.show();
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
191 // }
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
192 };
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
193
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
194 var handleUpdate = function (evt) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
195 console.debug("regions: handleUpdate");
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
196 data = this;
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
197 // if (data.settings.isBirdDivVisible) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
198 // renderBirdArea(data);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
199 // setupBirdDrag(data);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
200 // }
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
201 };
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
202
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
203 var handleRedisplay = function (evt) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
204 console.debug("regions: handleRedisplay");
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
205 data = this;
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
206 // if (data.settings.isBirdDivVisible) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
207 // updateBirdDiv(data);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
208 // }
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
209 };
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
210
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
211 var handleDragZoom = function (evt, zoomArea) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
212 console.debug("regions: handleDragZoom, zoomArea:", zoomArea);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
213 data = this;
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
214 // if (data.settings.isBirdDivVisible) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
215 // setBirdZoom(data, zoomArea);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
216 // }
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
217 };
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
218
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
219 // plugin installation called by digilib on plugin object.
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
220 var install = function(digilib) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
221 // import geometry classes
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
222 geom = digilib.fn.geometry;
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
223 FULL_AREA = geom.rectangle(0,0,1,1);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
224 // add defaults
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
225 $.extend(digilib.defaults, defaults);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
226 // add actions
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
227 $.extend(digilib.actions, actions);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
228 // add buttons
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
229 $.extend(digilib.buttons, buttons);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
230 };
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
231
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
232 // plugin initialization
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
233 var init = function (data) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
234 console.debug('initialising regions plugin. data:', data);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
235 var $data = $(data);
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
236 var buttonSettings = data.settings.buttonSettings.fullscreen;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
237 // configure buttons through digilib "regionSet" option
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
238 var buttonSet = data.settings.regionSet || regionSet;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
239 // set regionSet to [] or '' for no buttons (when showing regions only)
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
240 if (buttonSet.length && buttonSet.length > 0) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
241 buttonSettings['regionSet'] = buttonSet;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
242 buttonSettings.buttonSets.push('regionSet');
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
243 }
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
244 // install event handler
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
245 $data.bind('setup', handleSetup);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
246 $data.bind('update', handleUpdate);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
247 $data.bind('redisplay', handleRedisplay);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
248 $data.bind('dragZoom', handleDragZoom);
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
249 };
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
250
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
251 // plugin object with name and init
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
252 // shared objects filled by digilib on registration
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
253 var pluginProperties = {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
254 name : 'region',
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
255 install : install,
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
256 init : init,
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
257 buttons : {},
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
258 actions : {},
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
259 fn : {},
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
260 plugins : {}
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
261 };
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
262
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
263 if ($.fn.digilib == null) {
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
264 $.error("jquery.digilib.birdview must be loaded after jquery.digilib!");
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
265 } else {
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
266 $.fn.digilib('plugin', pluginProperties);
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
267 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
268 })(jQuery);