Mercurial > hg > digilib-old
annotate webapp/src/main/webapp/jquery/jquery.digilib.annotator.js @ 1125:f1be20adc98b
annotatorPlugins is now a list of plugin names (preserving order).
author | robcast |
---|---|
date | Fri, 09 Nov 2012 15:07:12 +0100 |
parents | 1fad569ccb4f |
children | f14220f939d5 |
rev | line source |
---|---|
1113 | 1 /** |
2 digilib plugin for annotations. | |
3 | |
4 currently only point-like annotations (like marks). | |
5 | |
6 Annotations are stored on a Annotator http://annotateit.org compatible server. | |
7 | |
8 */ | |
9 | |
10 (function($) { | |
11 | |
12 // affine geometry | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
13 var geom = null; |
1113 | 14 // plugin object with digilib data |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
15 var digilib = null; |
1113 | 16 |
17 var buttons = { | |
18 annotations : { | |
19 onclick : "toggleAnnotations", | |
20 tooltip : "show or hide annotations", | |
21 icon : "annotations.png" | |
22 }, | |
23 annotationuser : { | |
24 onclick : "setAnnotationUser", | |
25 tooltip : "set user account for annotations", | |
26 icon : "annotation-user.png" | |
27 }, | |
28 annotationmark : { | |
29 onclick : "setAnnotationMark", | |
30 tooltip : "create an annotation for a point", | |
31 icon : "annotation-mark.png" | |
1121 | 32 }, |
33 annotationregion : { | |
34 onclick : "setAnnotationRegion", | |
35 tooltip : "create an annotation for a region", | |
36 icon : "annotation-region.png" | |
1113 | 37 } |
38 }; | |
39 | |
40 var defaults = { | |
41 // are annotations active? | |
42 'isAnnotationsVisible' : true, | |
43 // buttonset of this plugin | |
1121 | 44 'annotationSet' : ['annotations', 'annotationuser', 'annotationmark', 'annotationregion', 'lessoptions'], |
1113 | 45 // URL of annotation server |
46 'annotationServerUrl' : 'http://virtuoso.mpiwg-berlin.mpg.de:8080/AnnotationManager/annotator', | |
47 // URL of authentication token server | |
48 'annotationTokenUrl' : 'http://localhost:8080/test/annotator/token', | |
49 // annotation user name | |
50 'annotationUser' : 'anonymous', | |
51 // function to translate user name from annotation server format | |
52 'annotationServerUserString' : function() { | |
53 if (this.user && this.user.name) { | |
54 return this.user.name; | |
55 } | |
56 return this.user; | |
57 }, | |
58 | |
1125
f1be20adc98b
annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents:
1123
diff
changeset
|
59 // list of Annotator plugins |
f1be20adc98b
annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents:
1123
diff
changeset
|
60 'annotatorPlugins' : ['Auth', 'Permissions', 'Store', 'DigilibIntegrator'], |
1118 | 61 // Annotator plugin settings (some values provided in handleSetup) |
1125
f1be20adc98b
annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents:
1123
diff
changeset
|
62 'annotatorPluginSettings' : { |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
63 'Auth' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
64 //token : data.annotationToken |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
65 //tokenUrl: data.settings.annotationTokenUrl |
1118 | 66 autoFetch: true, |
67 requestMethod: 'POST', | |
68 requestData: { | |
69 //'user': data.settings.annotationUser, | |
70 //'password': data.annotationPassword | |
71 } | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
72 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
73 'Permissions' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
74 //user: data.settings.annotationUser, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
75 userString : function(user) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
76 if (user && user.name) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
77 return user.name; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
78 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
79 return user; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
80 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
81 userId: function (user) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
82 if (user && user.id) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
83 return user.id; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
84 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
85 return user; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
86 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
87 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
88 'Store' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
89 //prefix : data.settings.annotationServerUrl, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
90 annotationData: { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
91 //'uri': getAnnotationPageUrl() |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
92 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
93 loadFromSearch: { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
94 'limit': 20, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
95 //'uri': getAnnotationPageUrl() |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
96 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
97 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
98 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
99 |
1113 | 100 }; |
101 | |
102 var actions = { | |
103 /** | |
104 * show/hide annotations | |
105 */ | |
106 toggleAnnotations : function (data) { | |
107 var show = !data.settings.isAnnotationsVisible; | |
108 data.settings.isAnnotationsVisible = show; | |
109 digilib.fn.highlightButtons(data, 'annotations', show); | |
110 renderAnnotations(data); | |
111 }, | |
112 | |
113 /** | |
114 * set user account for annotations | |
115 */ | |
116 setAnnotationUser : function (data, user, password) { | |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
117 var annotator = data.annotator; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
118 var auth = annotator.plugins.Auth; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
119 if (auth == null) { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
120 console.error("setAnnotationUser: No Auth plugin!!"); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
121 return; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
122 } |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
123 setAnnotationUser(data, auth, user, password); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
124 // get new token |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
125 auth.token = null; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
126 auth._unsafeToken = null; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
127 auth.requestToken(); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
128 // save new token in cookie |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
129 auth.withToken(function (tkn) { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
130 data.dlOpts.annotationToken = auth.token; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
131 digilib.fn.storeOptions(data); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
132 // reload annotations |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
133 data.annotations = []; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
134 renderAnnotations(data); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
135 annotator.plugins.Store.pluginInit(); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
136 }); |
1113 | 137 }, |
138 | |
139 /** | |
140 * set a mark-annotation by clicking (or giving a position and a text) | |
141 * | |
142 * @param data | |
143 * @param mpos | |
144 * @param text | |
145 */ | |
146 setAnnotationMark : function (data, mpos, text) { | |
147 if (mpos == null) { | |
148 // interactive | |
149 setAnnotationMark(data); | |
150 } else { | |
151 // use position and text (and user-id) | |
1118 | 152 console.error("Currently only interactive annotations!"); |
1113 | 153 } |
154 }, | |
1121 | 155 |
156 /** | |
157 * set a region-annotation by clicking (or giving a position and a text) | |
158 * | |
159 * @param data | |
160 * @param mpos | |
161 * @param text | |
162 */ | |
163 setAnnotationRegion : function (data, rect, text) { | |
164 if (rect == null) { | |
165 // interactive | |
166 setAnnotationRegion(data); | |
167 } else { | |
168 // use position and text (and user-id) | |
169 console.error("Currently only interactive annotations!"); | |
170 } | |
171 } | |
1113 | 172 }; |
173 | |
174 /** | |
175 * returns an annotatable url to this digilib image | |
176 */ | |
177 var getAnnotationPageUrl = function(data) { | |
178 var url = data.settings.digilibBaseUrl + '/jquery/digilib.html?'; | |
179 url += digilib.fn.getParamString(data.settings, ['fn', 'pn'], digilib.defaults); | |
180 return url; | |
181 }; | |
182 | |
183 /** | |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
184 * sets annotation user and password in digilib and Annotator.Auth plugin. |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
185 * auth is Auth plugin instance. |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
186 */ |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
187 var setAnnotationUser = function (data, auth, user, password) { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
188 if (user == null) { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
189 // user name entered in JS-prompt |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
190 user = window.prompt("Please authenticate: User name", data.settings.annotationUser); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
191 if (user != null && user != 'anonymous') { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
192 // password entered in JS-prompt |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
193 password = window.prompt("Please authenticate: Password", ''); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
194 // set params for Auth plugin |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
195 auth.options.requestData.password = password; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
196 } else { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
197 // use anonymous user |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
198 user = 'anonymous'; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
199 delete auth.options.requestData.password; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
200 } |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
201 } |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
202 // set user in digilib |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
203 data.settings.annotationUser = user; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
204 data.dlOpts.annotationUser = user; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
205 digilib.fn.storeOptions(data); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
206 // set params for Auth plugin |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
207 auth.options.requestData.user = user; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
208 // set params for Permissions plugin |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
209 var perms = data.annotator.plugins.Permissions; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
210 if (perms != null) { |
1123
1fad569ccb4f
provide annotator javascript for digilib.annotator plugin.
robcast
parents:
1121
diff
changeset
|
211 perms.setUser(user); |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
212 } |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
213 }; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
214 |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
215 |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
216 /** |
1113 | 217 * add a mark-annotation where clicked. |
218 */ | |
219 var setAnnotationMark = function(data) { | |
220 var $scaler = data.$scaler; | |
221 // unbind other handler TODO: do we need to do this? | |
222 $scaler.off(".dlZoomDrag"); | |
223 // start event capturing | |
224 $scaler.one('mousedown.dlSetAnnotationMark', function(evt) { | |
225 // event handler adding a new mark | |
226 console.log("setAnnotationMark at=", evt); | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
227 var annotator = data.annotator; |
1113 | 228 var mpos = geom.position(evt); |
229 var pos = data.imgTrafo.invtransform(mpos); | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
230 // mark selected areas |
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
231 annotator.selectedAreas = [geom.rectangle(pos)]; |
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
232 // create and edit new annotation |
1113 | 233 var annotation = annotator.createAnnotation(); |
234 annotator.showEditor(annotation, mpos.getAsCss()); | |
235 return false; | |
236 }); | |
237 }; | |
238 | |
239 /** | |
1121 | 240 * add a region-annotation where clicked. |
241 */ | |
242 var setAnnotationRegion = function(data) { | |
243 var annotator = data.annotator; | |
244 digilib.fn.defineArea(data, function (data, rect) { | |
245 if (rect == null) return; | |
246 // event handler adding a new mark | |
247 console.log("setAnnotationRegion at=", rect); | |
248 // mark selected areas | |
249 annotator.selectedAreas = [rect]; | |
250 // create and edit new annotation | |
251 var mpos = rect.getPt1(); | |
252 var pos = data.imgTrafo.transform(mpos); | |
253 var annotation = annotator.createAnnotation(); | |
254 annotator.showEditor(annotation, pos.getAsCss()); | |
255 }); | |
256 }; | |
257 | |
258 /** | |
1113 | 259 * place annotations on the image |
260 */ | |
1114 | 261 var renderAnnotations = function (data) { |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
262 console.debug("renderAnnotations!"); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
263 if (data.annotations == null || data.annotator == null || data.$img == null || data.imgTrafo == null) |
1113 | 264 return; |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
265 var annotations = data.annotations; |
1113 | 266 var cssPrefix = data.settings.cssPrefix; |
267 var $elem = data.$elem; | |
268 // try to show annotation user state | |
269 $elem.find('div#'+cssPrefix+'button-annotationuser').attr('title', 'annotation user: '+data.settings.annotationUser); | |
270 // clear annotations | |
271 $elem.find('div.' + cssPrefix + 'annotationmark').remove(); | |
272 if (!data.settings.isAnnotationsVisible) return; | |
273 for (var i = 0; i < annotations.length; i++) { | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
274 renderAnnotation(data, annotations[i]); |
1113 | 275 } |
276 }; | |
277 | |
278 /** | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
279 * place single annotation on the image |
1113 | 280 */ |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
281 var renderAnnotation = function (data, annot) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
282 console.debug("renderAnnotation: annotation=", annot); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
283 if (annot == null || annot.annotation == null || annot.annotation.areas == null |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
284 || data.$img == null || data.imgTrafo == null) |
1113 | 285 return; |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
286 if (!data.settings.isAnnotationsVisible) return; |
1113 | 287 var cssPrefix = data.settings.cssPrefix; |
288 var $elem = data.$elem; | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
289 var annotator = data.annotator; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
290 var annotation = annot.annotation; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
291 var idx = annot.idx ? annot.idx : '?'; |
1121 | 292 var area = geom.rectangle(annotation.areas[0]); |
293 var screenRect = null; | |
294 var $annotation = null; | |
295 if (area.isRectangle()) { | |
296 var clippedArea = data.zoomArea.intersect(area); | |
297 if (clippedArea == null) return; | |
298 screenRect = data.imgTrafo.transform(clippedArea); | |
299 // console.debug("renderRegion: pos=",geom.position(screenRect)); | |
300 $annotation = $('<div class="'+cssPrefix+'annotationregion '+cssPrefix+'overlay annotator-hl">'+idx+'</div>'); | |
301 //addRegionAttributes(data, $regionDiv, attr); | |
302 } else { | |
303 var pos = area.getPosition(); | |
304 if (!data.zoomArea.containsPosition(pos)) return; | |
305 var screenRect = data.imgTrafo.transform(pos); | |
306 console.debug("renderannotations: pos=", pos); | |
1113 | 307 // create annotation |
1114 | 308 var html = '<div class="'+cssPrefix+'annotationmark '+cssPrefix+'overlay annotator-hl">'+idx+'</div>'; |
1121 | 309 $annotation = $(html); |
310 } | |
311 // save annotation in data for Annotator | |
312 $annotation.data('annotation', annotation); | |
313 // save reference to div | |
314 annot.$div = $annotation; | |
315 $elem.append($annotation); | |
316 // hook up Annotator events | |
317 $annotation.on("mouseover", annotator.onHighlightMouseover); | |
318 $annotation.on("mouseout", annotator.startViewerHideTimer); | |
319 screenRect.adjustDiv($annotation); | |
1113 | 320 }; |
321 | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
322 /** |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
323 * returns setupAnnotation function using the given data. |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
324 */ |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
325 var getSetupAnnotation = function(data) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
326 return function (annotation) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
327 // create annotation wrapper |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
328 var ann = { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
329 'annotation' : annotation, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
330 'idx' : data.annotations.length+1 |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
331 }; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
332 // add to list |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
333 data.annotations.push(ann); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
334 // render this annotation |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
335 renderAnnotation(data, ann); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
336 }; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
337 }; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
338 |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
339 /** |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
340 * returns annotationDeleted function using the given data. |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
341 */ |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
342 var getAnnotationDeleted = function(data) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
343 return function (annotation) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
344 // remove annotation mark |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
345 var annots = data.annotations; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
346 for (var i = 0; i < annots.length; ++i) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
347 var annot = annots[i]; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
348 if (annot.annotation === annotation) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
349 // this is the right wrapper |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
350 if (annot.$div != null) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
351 // remove from screen |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
352 annot.$div.remove(); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
353 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
354 // remove from list |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
355 delete annots[i]; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
356 break; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
357 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
358 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
359 }; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
360 }; |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
361 |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
362 /** |
1125
f1be20adc98b
annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents:
1123
diff
changeset
|
363 * returns unauthorizedCallback function for Annotator authlogin plugin. |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
364 */ |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
365 var getHandleUnauthorized = function (data) { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
366 return function (auth) { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
367 // prompt for user name and set user |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
368 setAnnotationUser(data, auth); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
369 // then try again |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
370 return true; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
371 }; |
1113 | 372 }; |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
373 |
1113 | 374 /** |
375 * install additional buttons | |
376 */ | |
377 var installButtons = function(data) { | |
378 var settings = data.settings; | |
379 var mode = settings.interactionMode; | |
380 var buttonSettings = settings.buttonSettings[mode]; | |
381 // configure buttons through digilib "annotationSet" option | |
382 var buttonSet = settings.annotationSet || annotationSet; | |
383 // set annotationSet to [] or '' for no buttons (when showing annotations only) | |
384 if (buttonSet.length && buttonSet.length > 0) { | |
385 buttonSettings.annotationSet = buttonSet; | |
386 buttonSettings.buttonSets.push('annotationSet'); | |
387 } | |
388 }; | |
389 | |
390 /** | |
391 * plugin installation. called by digilib on plugin object. | |
392 */ | |
393 var install = function(plugin) { | |
394 digilib = plugin; | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
395 console.debug('installing annotator plugin. digilib:', digilib); |
1113 | 396 // import geometry classes |
397 geom = digilib.fn.geometry; | |
398 FULL_AREA = geom.rectangle(0, 0, 1, 1); | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
399 // add defaults, actions, buttons |
1113 | 400 $.extend(digilib.defaults, defaults); |
401 $.extend(digilib.actions, actions); | |
402 $.extend(digilib.buttons, buttons); | |
403 }; | |
404 | |
405 /** plugin initialization */ | |
406 var init = function(data) { | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
407 console.debug('initialising annotator plugin. data:', data); |
1113 | 408 var $data = $(data); |
409 // set up | |
410 data.annotations = []; | |
411 if (digilib.plugins.buttons != null) { | |
412 installButtons(data); | |
413 } | |
414 if (data.dlOpts.annotationUser != null) { | |
415 // get annotation user from cookie | |
416 data.settings.annotationUser = data.dlOpts.annotationUser; | |
417 } | |
418 // install event handler | |
419 $data.bind('setup', handleSetup); | |
420 $data.bind('update', handleUpdate); | |
421 }; | |
422 | |
423 /** | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
424 * setup creates Annotator object. |
1113 | 425 */ |
426 var handleSetup = function(evt) { | |
427 console.debug("annotations: handleSetup"); | |
428 var data = this; | |
1125
f1be20adc98b
annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents:
1123
diff
changeset
|
429 var settings = data.settings; |
1113 | 430 // set up annotator (after html has been set up) |
431 var uri = getAnnotationPageUrl(data); | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
432 var annotator = new Annotator(data.$elem.get(0)); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
433 // set plugin parameters |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
434 var pluginParams = { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
435 'Auth' : { |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
436 'token' : data.dlOpts.annotationToken, |
1125
f1be20adc98b
annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents:
1123
diff
changeset
|
437 'tokenUrl' : settings.annotationTokenUrl, |
1119 | 438 'autoFetch' : true, |
439 'requestMethod' : 'POST', | |
440 'requestData' : { | |
1125
f1be20adc98b
annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents:
1123
diff
changeset
|
441 'user': settings.annotationUser, |
1119 | 442 }, |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
443 'unauthorizedCallback' : getHandleUnauthorized(data) |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
444 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
445 'Permissions' : { |
1125
f1be20adc98b
annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents:
1123
diff
changeset
|
446 'user' : settings.annotationUser |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
447 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
448 'Store' : { |
1125
f1be20adc98b
annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents:
1123
diff
changeset
|
449 'prefix' : settings.annotationServerUrl, |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
450 'annotationData' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
451 'uri': uri |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
452 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
453 'loadFromSearch' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
454 'uri': uri |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
455 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
456 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
457 'DigilibIntegrator' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
458 'hooks' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
459 'setupAnnotation' : getSetupAnnotation(data), |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
460 'annotationDeleted' : getAnnotationDeleted(data) |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
461 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
462 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
463 }; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
464 // merge with settings |
1125
f1be20adc98b
annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents:
1123
diff
changeset
|
465 $.extend(true, pluginParams, data.settings.annotatorPluginSettings); |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
466 // add plugins |
1125
f1be20adc98b
annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents:
1123
diff
changeset
|
467 $.each(settings.annotatorPlugins, function (idx, name) { |
f1be20adc98b
annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents:
1123
diff
changeset
|
468 var params = pluginParams[name]; |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
469 console.debug("plugin:", name, params); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
470 annotator.addPlugin(name, params); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
471 }); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
472 // save annotator reference |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
473 data.annotator = annotator; |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
474 // save annotation token in cookie |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
475 var auth = annotator.plugins.Auth; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
476 // save new token in cookie |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
477 auth.withToken(function (tkn) { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
478 data.dlOpts.annotationToken = auth.token; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
479 digilib.fn.storeOptions(data); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
480 }); |
1113 | 481 }; |
482 | |
483 /** | |
484 * update renders all annotations. | |
485 */ | |
486 var handleUpdate = function(evt) { | |
487 console.debug("annotations: handleUpdate"); | |
488 var data = this; | |
489 renderAnnotations(data); | |
490 }; | |
491 | |
492 // plugin object with name and init | |
493 // shared objects filled by digilib on registration | |
494 var plugin = { | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
495 name : 'annotator', |
1113 | 496 install : install, |
497 init : init, | |
498 buttons : {}, | |
499 actions : {}, | |
500 fn : {}, | |
501 plugins : {} | |
502 }; | |
503 | |
504 if ($.fn.digilib == null) { | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
505 $.error("jquery.digilib.annotator must be loaded after jquery.digilib!"); |
1113 | 506 } else { |
507 $.fn.digilib('plugin', plugin); | |
508 } | |
509 })(jQuery); |