Mercurial > hg > digilib-old
annotate webapp/src/main/webapp/jquery/jquery.digilib.annotator.js @ 1153:dcf55ac4ed4e
add autozoom on click (from regions plugin)
author | hertzhaft |
---|---|
date | Tue, 27 Nov 2012 14:42:18 +0100 |
parents | 13be1a009bbc |
children | 3cfeec734282 |
rev | line source |
---|---|
1113 | 1 /** |
2 digilib plugin for annotations. | |
3 | |
1142 | 4 Currently supported are point annotations (like marks) and region annotations. |
1113 | 5 |
1142 | 6 Annotations are displayed using code from the Annotator (http://annotateit.org) project |
7 and stored on a Annotator-API compatible server. | |
1113 | 8 |
9 */ | |
10 | |
11 (function($) { | |
12 | |
13 // affine geometry | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
14 var geom = null; |
1113 | 15 // plugin object with digilib data |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
16 var digilib = null; |
1153 | 17 // the functions made available by digilib |
18 var fn = {}; | |
19 // the normal zoom area | |
20 var FULL_AREA = null; | |
1113 | 21 |
22 var buttons = { | |
23 annotations : { | |
24 onclick : "toggleAnnotations", | |
25 tooltip : "show or hide annotations", | |
26 icon : "annotations.png" | |
27 }, | |
28 annotationuser : { | |
29 onclick : "setAnnotationUser", | |
30 tooltip : "set user account for annotations", | |
31 icon : "annotation-user.png" | |
32 }, | |
33 annotationmark : { | |
34 onclick : "setAnnotationMark", | |
35 tooltip : "create an annotation for a point", | |
36 icon : "annotation-mark.png" | |
1121 | 37 }, |
38 annotationregion : { | |
39 onclick : "setAnnotationRegion", | |
40 tooltip : "create an annotation for a region", | |
41 icon : "annotation-region.png" | |
1113 | 42 } |
43 }; | |
44 | |
1140
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
45 // for defaults see below (we need to define the functions used in annotatorPluginSettings first) |
1113 | 46 |
47 var actions = { | |
48 /** | |
49 * show/hide annotations | |
50 */ | |
51 toggleAnnotations : function (data) { | |
52 var show = !data.settings.isAnnotationsVisible; | |
53 data.settings.isAnnotationsVisible = show; | |
1153 | 54 fn.highlightButtons(data, 'annotations', show); |
1113 | 55 renderAnnotations(data); |
56 }, | |
1152 | 57 |
1113 | 58 /** |
59 * set user account for annotations | |
60 */ | |
61 setAnnotationUser : function (data, user, password) { | |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
62 var annotator = data.annotator; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
63 var auth = annotator.plugins.Auth; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
64 if (auth == null) { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
65 console.error("setAnnotationUser: No Auth plugin!!"); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
66 return; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
67 } |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
68 setAnnotationUser(data, auth, user, password); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
69 // get new token |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
70 auth.token = null; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
71 auth._unsafeToken = null; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
72 auth.requestToken(); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
73 // save new token in cookie |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
74 auth.withToken(function (tkn) { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
75 data.dlOpts.annotationToken = auth.token; |
1153 | 76 fn.storeOptions(data); |
1126 | 77 // clear annotations |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
78 data.annotations = []; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
79 renderAnnotations(data); |
1126 | 80 // reload annotations |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
81 annotator.plugins.Store.pluginInit(); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
82 }); |
1113 | 83 }, |
84 | |
85 /** | |
86 * set a mark-annotation by clicking (or giving a position and a text) | |
87 * | |
88 * @param data | |
89 * @param mpos | |
90 * @param text | |
91 */ | |
92 setAnnotationMark : function (data, mpos, text) { | |
93 if (mpos == null) { | |
94 // interactive | |
95 setAnnotationMark(data); | |
96 } else { | |
97 // use position and text (and user-id) | |
1118 | 98 console.error("Currently only interactive annotations!"); |
1113 | 99 } |
100 }, | |
1121 | 101 |
102 /** | |
103 * set a region-annotation by clicking (or giving a position and a text) | |
104 * | |
105 * @param data | |
1126 | 106 * @param rect |
1121 | 107 * @param text |
108 */ | |
109 setAnnotationRegion : function (data, rect, text) { | |
110 if (rect == null) { | |
111 // interactive | |
112 setAnnotationRegion(data); | |
113 } else { | |
114 // use position and text (and user-id) | |
115 console.error("Currently only interactive annotations!"); | |
116 } | |
117 } | |
1113 | 118 }; |
119 | |
120 /** | |
1142 | 121 * returns an annotatable uri to this digilib image |
1113 | 122 */ |
1142 | 123 var getAnnotationPageUri = function(data) { |
124 var settings = data.settings; | |
125 var uri = settings.annotationPageUri; | |
126 if (uri == null) { | |
127 // default uri with digilibBaseUrl | |
128 uri = settings.digilibBaseUrl + settings.digilibFrontendPath; | |
1153 | 129 uri += '?' + fn.getParamString(data.settings, ['fn', 'pn'], digilib.defaults); |
1142 | 130 } else if (typeof uri === 'function') { |
131 // call function | |
132 uri = uri(data); | |
133 } | |
134 return uri; | |
1113 | 135 }; |
1153 | 136 |
1113 | 137 /** |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
138 * 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
|
139 * auth is Auth plugin instance. |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
140 */ |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
141 var setAnnotationUser = function (data, auth, user, password) { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
142 if (user == null) { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
143 // user name entered in JS-prompt |
1133 | 144 user = window.prompt("Please authenticate (Cancel to log out): User name", data.settings.annotationUser); |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
145 if (user != null && user != 'anonymous') { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
146 // password entered in JS-prompt |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
147 password = window.prompt("Please authenticate: Password", ''); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
148 // set params for Auth plugin |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
149 auth.options.requestData.password = password; |
1132
d47513632da5
additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents:
1129
diff
changeset
|
150 // try to use the safe url for the password |
d47513632da5
additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents:
1129
diff
changeset
|
151 if (data.settings.annotationSafeTokenUrl != null) { |
d47513632da5
additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents:
1129
diff
changeset
|
152 auth.options.tokenUrl = data.settings.annotationSafeTokenUrl; |
d47513632da5
additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents:
1129
diff
changeset
|
153 } else { |
d47513632da5
additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents:
1129
diff
changeset
|
154 console.warn("Sending token password over standard-URL!"); |
d47513632da5
additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents:
1129
diff
changeset
|
155 } |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
156 } else { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
157 // use anonymous user |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
158 user = 'anonymous'; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
159 delete auth.options.requestData.password; |
1132
d47513632da5
additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents:
1129
diff
changeset
|
160 if (data.settings.annotationSafeTokenUrl != null) { |
d47513632da5
additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents:
1129
diff
changeset
|
161 // reset url to unsafe |
d47513632da5
additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents:
1129
diff
changeset
|
162 auth.options.tokenUrl = data.settings.annotationTokenUrl; |
d47513632da5
additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents:
1129
diff
changeset
|
163 } |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
164 } |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
165 } |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
166 // set user in digilib |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
167 data.settings.annotationUser = user; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
168 data.dlOpts.annotationUser = user; |
1153 | 169 fn.storeOptions(data); |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
170 // set params for Auth plugin |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
171 auth.options.requestData.user = user; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
172 // set params for Permissions plugin |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
173 var perms = data.annotator.plugins.Permissions; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
174 if (perms != null) { |
1123
1fad569ccb4f
provide annotator javascript for digilib.annotator plugin.
robcast
parents:
1121
diff
changeset
|
175 perms.setUser(user); |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
176 } |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
177 }; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
178 |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
179 |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
180 /** |
1113 | 181 * add a mark-annotation where clicked. |
182 */ | |
183 var setAnnotationMark = function(data) { | |
184 var $scaler = data.$scaler; | |
185 // start event capturing | |
186 $scaler.one('mousedown.dlSetAnnotationMark', function(evt) { | |
187 // event handler adding a new mark | |
188 console.log("setAnnotationMark at=", evt); | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
189 var annotator = data.annotator; |
1113 | 190 var mpos = geom.position(evt); |
191 var pos = data.imgTrafo.invtransform(mpos); | |
1145 | 192 // mark selection shape |
193 var shape = {'type' : 'point', 'units' : 'fraction', 'geometry' : geom.position(pos)}; | |
194 annotator.selectedShapes = [shape]; | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
195 // create and edit new annotation |
1113 | 196 var annotation = annotator.createAnnotation(); |
197 annotator.showEditor(annotation, mpos.getAsCss()); | |
1152 | 198 return false; |
1113 | 199 }); |
200 }; | |
201 | |
202 /** | |
1121 | 203 * add a region-annotation where clicked. |
204 */ | |
205 var setAnnotationRegion = function(data) { | |
206 var annotator = data.annotator; | |
1153 | 207 fn.defineArea(data, function (data, rect) { |
1121 | 208 if (rect == null) return; |
209 // event handler adding a new mark | |
210 console.log("setAnnotationRegion at=", rect); | |
1145 | 211 // mark selection shape |
212 var shape = {'type' : 'rectangle', 'units' : 'fraction', 'geometry' : rect}; | |
213 annotator.selectedShapes = [shape]; | |
1121 | 214 // create and edit new annotation |
1126 | 215 var pos = rect.getPt1(); |
216 var mpos = data.imgTrafo.transform(pos); | |
1121 | 217 var annotation = annotator.createAnnotation(); |
1126 | 218 annotator.showEditor(annotation, mpos.getAsCss()); |
1121 | 219 }); |
220 }; | |
221 | |
222 /** | |
1113 | 223 * place annotations on the image |
224 */ | |
1114 | 225 var renderAnnotations = function (data) { |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
226 if (data.annotations == null || data.annotator == null || data.$img == null || data.imgTrafo == null) |
1113 | 227 return; |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
228 var annotations = data.annotations; |
1113 | 229 var cssPrefix = data.settings.cssPrefix; |
230 var $elem = data.$elem; | |
1126 | 231 // show annotation user state |
1113 | 232 $elem.find('div#'+cssPrefix+'button-annotationuser').attr('title', 'annotation user: '+data.settings.annotationUser); |
233 // clear annotations | |
1126 | 234 $elem.find('div.'+cssPrefix+'annotationmark,div.'+cssPrefix+'annotationregion').remove(); |
1113 | 235 if (!data.settings.isAnnotationsVisible) return; |
1126 | 236 // re-render |
1113 | 237 for (var i = 0; i < annotations.length; i++) { |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
238 renderAnnotation(data, annotations[i]); |
1113 | 239 } |
240 }; | |
241 | |
242 /** | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
243 * place single annotation on the image |
1113 | 244 */ |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
245 var renderAnnotation = function (data, annot) { |
1143 | 246 if (annot == null || annot.annotation == null || data.$img == null || data.imgTrafo == null) |
1113 | 247 return; |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
248 if (!data.settings.isAnnotationsVisible) return; |
1113 | 249 var cssPrefix = data.settings.cssPrefix; |
250 var $elem = data.$elem; | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
251 var annotator = data.annotator; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
252 var annotation = annot.annotation; |
1150
d9d17eb3d731
shoAnnotationNumbers controls now also numbers on mark-annotations.
robcast
parents:
1148
diff
changeset
|
253 var idx = ''; |
d9d17eb3d731
shoAnnotationNumbers controls now also numbers on mark-annotations.
robcast
parents:
1148
diff
changeset
|
254 if (data.settings.showAnnotationNumbers) { |
d9d17eb3d731
shoAnnotationNumbers controls now also numbers on mark-annotations.
robcast
parents:
1148
diff
changeset
|
255 // show annotation number |
d9d17eb3d731
shoAnnotationNumbers controls now also numbers on mark-annotations.
robcast
parents:
1148
diff
changeset
|
256 idx = annot.idx ? annot.idx : '?'; |
d9d17eb3d731
shoAnnotationNumbers controls now also numbers on mark-annotations.
robcast
parents:
1148
diff
changeset
|
257 } |
1152 | 258 var shape = null; |
1143 | 259 var area = null; |
260 var type = null; | |
261 if (annotation.shapes != null) { | |
262 // annotation shape | |
1152 | 263 shape = annotation.shapes[0]; |
1143 | 264 type = shape.type; |
265 if (type === "point") { | |
266 area = geom.position(shape.geometry); | |
267 } else if (type === "rectangle") { | |
268 area = geom.rectangle(shape.geometry); | |
269 } else { | |
270 console.error("Unsupported shape type="+type); | |
271 return; | |
272 } | |
273 } else if (annotation.areas != null) { | |
274 // legacy annotation areas | |
1152 | 275 shape = annotation.areas[0] |
276 area = geom.rectangle(shape); | |
1143 | 277 if (area.isRectangle()) { |
278 type = 'rectangle'; | |
279 } else { | |
280 type = 'point'; | |
281 } | |
282 } else { | |
283 console.error("Unable to render this annotation!"); | |
284 return; | |
285 } | |
1121 | 286 var screenRect = null; |
287 var $annotation = null; | |
1143 | 288 if (type === 'rectangle') { |
289 // render rectangle | |
1121 | 290 var clippedArea = data.zoomArea.intersect(area); |
291 if (clippedArea == null) return; | |
292 screenRect = data.imgTrafo.transform(clippedArea); | |
293 $annotation = $('<div class="'+cssPrefix+'annotationregion '+cssPrefix+'overlay annotator-hl">'+idx+'</div>'); | |
294 } else { | |
1143 | 295 // render point |
1145 | 296 if (!data.zoomArea.containsPosition(area)) return; |
297 var screenRect = data.imgTrafo.transform(area); | |
1113 | 298 // create annotation |
1114 | 299 var html = '<div class="'+cssPrefix+'annotationmark '+cssPrefix+'overlay annotator-hl">'+idx+'</div>'; |
1121 | 300 $annotation = $(html); |
301 } | |
302 // save annotation in data for Annotator | |
303 $annotation.data('annotation', annotation); | |
1153 | 304 $annotation.data('rect', area); |
305 // add shared css class from annotations collection | |
1142 | 306 if (annotation.cssclass != null) { |
307 $annotation.addClass(annotation.cssclass); | |
308 } | |
1153 | 309 // add individual css class from this annotation |
1152 | 310 if (shape.cssclass != null) { |
311 $annotation.addClass(shape.cssclass); | |
312 } | |
1121 | 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); | |
1153 | 319 $annotation.on('click.dlAnnotation', function (event) { |
320 $(data).trigger('annotationClick', [$annotation]); | |
321 }); | |
1121 | 322 screenRect.adjustDiv($annotation); |
1113 | 323 }; |
324 | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
325 /** |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
326 * returns setupAnnotation function using the given data. |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
327 */ |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
328 var getSetupAnnotation = function(data) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
329 return function (annotation) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
330 // create annotation wrapper |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
331 var ann = { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
332 'annotation' : annotation, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
333 'idx' : data.annotations.length+1 |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
334 }; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
335 // add to list |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
336 data.annotations.push(ann); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
337 // render this annotation |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
338 renderAnnotation(data, ann); |
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 }; |
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 /** |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
343 * returns annotationDeleted function using the given data. |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
344 */ |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
345 var getAnnotationDeleted = function(data) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
346 return function (annotation) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
347 // remove annotation mark |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
348 var annots = data.annotations; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
349 for (var i = 0; i < annots.length; ++i) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
350 var annot = annots[i]; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
351 if (annot.annotation === annotation) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
352 // this is the right wrapper |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
353 if (annot.$div != null) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
354 // remove from screen |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
355 annot.$div.remove(); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
356 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
357 // remove from list |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
358 delete annots[i]; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
359 break; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
360 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
361 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
362 }; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
363 }; |
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 /** |
1125
f1be20adc98b
annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents:
1123
diff
changeset
|
366 * 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
|
367 */ |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
368 var getHandleUnauthorized = function (data) { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
369 return function (auth) { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
370 // prompt for user name and set user |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
371 setAnnotationUser(data, auth); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
372 // then try again |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
373 return true; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
374 }; |
1113 | 375 }; |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
376 |
1140
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
377 /** |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
378 * returns the annotation server URL. |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
379 */ |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
380 var getAnnotationServerUrl = function (data) { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
381 return data.settings.annotationServerUrl; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
382 }; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
383 |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
384 /** |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
385 * returns the annotation token URL. |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
386 */ |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
387 var getAnnotationTokenUrl = function (data) { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
388 return data.settings.annotationTokenUrl; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
389 }; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
390 |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
391 /** |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
392 * returns the cached annotation token. |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
393 */ |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
394 var getAnnotationToken = function (data) { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
395 return data.dlOpts.annotationToken; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
396 }; |
1152 | 397 |
1140
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
398 /** |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
399 * returns the annotation user. |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
400 */ |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
401 var getAnnotationUser = function (data) { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
402 return data.settings.annotationUser; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
403 }; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
404 |
1153 | 405 /** |
406 * zoom in, display the annotation in the middle of the screen. | |
407 */ | |
408 // | |
409 var zoomToAnnotation = function (data, $div) { | |
410 var settings = data.settings; | |
411 var rect = $div.data('rect'); | |
412 var za = rect.copy(); | |
413 var w = settings.annotationAutoWidth; | |
414 if (za.width == null || za.width == 0) za.width = w; | |
415 if (za.height == null || za.height == 0) za.height = w; | |
416 var factor = settings.annotationAutoZoomFactor; | |
417 za.width *= factor; | |
418 za.height *= factor; | |
419 za.setProportion(1, true); // avoid extreme zoomArea proportions | |
420 za.setCenter(rect.getCenter()).stayInside(FULL_AREA); | |
421 fn.setZoomArea(data, za); | |
422 fn.redisplay(data); | |
423 }; | |
424 | |
425 // event handler, gets called when a annotationClick event is triggered | |
426 var handleAnnotationClick = function (evt, $div) { | |
427 var data = this; | |
428 var settings = data.settings; | |
429 console.debug("annotations: handleAnnotationClick", $div); | |
430 if (typeof settings.annotationOnClick === 'function') { | |
431 // execute callback | |
432 return settings.annotationOnClick(data, $div); | |
433 } | |
434 if (typeof settings.annotationOnClick === 'string') { | |
435 // execute action | |
436 return actions[settings.annotationOnClick](data, $div); | |
437 } | |
438 }; | |
439 | |
1113 | 440 /** |
441 * install additional buttons | |
442 */ | |
1126 | 443 var installButtons = function(data, buttonSet) { |
1113 | 444 var settings = data.settings; |
445 var mode = settings.interactionMode; | |
446 var buttonSettings = settings.buttonSettings[mode]; | |
447 // set annotationSet to [] or '' for no buttons (when showing annotations only) | |
448 if (buttonSet.length && buttonSet.length > 0) { | |
449 buttonSettings.annotationSet = buttonSet; | |
450 buttonSettings.buttonSets.push('annotationSet'); | |
451 } | |
452 }; | |
453 | |
1140
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
454 var defaults = { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
455 // are annotations active? |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
456 'isAnnotationsVisible' : true, |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
457 // buttonset of this plugin |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
458 'annotationSet' : ['annotations', 'annotationuser', 'annotationmark', 'annotationregion', 'lessoptions'], |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
459 'annotationReadOnlySet' : ['annotations', 'lessoptions'], |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
460 // URL of annotation server .e.g. 'http://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager/annotator' |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
461 'annotationServerUrl' : null, |
1148
05413c47a976
new parameter showAnnotationNumbers (for rectangles).
robcast
parents:
1145
diff
changeset
|
462 // show numbers in rectangle annotations |
05413c47a976
new parameter showAnnotationNumbers (for rectangles).
robcast
parents:
1145
diff
changeset
|
463 'showAnnotationNumbers' : true, |
1153 | 464 // default width for annotation when only point is given |
465 'annotationAutoWidth' : 0.005, | |
466 // zoomfactor for displaying larger area around region (for autoZoomOnClick) | |
467 'annotationAutoZoomFactor' : 3, | |
468 // zoom in and center on click on the annotation area | |
469 'annotationOnClick' : zoomToAnnotation, | |
1140
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
470 // are the annotations read-only |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
471 'annotationsReadOnly' : false, |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
472 // URL of authentication token server e.g. 'http://libcoll.mpiwg-berlin.mpg.de/libviewa/template/token' |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
473 'annotationTokenUrl' : null, |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
474 // URL of safe authentication token server e.g. 'https://libcoll.mpiwg-berlin.mpg.de/libviewa/template/token' |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
475 'annotationSafeTokenUrl' : null, |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
476 // annotation user name |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
477 'annotationUser' : 'anonymous', |
1142 | 478 // string or function that returns the uri of the page being annotated |
479 'annotationPageUri' : null, | |
1140
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
480 // list of Annotator plugins |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
481 'annotatorPlugins' : ['Auth', 'Permissions', 'Store', 'DigilibIntegrator'], |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
482 // Annotator plugin settings (values that are functions are replaced by fn(data)) |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
483 'annotatorPluginSettings' : { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
484 'Auth' : { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
485 'token' : getAnnotationToken, |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
486 'tokenUrl' : getAnnotationTokenUrl, |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
487 'autoFetch' : true, |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
488 'requestMethod' : 'POST', |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
489 'requestData' : { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
490 'user': getAnnotationUser |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
491 }, |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
492 'unauthorizedCallback' : getHandleUnauthorized |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
493 }, |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
494 'Permissions' : { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
495 'user' : getAnnotationUser, |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
496 // userString and userId have to remain functions after evaluation |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
497 'userString' : function (data) { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
498 return function(user) { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
499 if (user && user.name) { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
500 return user.name; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
501 } |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
502 return user; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
503 }; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
504 }, |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
505 'userId' : function (data) { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
506 return function(user) { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
507 if (user && user.id) { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
508 return user.id; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
509 } |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
510 return user; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
511 }; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
512 } |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
513 }, |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
514 'Store' : { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
515 'prefix' : getAnnotationServerUrl, |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
516 'annotationData': { |
1142 | 517 'uri': getAnnotationPageUri |
1140
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
518 }, |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
519 'loadFromSearch': { |
1142 | 520 'uri': getAnnotationPageUri |
1140
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
521 } |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
522 }, |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
523 'DigilibIntegrator' : { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
524 'hooks' : { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
525 'setupAnnotation' : getSetupAnnotation, |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
526 'annotationDeleted' : getAnnotationDeleted |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
527 } |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
528 } |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
529 |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
530 } |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
531 }; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
532 |
1113 | 533 /** |
534 * plugin installation. called by digilib on plugin object. | |
535 */ | |
536 var install = function(plugin) { | |
537 digilib = plugin; | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
538 console.debug('installing annotator plugin. digilib:', digilib); |
1153 | 539 // import digilib functions |
540 $.extend(fn, digilib.fn); | |
1113 | 541 // import geometry classes |
1153 | 542 geom = fn.geometry; |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
543 // add defaults, actions, buttons |
1113 | 544 $.extend(digilib.defaults, defaults); |
545 $.extend(digilib.actions, actions); | |
546 $.extend(digilib.buttons, buttons); | |
547 }; | |
548 | |
549 /** plugin initialization */ | |
550 var init = function(data) { | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
551 console.debug('initialising annotator plugin. data:', data); |
1113 | 552 var $data = $(data); |
1126 | 553 var settings = data.settings; |
1153 | 554 FULL_AREA = geom.rectangle(0, 0, 1, 1); |
1126 | 555 // set up list of annotation wrappers |
1113 | 556 data.annotations = []; |
1126 | 557 // set up buttons |
1113 | 558 if (digilib.plugins.buttons != null) { |
1126 | 559 if (settings.annotationsReadOnly) { |
560 installButtons(data, settings.annotationReadOnlySet); | |
561 } else { | |
562 installButtons(data, settings.annotationSet); | |
563 } | |
1113 | 564 } |
565 if (data.dlOpts.annotationUser != null) { | |
566 // get annotation user from cookie | |
1126 | 567 settings.annotationUser = data.dlOpts.annotationUser; |
1113 | 568 } |
1153 | 569 |
1113 | 570 // install event handler |
571 $data.bind('setup', handleSetup); | |
572 $data.bind('update', handleUpdate); | |
1153 | 573 $data.on('annotationClick', handleAnnotationClick); |
1113 | 574 }; |
575 | |
576 /** | |
1126 | 577 * setup creates Annotator object (after HTML setup by digilib). |
1113 | 578 */ |
579 var handleSetup = function(evt) { | |
580 console.debug("annotations: handleSetup"); | |
581 var data = this; | |
1125
f1be20adc98b
annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents:
1123
diff
changeset
|
582 var settings = data.settings; |
1113 | 583 // set up annotator (after html has been set up) |
1142 | 584 var uri = getAnnotationPageUri(data); |
1126 | 585 var elem = data.$elem.get(0); |
586 var opts = {'readOnly' : data.settings.annotationsReadOnly}; | |
587 var annotator = new Annotator(elem, opts); | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
588 // set plugin parameters |
1140
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
589 var def = defaults.annotatorPluginSettings; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
590 var pluginParams = {}; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
591 // merge settings |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
592 // (deep copy of defaults from plugin and options from HTML) |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
593 $.extend(true, pluginParams, defaults.annotatorPluginSettings, data.options.annotatorPluginSettings); |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
594 // function to evaluate plugin settings |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
595 var evalParams = function (params) { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
596 if (params == null) return; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
597 // eval functions in params |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
598 $.each(params, function (idx, param) { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
599 if (typeof param === 'function') { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
600 // replace function by value |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
601 params[idx] = param(data); |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
602 } else if (param == null) { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
603 // delete value null |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
604 delete params[idx]; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
605 } else if (typeof param === 'object') { |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
606 // evaluate sub-objects |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
607 evalParams(param); |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
608 } |
1140
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
609 }); |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
610 }; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
611 // add plugins |
1125
f1be20adc98b
annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents:
1123
diff
changeset
|
612 $.each(settings.annotatorPlugins, function (idx, name) { |
1140
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
613 var params = pluginParams[name]; |
50d6eaa74b4b
reorganized annotator plugin settings handling... again.
robcast
parents:
1138
diff
changeset
|
614 evalParams(params); |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
615 console.debug("plugin:", name, params); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
616 annotator.addPlugin(name, params); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
617 }); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
618 // save annotator reference |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
619 data.annotator = annotator; |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
620 // save annotation token in cookie |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
621 var auth = annotator.plugins.Auth; |
1126 | 622 if (auth != null) { |
623 auth.withToken(function (tkn) { | |
624 data.dlOpts.annotationToken = auth.token; | |
1153 | 625 fn.storeOptions(data); |
1126 | 626 }); |
627 } | |
1113 | 628 }; |
629 | |
630 /** | |
631 * update renders all annotations. | |
632 */ | |
633 var handleUpdate = function(evt) { | |
634 console.debug("annotations: handleUpdate"); | |
635 var data = this; | |
636 renderAnnotations(data); | |
637 }; | |
638 | |
639 // plugin object with name and init | |
640 // shared objects filled by digilib on registration | |
641 var plugin = { | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
642 name : 'annotator', |
1113 | 643 install : install, |
644 init : init, | |
645 buttons : {}, | |
646 actions : {}, | |
647 fn : {}, | |
648 plugins : {} | |
649 }; | |
650 | |
651 if ($.fn.digilib == null) { | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
652 $.error("jquery.digilib.annotator must be loaded after jquery.digilib!"); |
1113 | 653 } else { |
654 $.fn.digilib('plugin', plugin); | |
655 } | |
656 })(jQuery); |