Mercurial > hg > digilib-old
annotate webapp/src/main/webapp/jquery/jquery.digilib.annotator.js @ 1119:036efe7361c8
working on new auth for annotations.
author | robcast |
---|---|
date | Wed, 07 Nov 2012 11:22:29 +0100 |
parents | f0474c1faaff |
children | 8bd10cd04169 |
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) { | |
1119 | 280 return; |
1113 | 281 var settings = data.settings; |
282 var url = settings.annotationTokenUrl; | |
283 var params = {'user': settings.annotationUser}; | |
284 if (password != null) { | |
285 params.password = password; | |
286 } | |
287 // TODO: better error handling | |
288 $.post(url, params) | |
289 .done(function (authToken, authStatus) { | |
290 console.debug("got auth token data=", authToken); | |
291 data.annotationToken = authToken; | |
292 data.dlOpts.annotationToken = authToken; | |
293 digilib.fn.storeOptions(data); | |
294 //loadAnnotations(data); | |
295 }) | |
296 .fail(function (xhr, status) { | |
297 console.error("got auth token error:", xhr); | |
298 data.annotationToken = null; | |
299 data.settings.annotationUser = "anonymous"; | |
300 //loadAnnotations(data); | |
301 }); | |
302 }; | |
303 | |
304 /** | |
305 * install additional buttons | |
306 */ | |
307 var installButtons = function(data) { | |
308 var settings = data.settings; | |
309 var mode = settings.interactionMode; | |
310 var buttonSettings = settings.buttonSettings[mode]; | |
311 // configure buttons through digilib "annotationSet" option | |
312 var buttonSet = settings.annotationSet || annotationSet; | |
313 // set annotationSet to [] or '' for no buttons (when showing annotations only) | |
314 if (buttonSet.length && buttonSet.length > 0) { | |
315 buttonSettings.annotationSet = buttonSet; | |
316 buttonSettings.buttonSets.push('annotationSet'); | |
317 } | |
318 }; | |
319 | |
320 /** | |
321 * plugin installation. called by digilib on plugin object. | |
322 */ | |
323 var install = function(plugin) { | |
324 digilib = plugin; | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
325 console.debug('installing annotator plugin. digilib:', digilib); |
1113 | 326 // import geometry classes |
327 geom = digilib.fn.geometry; | |
328 FULL_AREA = geom.rectangle(0, 0, 1, 1); | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
329 // add defaults, actions, buttons |
1113 | 330 $.extend(digilib.defaults, defaults); |
331 $.extend(digilib.actions, actions); | |
332 $.extend(digilib.buttons, buttons); | |
333 }; | |
334 | |
335 /** plugin initialization */ | |
336 var init = function(data) { | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
337 console.debug('initialising annotator plugin. data:', data); |
1113 | 338 var $data = $(data); |
339 // set up | |
340 data.annotations = []; | |
341 if (digilib.plugins.buttons != null) { | |
342 installButtons(data); | |
343 } | |
344 if (data.dlOpts.annotationUser != null) { | |
345 // get annotation user from cookie | |
346 data.settings.annotationUser = data.dlOpts.annotationUser; | |
347 } | |
348 if (data.dlOpts.annotationToken != null) { | |
349 // get annotation token from cookie | |
350 data.annotationToken = data.dlOpts.annotationToken; | |
351 } | |
352 // install event handler | |
353 $data.bind('setup', handleSetup); | |
354 $data.bind('update', handleUpdate); | |
355 }; | |
356 | |
357 /** | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
358 * setup creates Annotator object. |
1113 | 359 */ |
360 var handleSetup = function(evt) { | |
361 console.debug("annotations: handleSetup"); | |
362 var data = this; | |
1118 | 363 /* if (data.annotationToken == null) { |
1113 | 364 loadAnnotationToken(data); |
1118 | 365 } */ |
1113 | 366 // set up annotator (after html has been set up) |
367 var uri = getAnnotationPageUrl(data); | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
368 var annotator = new Annotator(data.$elem.get(0)); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
369 // set plugin parameters |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
370 var pluginParams = { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
371 'Auth' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
372 'token' : data.annotationToken, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
373 'tokenUrl' : data.settings.annotationTokenUrl, |
1119 | 374 'autoFetch' : true, |
375 'requestMethod' : 'POST', | |
376 'requestData' : { | |
377 'user': data.settings.annotationUser, | |
378 'password': data.annotationPassword | |
379 }, | |
380 'unauthorizedCallback' : function (that) { | |
381 window.alert("401"); | |
382 return false; | |
383 } | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
384 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
385 'Permissions' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
386 'user' : data.settings.annotationUser |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
387 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
388 'Store' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
389 'prefix' : data.settings.annotationServerUrl, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
390 'annotationData' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
391 'uri': uri |
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 'loadFromSearch' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
394 'uri': uri |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
395 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
396 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
397 'DigilibIntegrator' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
398 'hooks' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
399 'setupAnnotation' : getSetupAnnotation(data), |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
400 'annotationDeleted' : getAnnotationDeleted(data) |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
401 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
402 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
403 }; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
404 // merge with settings |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
405 $.extend(true, pluginParams, data.settings.annotatorPlugins); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
406 // add plugins |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
407 $.each(pluginParams, function (name, params) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
408 console.debug("plugin:", name, params); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
409 annotator.addPlugin(name, params); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
410 }); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
411 // save annotator reference |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
412 data.annotator = annotator; |
1113 | 413 }; |
414 | |
415 /** | |
416 * update renders all annotations. | |
417 */ | |
418 var handleUpdate = function(evt) { | |
419 console.debug("annotations: handleUpdate"); | |
420 var data = this; | |
421 renderAnnotations(data); | |
422 }; | |
423 | |
424 // plugin object with name and init | |
425 // shared objects filled by digilib on registration | |
426 var plugin = { | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
427 name : 'annotator', |
1113 | 428 install : install, |
429 init : init, | |
430 buttons : {}, | |
431 actions : {}, | |
432 fn : {}, | |
433 plugins : {} | |
434 }; | |
435 | |
436 if ($.fn.digilib == null) { | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
437 $.error("jquery.digilib.annotator must be loaded after jquery.digilib!"); |
1113 | 438 } else { |
439 $.fn.digilib('plugin', plugin); | |
440 } | |
441 })(jQuery); |