annotate client/digitallibrary/jquery/jquery.digilib.regions.js @ 808:ae8e98c479d5 jquery

stub for new plugins; overlay div for regions plugin
author hertzhaft
date Sun, 20 Feb 2011 13:24:49 +0100
parents 12f790cb30de
children 1a7b14deae3a
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 = {
808
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
56
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
57 // define a region interactively with two clicked points
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
58 "setRegion" : function(data) {
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
59 var $elem = data.$elem;
808
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
60 var $body = $('body');
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
61 var bodyRect = geom.rectangle($body);
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
62 var $scaler = data.$scaler;
808
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
63 var scalerRect = geom.rectangle($scaler);
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
64 var pt1, pt2;
808
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
65 // overlay prevents other elements from reacting to mouse events
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
66 var $overlay = $('<div class="digilib-overlay"/>');
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
67 $body.append($overlay);
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
68 bodyRect.adjustDiv($overlay);
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
69 // the region to be defined
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
70 var $regionDiv = $('<div class="region" style="display:none"/>');
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
71 $elem.append($regionDiv);
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
72
808
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
73 // mousedown handler: start sizing
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
74 var regionStart = function (evt) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
75 pt1 = geom.position(evt);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
76 // setup and show zoom div
808
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
77 pt1.adjustDiv($regionDiv);
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
78 $regionDiv.width(0).height(0);
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
79 $regionDiv.show();
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
80 // register mouse events
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
81 $overlay.bind("mousemove.dlRegion", regionMove);
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
82 $overlay.bind("mouseup.dlRegion", regionEnd);
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
83 return false;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
84 };
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
85
808
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
86 // mousemove handler: size region
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
87 var regionMove = function (evt) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
88 pt2 = geom.position(evt);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
89 var rect = geom.rectangle(pt1, pt2);
808
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
90 rect.clipTo(scalerRect);
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
91 // update region
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
92 rect.adjustDiv($regionDiv);
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
93 return false;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
94 };
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
95
808
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
96 // mouseup handler: end sizing
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
97 var regionEnd = function (evt) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
98 pt2 = geom.position(evt);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
99 // assume a click and continue if the area is too small
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
100 var clickRect = geom.rectangle(pt1, pt2);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
101 if (clickRect.getArea() <= 5) return false;
808
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
102 // unregister mouse events and get rid of overlay
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
103 $overlay.unbind("mousemove.dlRegion", regionMove);
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
104 $overlay.unbind("mouseup.dlRegion", regionEnd);
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
105 $overlay.remove();
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
106 // clip region
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
107 clickRect.clipTo(scalerRect);
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
108 clickRect.adjustDiv($regionDiv);
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
109 data.settings.regions.push(clickRect); // TODO: trafo, params
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
110 // fn.redisplay(data);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
111 return false;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
112 };
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
113
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
114 // bind start zoom handler
808
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
115 $overlay.one('mousedown.dlRegion', regionStart);
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
116 },
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
117
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
118 // remove the last added region
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
119 "removeRegion" : function (data) {
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
120 var $regionDiv = data.settings.regions.pop();
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
121 $regionDiv.remove();
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
122 // fn.redisplay(data);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
123 },
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
124
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
125 // add a region programmatically
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
126 "addRegion" : function(data, pos, url) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
127 // TODO: backlink mechanism
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
128 if (pos.length === 4) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
129 // TODO: trafo
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
130 var $regionDiv = $('<div class="region" style="display:none"/>');
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
131 $regionDiv.attr("id", "region" + i);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
132 var regionRect = geom.rectangle(pos[0], pos[1], pos[2], pos[3]);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
133 regionRect.adjustDiv($regionDiv);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
134 if (!data.regions) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
135 data.regions = [];
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
136 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
137 data.regions.push($regionDiv);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
138 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
139 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
140 };
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
141
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
142 var addRegion = actions.addRegion;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
143
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
144 var realizeRegions = function (data) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
145 // create regions from parameters
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
146 var settings = data.settings;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
147 var rg = settings.rg;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
148 var regions = rg.split(",");
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
149 for (var i = 0; i < regions.length ; i++) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
150 var pos = regions.split("/", 4);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
151 // TODO: backlink mechanism
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
152 var url = paramString.match(/http.*$/);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
153 addRegion(data, pos, url);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
154 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
155 };
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
156
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
157 // display current regions
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
158 var renderRegions = function (data) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
159 var regions = data.regions;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
160 for (var i = 0; i < regions.length; i++) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
161 var region = regions[i];
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
162 if (data.zoomArea.containsPosition(region)) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
163 var rpos = data.imgTrafo.transform(region);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
164 console.debug("renderRegions: rpos=", rpos);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
165 // create region
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
166 var $regionDiv = $('<div class="region" style="display:none"/>');
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
167 $regionDiv.attr("id", "region" + data.regions.length);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
168 $elem.append($regionDiv);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
169 rpos.adjustDiv($regionDiv);
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
170 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
171 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
172 };
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
173
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
174 var serializeRegions = function (data) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
175 if (data.regions) {
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 for (var i = 0; i < data.regions.length; i++) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
178 if (i) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
179 settings.rg += ',';
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
180 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
181 settings.rg +=
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
182 cropFloat(data.regions[i].x).toString() + '/' +
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
183 cropFloat(data.regions[i].y).toString() + '/' +
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
184 cropFloat(data.regions[i].width).toString() + '/' +
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
185 cropFloat(data.regions[i].height).toString();
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
186 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
187 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
188 };
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
189
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
190 var handleSetup = function (evt) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
191 console.debug("regions: handleSetup");
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
192 data = this;
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
193 // if (data.settings.isBirdDivVisible) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
194 // setupBirdDiv(data);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
195 // data.$birdDiv.show();
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
196 // }
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
197 };
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
198
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
199 var handleUpdate = function (evt) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
200 console.debug("regions: handleUpdate");
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
201 data = this;
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
202 // if (data.settings.isBirdDivVisible) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
203 // renderBirdArea(data);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
204 // setupBirdDrag(data);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
205 // }
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
206 };
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
207
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
208 var handleRedisplay = function (evt) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
209 console.debug("regions: handleRedisplay");
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
210 data = this;
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
211 // if (data.settings.isBirdDivVisible) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
212 // updateBirdDiv(data);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
213 // }
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
214 };
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
215
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
216 var handleDragZoom = function (evt, zoomArea) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
217 console.debug("regions: handleDragZoom, zoomArea:", zoomArea);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
218 data = this;
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
219 // if (data.settings.isBirdDivVisible) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
220 // setBirdZoom(data, zoomArea);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
221 // }
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
222 };
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
223
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
224 // plugin installation called by digilib on plugin object.
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
225 var install = function(digilib) {
808
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
226 console.debug('installing regions plugin. digilib:', digilib);
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
227 // import geometry classes
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
228 geom = digilib.fn.geometry;
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
229 FULL_AREA = geom.rectangle(0,0,1,1);
808
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
230 // add defaults, actions, buttons
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
231 $.extend(digilib.defaults, defaults);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
232 $.extend(digilib.actions, actions);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
233 $.extend(digilib.buttons, buttons);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
234 };
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
235
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
236 // plugin initialization
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
237 var init = function (data) {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
238 console.debug('initialising regions plugin. data:', data);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
239 var $data = $(data);
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
240 var buttonSettings = data.settings.buttonSettings.fullscreen;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
241 // configure buttons through digilib "regionSet" option
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
242 var buttonSet = data.settings.regionSet || regionSet;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
243 // set regionSet to [] or '' for no buttons (when showing regions only)
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
244 if (buttonSet.length && buttonSet.length > 0) {
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
245 buttonSettings['regionSet'] = buttonSet;
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
246 buttonSettings.buttonSets.push('regionSet');
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
247 }
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
248 // install event handler
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
249 $data.bind('setup', handleSetup);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
250 $data.bind('update', handleUpdate);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
251 $data.bind('redisplay', handleRedisplay);
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
252 $data.bind('dragZoom', handleDragZoom);
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
253 };
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
254
808
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
255 // plugin object with name and install/init methods
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
256 // shared objects filled by digilib on registration
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
257 var pluginProperties = {
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
258 name : 'region',
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
259 install : install,
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
260 init : init,
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
261 buttons : {},
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
262 actions : {},
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
263 fn : {},
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
264 plugins : {}
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
265 };
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
266
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
267 if ($.fn.digilib == null) {
808
ae8e98c479d5 stub for new plugins; overlay div for regions plugin
hertzhaft
parents: 799
diff changeset
268 $.error("jquery.digilib.regions must be loaded after jquery.digilib!");
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
269 } else {
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 792
diff changeset
270 $.fn.digilib('plugin', pluginProperties);
792
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
271 }
d742bd92b05a first step to a regions plugin
hertzhaft
parents:
diff changeset
272 })(jQuery);