Mercurial > hg > digilib-old
annotate webapp/src/main/webapp/jquery/jquery.digilib.annotator.js @ 1120:8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
author | robcast |
---|---|
date | Wed, 07 Nov 2012 18:09:57 +0100 |
parents | 036efe7361c8 |
children | efe4b0f18cf8 |
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" | |
32 } | |
33 }; | |
34 | |
35 var defaults = { | |
36 // are annotations active? | |
37 'isAnnotationsVisible' : true, | |
38 // buttonset of this plugin | |
39 'annotationSet' : ['annotations', 'annotationuser', 'annotationmark', 'lessoptions'], | |
40 // URL of annotation server | |
41 'annotationServerUrl' : 'http://virtuoso.mpiwg-berlin.mpg.de:8080/AnnotationManager/annotator', | |
42 // URL of authentication token server | |
43 'annotationTokenUrl' : 'http://localhost:8080/test/annotator/token', | |
44 // annotation user name | |
45 'annotationUser' : 'anonymous', | |
46 // function to translate user name from annotation server format | |
47 'annotationServerUserString' : function() { | |
48 if (this.user && this.user.name) { | |
49 return this.user.name; | |
50 } | |
51 return this.user; | |
52 }, | |
53 | |
1118 | 54 // Annotator plugin settings (some values provided in handleSetup) |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
55 'annotatorPlugins' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
56 //'Tags' : {}, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
57 'Auth' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
58 //token : data.annotationToken |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
59 //tokenUrl: data.settings.annotationTokenUrl |
1118 | 60 autoFetch: true, |
61 requestMethod: 'POST', | |
62 requestData: { | |
63 //'user': data.settings.annotationUser, | |
64 //'password': data.annotationPassword | |
65 } | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
66 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
67 'Permissions' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
68 //user: data.settings.annotationUser, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
69 userString : function(user) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
70 if (user && user.name) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
71 return user.name; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
72 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
73 return user; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
74 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
75 userId: function (user) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
76 if (user && user.id) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
77 return user.id; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
78 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
79 return user; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
80 } |
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 'Store' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
83 //prefix : data.settings.annotationServerUrl, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
84 annotationData: { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
85 //'uri': getAnnotationPageUrl() |
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 loadFromSearch: { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
88 'limit': 20, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
89 //'uri': getAnnotationPageUrl() |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
90 } |
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); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
126 // reload annotations |
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); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
129 annotator.plugins.Store.pluginInit(); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
130 }); |
1113 | 131 }, |
132 | |
133 /** | |
134 * set a mark-annotation by clicking (or giving a position and a text) | |
135 * | |
136 * @param data | |
137 * @param mpos | |
138 * @param text | |
139 */ | |
140 setAnnotationMark : function (data, mpos, text) { | |
141 if (mpos == null) { | |
142 // interactive | |
143 setAnnotationMark(data); | |
144 } else { | |
145 // use position and text (and user-id) | |
1118 | 146 console.error("Currently only interactive annotations!"); |
1113 | 147 } |
148 }, | |
149 }; | |
150 | |
151 /** | |
152 * returns an annotatable url to this digilib image | |
153 */ | |
154 var getAnnotationPageUrl = function(data) { | |
155 var url = data.settings.digilibBaseUrl + '/jquery/digilib.html?'; | |
156 url += digilib.fn.getParamString(data.settings, ['fn', 'pn'], digilib.defaults); | |
157 return url; | |
158 }; | |
159 | |
160 /** | |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
161 * 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
|
162 * auth is Auth plugin instance. |
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 var setAnnotationUser = function (data, auth, user, password) { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
165 if (user == null) { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
166 // user name entered in JS-prompt |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
167 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
|
168 if (user != null && user != 'anonymous') { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
169 // password entered in JS-prompt |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
170 password = window.prompt("Please authenticate: Password", ''); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
171 // set params for Auth plugin |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
172 auth.options.requestData.password = password; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
173 } else { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
174 // use anonymous user |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
175 user = 'anonymous'; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
176 delete auth.options.requestData.password; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
177 } |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
178 } |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
179 // set user in digilib |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
180 data.settings.annotationUser = user; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
181 data.dlOpts.annotationUser = user; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
182 digilib.fn.storeOptions(data); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
183 // set params for Auth plugin |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
184 auth.options.requestData.user = user; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
185 // set params for Permissions plugin |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
186 var perms = data.annotator.plugins.Permissions; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
187 if (perms != null) { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
188 perms.options.user = user; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
189 } |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
190 }; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
191 |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
192 |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
193 /** |
1113 | 194 * add a mark-annotation where clicked. |
195 */ | |
196 var setAnnotationMark = function(data) { | |
197 var $scaler = data.$scaler; | |
198 // unbind other handler TODO: do we need to do this? | |
199 $scaler.off(".dlZoomDrag"); | |
200 // start event capturing | |
201 $scaler.one('mousedown.dlSetAnnotationMark', function(evt) { | |
202 // event handler adding a new mark | |
203 console.log("setAnnotationMark at=", evt); | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
204 var annotator = data.annotator; |
1113 | 205 var mpos = geom.position(evt); |
206 var pos = data.imgTrafo.invtransform(mpos); | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
207 // mark selected areas |
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
208 annotator.selectedAreas = [geom.rectangle(pos)]; |
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
209 // create and edit new annotation |
1113 | 210 var annotation = annotator.createAnnotation(); |
211 annotator.showEditor(annotation, mpos.getAsCss()); | |
212 return false; | |
213 }); | |
214 }; | |
215 | |
216 /** | |
217 * place annotations on the image | |
218 */ | |
1114 | 219 var renderAnnotations = function (data) { |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
220 console.debug("renderAnnotations!"); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
221 if (data.annotations == null || data.annotator == null || data.$img == null || data.imgTrafo == null) |
1113 | 222 return; |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
223 var annotations = data.annotations; |
1113 | 224 var cssPrefix = data.settings.cssPrefix; |
225 var $elem = data.$elem; | |
226 // try to show annotation user state | |
227 $elem.find('div#'+cssPrefix+'button-annotationuser').attr('title', 'annotation user: '+data.settings.annotationUser); | |
228 // clear annotations | |
229 $elem.find('div.' + cssPrefix + 'annotationmark').remove(); | |
230 if (!data.settings.isAnnotationsVisible) return; | |
231 for (var i = 0; i < annotations.length; i++) { | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
232 renderAnnotation(data, annotations[i]); |
1113 | 233 } |
234 }; | |
235 | |
236 /** | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
237 * place single annotation on the image |
1113 | 238 */ |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
239 var renderAnnotation = function (data, annot) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
240 console.debug("renderAnnotation: annotation=", annot); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
241 if (annot == null || annot.annotation == null || annot.annotation.areas == null |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
242 || data.$img == null || data.imgTrafo == null) |
1113 | 243 return; |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
244 if (!data.settings.isAnnotationsVisible) return; |
1113 | 245 var cssPrefix = data.settings.cssPrefix; |
246 var $elem = data.$elem; | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
247 var annotator = data.annotator; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
248 var annotation = annot.annotation; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
249 var idx = annot.idx ? annot.idx : '?'; |
1113 | 250 var pos = geom.position(annotation.areas[0]); |
251 if (data.zoomArea.containsPosition(pos)) { | |
252 var mpos = data.imgTrafo.transform(pos); | |
253 console.debug("renderannotations: pos=", mpos); | |
254 // create annotation | |
1114 | 255 var html = '<div class="'+cssPrefix+'annotationmark '+cssPrefix+'overlay annotator-hl">'+idx+'</div>'; |
1113 | 256 var $annotation = $(html); |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
257 // save annotation in data for Annotator |
1114 | 258 $annotation.data('annotation', annotation); |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
259 // save reference to div |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
260 annot.$div = $annotation; |
1113 | 261 $elem.append($annotation); |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
262 // hook up Annotator events |
1114 | 263 $annotation.on("mouseover", annotator.onHighlightMouseover); |
264 $annotation.on("mouseout", annotator.startViewerHideTimer); | |
1113 | 265 mpos.adjustDiv($annotation); |
266 } | |
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 /** |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
310 * returns handleUnauthorized function for Annotator.Auth plugin. |
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 |
1113 | 321 /** |
322 * install additional buttons | |
323 */ | |
324 var installButtons = function(data) { | |
325 var settings = data.settings; | |
326 var mode = settings.interactionMode; | |
327 var buttonSettings = settings.buttonSettings[mode]; | |
328 // configure buttons through digilib "annotationSet" option | |
329 var buttonSet = settings.annotationSet || annotationSet; | |
330 // set annotationSet to [] or '' for no buttons (when showing annotations only) | |
331 if (buttonSet.length && buttonSet.length > 0) { | |
332 buttonSettings.annotationSet = buttonSet; | |
333 buttonSettings.buttonSets.push('annotationSet'); | |
334 } | |
335 }; | |
336 | |
337 /** | |
338 * plugin installation. called by digilib on plugin object. | |
339 */ | |
340 var install = function(plugin) { | |
341 digilib = plugin; | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
342 console.debug('installing annotator plugin. digilib:', digilib); |
1113 | 343 // import geometry classes |
344 geom = digilib.fn.geometry; | |
345 FULL_AREA = geom.rectangle(0, 0, 1, 1); | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
346 // add defaults, actions, buttons |
1113 | 347 $.extend(digilib.defaults, defaults); |
348 $.extend(digilib.actions, actions); | |
349 $.extend(digilib.buttons, buttons); | |
350 }; | |
351 | |
352 /** plugin initialization */ | |
353 var init = function(data) { | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
354 console.debug('initialising annotator plugin. data:', data); |
1113 | 355 var $data = $(data); |
356 // set up | |
357 data.annotations = []; | |
358 if (digilib.plugins.buttons != null) { | |
359 installButtons(data); | |
360 } | |
361 if (data.dlOpts.annotationUser != null) { | |
362 // get annotation user from cookie | |
363 data.settings.annotationUser = data.dlOpts.annotationUser; | |
364 } | |
365 // install event handler | |
366 $data.bind('setup', handleSetup); | |
367 $data.bind('update', handleUpdate); | |
368 }; | |
369 | |
370 /** | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
371 * setup creates Annotator object. |
1113 | 372 */ |
373 var handleSetup = function(evt) { | |
374 console.debug("annotations: handleSetup"); | |
375 var data = this; | |
376 // set up annotator (after html has been set up) | |
377 var uri = getAnnotationPageUrl(data); | |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
378 var annotator = new Annotator(data.$elem.get(0)); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
379 // set plugin parameters |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
380 var pluginParams = { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
381 'Auth' : { |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
382 'token' : data.dlOpts.annotationToken, |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
383 'tokenUrl' : data.settings.annotationTokenUrl, |
1119 | 384 'autoFetch' : true, |
385 'requestMethod' : 'POST', | |
386 'requestData' : { | |
387 'user': data.settings.annotationUser, | |
388 }, | |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
389 'unauthorizedCallback' : getHandleUnauthorized(data) |
1116
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
390 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
391 'Permissions' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
392 'user' : data.settings.annotationUser |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
393 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
394 'Store' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
395 'prefix' : data.settings.annotationServerUrl, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
396 'annotationData' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
397 'uri': uri |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
398 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
399 'loadFromSearch' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
400 'uri': uri |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
401 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
402 }, |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
403 'DigilibIntegrator' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
404 'hooks' : { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
405 'setupAnnotation' : getSetupAnnotation(data), |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
406 'annotationDeleted' : getAnnotationDeleted(data) |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
407 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
408 } |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
409 }; |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
410 // merge with settings |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
411 $.extend(true, pluginParams, data.settings.annotatorPlugins); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
412 // add plugins |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
413 $.each(pluginParams, function (name, params) { |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
414 console.debug("plugin:", name, params); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
415 annotator.addPlugin(name, params); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
416 }); |
08206603c7dc
annotations use new Annotator-digilibintegration plugin.
robcast
parents:
1115
diff
changeset
|
417 // save annotator reference |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
418 data.annotator = annotator; |
1120
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
419 // save annotation token in cookie |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
420 var auth = annotator.plugins.Auth; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
421 // save new token in cookie |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
422 auth.withToken(function (tkn) { |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
423 data.dlOpts.annotationToken = auth.token; |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
424 digilib.fn.storeOptions(data); |
8bd10cd04169
authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents:
1119
diff
changeset
|
425 }); |
1113 | 426 }; |
427 | |
428 /** | |
429 * update renders all annotations. | |
430 */ | |
431 var handleUpdate = function(evt) { | |
432 console.debug("annotations: handleUpdate"); | |
433 var data = this; | |
434 renderAnnotations(data); | |
435 }; | |
436 | |
437 // plugin object with name and init | |
438 // shared objects filled by digilib on registration | |
439 var plugin = { | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
440 name : 'annotator', |
1113 | 441 install : install, |
442 init : init, | |
443 buttons : {}, | |
444 actions : {}, | |
445 fn : {}, | |
446 plugins : {} | |
447 }; | |
448 | |
449 if ($.fn.digilib == null) { | |
1115
526dafa4690d
using annotator in digilib works now. code still ugly.
robcast
parents:
1114
diff
changeset
|
450 $.error("jquery.digilib.annotator must be loaded after jquery.digilib!"); |
1113 | 451 } else { |
452 $.fn.digilib('plugin', plugin); | |
453 } | |
454 })(jQuery); |