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