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