annotate client/digitallibrary/jquery/jquery.digilib.regions.js @ 801:2fb1f576375d jquery

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