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