Mercurial > hg > digilib-old
annotate webapp/src/main/webapp/jquery/jquery.digilib.annotator.js @ 1118:f0474c1faaff
trying new annotator authentication.
author | robcast |
---|---|
date | Tue, 06 Nov 2012 18:24:39 +0100 |
parents | 08206603c7dc |
children | 036efe7361c8 |
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" | |
32 } | |
33 }; | |
34 | |
35 var defaults = { | |
36 // are annotations active? | |
37 'isAnnotationsVisible' : true, | |
38 // buttonset of this plugin | |
39 'annotationSet' : ['annotations', 'annotationuser', 'annotationmark', 'lessoptions'], | |
40 // URL of annotation server | |
41 'annotationServerUrl' : 'http://virtuoso.mpiwg-berlin.mpg.de:8080/AnnotationManager/annotator', | |
42 // URL of authentication token server | |
43 'annotationTokenUrl' : 'http://localhost:8080/test/annotator/token', | |
44 // annotation user name | |
45 'annotationUser' : 'anonymous', | |
46 // function to translate user name from annotation server format | |
47 'annotationServerUserString' : function() { | |
48 if (this.user && this.user.name) { | |
49 return this.user.name; | |
50 } | |
51 return this.user; | |
52 }, | |
53 | |
1118 | 54 // Annotator plugin settings (some values provided in handleSetup) |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
55 'annotatorPlugins' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
56 //'Tags' : {}, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
57 'Auth' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
58 //token : data.annotationToken |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
59 //tokenUrl: data.settings.annotationTokenUrl |
1118 | 60 autoFetch: true, |
61 requestMethod: 'POST', | |
62 requestData: { | |
63 //'user': data.settings.annotationUser, | |
64 //'password': data.annotationPassword | |
65 } | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
66 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
67 'Permissions' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
68 //user: data.settings.annotationUser, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
69 userString : function(user) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
70 if (user && user.name) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
71 return user.name; |
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 return user; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
74 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
75 userId: function (user) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
76 if (user && user.id) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
77 return user.id; |
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 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
82 'Store' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
83 //prefix : data.settings.annotationServerUrl, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
84 annotationData: { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
85 //'uri': getAnnotationPageUrl() |
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 loadFromSearch: { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
88 'limit': 20, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
89 //'uri': getAnnotationPageUrl() |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
90 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
91 } |
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 |
1113 | 94 }; |
95 | |
96 var actions = { | |
97 /** | |
98 * show/hide annotations | |
99 */ | |
100 toggleAnnotations : function (data) { | |
101 var show = !data.settings.isAnnotationsVisible; | |
102 data.settings.isAnnotationsVisible = show; | |
103 digilib.fn.highlightButtons(data, 'annotations', show); | |
104 renderAnnotations(data); | |
105 }, | |
106 | |
107 /** | |
108 * set user account for annotations | |
109 */ | |
110 setAnnotationUser : function (data, user, password) { | |
111 var settings = data.settings; | |
112 if (user == null) { | |
113 // user name entered in JS-prompt | |
114 user = window.prompt("User name:", settings.annotationUser); | |
115 if (user != null) { | |
116 // password entered in JS-prompt | |
117 password = window.prompt("Password:", ''); | |
118 settings.annotationUser = user; | |
119 data.dlOpts.annotationUser = user; | |
120 digilib.fn.storeOptions(data); | |
121 loadAnnotationToken(data, password); | |
122 } | |
123 } else { | |
124 settings.annotationUser = user; | |
125 data.dlOpts.annotationUser = user; | |
126 digilib.fn.storeOptions(data); | |
127 loadAnnotationToken(data, password); | |
128 } | |
129 }, | |
130 | |
131 /** | |
132 * set a mark-annotation by clicking (or giving a position and a text) | |
133 * | |
134 * @param data | |
135 * @param mpos | |
136 * @param text | |
137 */ | |
138 setAnnotationMark : function (data, mpos, text) { | |
139 if (mpos == null) { | |
140 // interactive | |
141 setAnnotationMark(data); | |
142 } else { | |
143 // use position and text (and user-id) | |
1118 | 144 console.error("Currently only interactive annotations!"); |
1113 | 145 } |
146 }, | |
147 }; | |
148 | |
149 /** | |
150 * returns an annotatable url to this digilib image | |
151 */ | |
152 var getAnnotationPageUrl = function(data) { | |
153 var url = data.settings.digilibBaseUrl + '/jquery/digilib.html?'; | |
154 url += digilib.fn.getParamString(data.settings, ['fn', 'pn'], digilib.defaults); | |
155 return url; | |
156 }; | |
157 | |
158 /** | |
159 * add a mark-annotation where clicked. | |
160 */ | |
161 var setAnnotationMark = function(data) { | |
162 var $scaler = data.$scaler; | |
163 // unbind other handler TODO: do we need to do this? | |
164 $scaler.off(".dlZoomDrag"); | |
165 // start event capturing | |
166 $scaler.one('mousedown.dlSetAnnotationMark', function(evt) { | |
167 // event handler adding a new mark | |
168 console.log("setAnnotationMark at=", evt); | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
169 var annotator = data.annotator; |
1113 | 170 var mpos = geom.position(evt); |
171 var pos = data.imgTrafo.invtransform(mpos); | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
172 // mark selected areas |
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
173 annotator.selectedAreas = [geom.rectangle(pos)]; |
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
174 // create and edit new annotation |
1113 | 175 var annotation = annotator.createAnnotation(); |
176 annotator.showEditor(annotation, mpos.getAsCss()); | |
177 return false; | |
178 }); | |
179 }; | |
180 | |
181 /** | |
182 * place annotations on the image | |
183 */ | |
1114 | 184 var renderAnnotations = function (data) { |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
185 console.debug("renderAnnotations!"); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
186 if (data.annotations == null || data.annotator == null || data.$img == null || data.imgTrafo == null) |
1113 | 187 return; |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
188 var annotations = data.annotations; |
1113 | 189 var cssPrefix = data.settings.cssPrefix; |
190 var $elem = data.$elem; | |
191 // try to show annotation user state | |
192 $elem.find('div#'+cssPrefix+'button-annotationuser').attr('title', 'annotation user: '+data.settings.annotationUser); | |
193 // clear annotations | |
194 $elem.find('div.' + cssPrefix + 'annotationmark').remove(); | |
195 if (!data.settings.isAnnotationsVisible) return; | |
196 for (var i = 0; i < annotations.length; i++) { | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
197 renderAnnotation(data, annotations[i]); |
1113 | 198 } |
199 }; | |
200 | |
201 /** | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
202 * place single annotation on the image |
1113 | 203 */ |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
204 var renderAnnotation = function (data, annot) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
205 console.debug("renderAnnotation: annotation=", annot); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
206 if (annot == null || annot.annotation == null || annot.annotation.areas == null |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
207 || data.$img == null || data.imgTrafo == null) |
1113 | 208 return; |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
209 if (!data.settings.isAnnotationsVisible) return; |
1113 | 210 var cssPrefix = data.settings.cssPrefix; |
211 var $elem = data.$elem; | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
212 var annotator = data.annotator; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
213 var annotation = annot.annotation; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
214 var idx = annot.idx ? annot.idx : '?'; |
1113 | 215 var pos = geom.position(annotation.areas[0]); |
216 if (data.zoomArea.containsPosition(pos)) { | |
217 var mpos = data.imgTrafo.transform(pos); | |
218 console.debug("renderannotations: pos=", mpos); | |
219 // create annotation | |
1114 | 220 var html = '<div class="'+cssPrefix+'annotationmark '+cssPrefix+'overlay annotator-hl">'+idx+'</div>'; |
1113 | 221 var $annotation = $(html); |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
222 // save annotation in data for Annotator |
1114 | 223 $annotation.data('annotation', annotation); |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
224 // save reference to div |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
225 annot.$div = $annotation; |
1113 | 226 $elem.append($annotation); |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
227 // hook up Annotator events |
1114 | 228 $annotation.on("mouseover", annotator.onHighlightMouseover); |
229 $annotation.on("mouseout", annotator.startViewerHideTimer); | |
1113 | 230 mpos.adjustDiv($annotation); |
231 } | |
232 }; | |
233 | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
234 /** |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
235 * returns setupAnnotation function using the given data. |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
236 */ |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
237 var getSetupAnnotation = function(data) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
238 return function (annotation) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
239 // create annotation wrapper |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
240 var ann = { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
241 'annotation' : annotation, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
242 'idx' : data.annotations.length+1 |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
243 }; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
244 // add to list |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
245 data.annotations.push(ann); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
246 // render this annotation |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
247 renderAnnotation(data, ann); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
248 }; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
249 }; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
250 |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
251 /** |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
252 * returns annotationDeleted function using the given data. |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
253 */ |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
254 var getAnnotationDeleted = function(data) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
255 return function (annotation) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
256 // remove annotation mark |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
257 var annots = data.annotations; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
258 for (var i = 0; i < annots.length; ++i) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
259 var annot = annots[i]; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
260 if (annot.annotation === annotation) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
261 // this is the right wrapper |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
262 if (annot.$div != null) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
263 // remove from screen |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
264 annot.$div.remove(); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
265 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
266 // remove from list |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
267 delete annots[i]; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
268 break; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
269 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
270 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
271 }; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
272 }; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
273 |
1113 | 274 /** |
275 * Get an authentication token from the token server. | |
276 * | |
277 * Stores the token and loads annotations on success. | |
278 */ | |
279 var loadAnnotationToken = function(data, password) { | |
280 var settings = data.settings; | |
281 var url = settings.annotationTokenUrl; | |
282 var params = {'user': settings.annotationUser}; | |
283 if (password != null) { | |
284 params.password = password; | |
285 } | |
286 // TODO: better error handling | |
287 $.post(url, params) | |
288 .done(function (authToken, authStatus) { | |
289 console.debug("got auth token data=", authToken); | |
290 data.annotationToken = authToken; | |
291 data.dlOpts.annotationToken = authToken; | |
292 digilib.fn.storeOptions(data); | |
293 //loadAnnotations(data); | |
294 }) | |
295 .fail(function (xhr, status) { | |
296 console.error("got auth token error:", xhr); | |
297 data.annotationToken = null; | |
298 data.settings.annotationUser = "anonymous"; | |
299 //loadAnnotations(data); | |
300 }); | |
301 }; | |
302 | |
303 /** | |
304 * install additional buttons | |
305 */ | |
306 var installButtons = function(data) { | |
307 var settings = data.settings; | |
308 var mode = settings.interactionMode; | |
309 var buttonSettings = settings.buttonSettings[mode]; | |
310 // configure buttons through digilib "annotationSet" option | |
311 var buttonSet = settings.annotationSet || annotationSet; | |
312 // set annotationSet to [] or '' for no buttons (when showing annotations only) | |
313 if (buttonSet.length && buttonSet.length > 0) { | |
314 buttonSettings.annotationSet = buttonSet; | |
315 buttonSettings.buttonSets.push('annotationSet'); | |
316 } | |
317 }; | |
318 | |
319 /** | |
320 * plugin installation. called by digilib on plugin object. | |
321 */ | |
322 var install = function(plugin) { | |
323 digilib = plugin; | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
324 console.debug('installing annotator plugin. digilib:', digilib); |
1113 | 325 // import geometry classes |
326 geom = digilib.fn.geometry; | |
327 FULL_AREA = geom.rectangle(0, 0, 1, 1); | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
328 // add defaults, actions, buttons |
1113 | 329 $.extend(digilib.defaults, defaults); |
330 $.extend(digilib.actions, actions); | |
331 $.extend(digilib.buttons, buttons); | |
332 }; | |
333 | |
334 /** plugin initialization */ | |
335 var init = function(data) { | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
336 console.debug('initialising annotator plugin. data:', data); |
1113 | 337 var $data = $(data); |
338 // set up | |
339 data.annotations = []; | |
340 if (digilib.plugins.buttons != null) { | |
341 installButtons(data); | |
342 } | |
343 if (data.dlOpts.annotationUser != null) { | |
344 // get annotation user from cookie | |
345 data.settings.annotationUser = data.dlOpts.annotationUser; | |
346 } | |
347 if (data.dlOpts.annotationToken != null) { | |
348 // get annotation token from cookie | |
349 data.annotationToken = data.dlOpts.annotationToken; | |
350 } | |
351 // install event handler | |
352 $data.bind('setup', handleSetup); | |
353 $data.bind('update', handleUpdate); | |
354 }; | |
355 | |
356 /** | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
357 * setup creates Annotator object. |
1113 | 358 */ |
359 var handleSetup = function(evt) { | |
360 console.debug("annotations: handleSetup"); | |
361 var data = this; | |
1118 | 362 /* if (data.annotationToken == null) { |
1113 | 363 loadAnnotationToken(data); |
1118 | 364 } */ |
1113 | 365 // set up annotator (after html has been set up) |
366 var uri = getAnnotationPageUrl(data); | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
367 var annotator = new Annotator(data.$elem.get(0)); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
368 // set plugin parameters |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
369 var pluginParams = { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
370 'Auth' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
371 'token' : data.annotationToken, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
372 'tokenUrl' : data.settings.annotationTokenUrl, |
1118 | 373 'autoFetch' : true |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
374 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
375 'Permissions' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
376 'user' : data.settings.annotationUser |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
377 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
378 'Store' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
379 'prefix' : data.settings.annotationServerUrl, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
380 'annotationData' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
381 'uri': uri |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
382 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
383 'loadFromSearch' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
384 'uri': uri |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
385 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
386 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
387 'DigilibIntegrator' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
388 'hooks' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
389 'setupAnnotation' : getSetupAnnotation(data), |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
390 'annotationDeleted' : getAnnotationDeleted(data) |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
391 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
392 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
393 }; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
394 // merge with settings |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
395 $.extend(true, pluginParams, data.settings.annotatorPlugins); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
396 // add plugins |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
397 $.each(pluginParams, function (name, params) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
398 console.debug("plugin:", name, params); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
399 annotator.addPlugin(name, params); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
400 }); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
401 // save annotator reference |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
402 data.annotator = annotator; |
1113 | 403 }; |
404 | |
405 /** | |
406 * update renders all annotations. | |
407 */ | |
408 var handleUpdate = function(evt) { | |
409 console.debug("annotations: handleUpdate"); | |
410 var data = this; | |
411 renderAnnotations(data); | |
412 }; | |
413 | |
414 // plugin object with name and init | |
415 // shared objects filled by digilib on registration | |
416 var plugin = { | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
417 name : 'annotator', |
1113 | 418 install : install, |
419 init : init, | |
420 buttons : {}, | |
421 actions : {}, | |
422 fn : {}, | |
423 plugins : {} | |
424 }; | |
425 | |
426 if ($.fn.digilib == null) { | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
427 $.error("jquery.digilib.annotator must be loaded after jquery.digilib!"); |
1113 | 428 } else { |
429 $.fn.digilib('plugin', plugin); | |
430 } | |
431 })(jQuery); |