annotate client/digitallibrary/jquery/jquery.digilib.regions.js @ 816:36fbccbaf413 jquery

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