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