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