annotate client/digitallibrary/jquery/jquery.digilib.regions.js @ 852:4658ec2f9565 jquery

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