Mercurial > hg > digilib-old
comparison webapp/src/main/webapp/jquery/jquery.digilib.annotator.js @ 1126:f14220f939d5
add annotationsReadOnly mode.
author | robcast |
---|---|
date | Fri, 09 Nov 2012 18:53:13 +0100 |
parents | f1be20adc98b |
children | 9e85efcfbb0c |
comparison
equal
deleted
inserted
replaced
1125:f1be20adc98b | 1126:f14220f939d5 |
---|---|
40 var defaults = { | 40 var defaults = { |
41 // are annotations active? | 41 // are annotations active? |
42 'isAnnotationsVisible' : true, | 42 'isAnnotationsVisible' : true, |
43 // buttonset of this plugin | 43 // buttonset of this plugin |
44 'annotationSet' : ['annotations', 'annotationuser', 'annotationmark', 'annotationregion', 'lessoptions'], | 44 'annotationSet' : ['annotations', 'annotationuser', 'annotationmark', 'annotationregion', 'lessoptions'], |
45 // URL of annotation server | 45 'annotationReadOnlySet' : ['annotations', 'lessoptions'], |
46 'annotationServerUrl' : 'http://virtuoso.mpiwg-berlin.mpg.de:8080/AnnotationManager/annotator', | 46 // URL of annotation server .e.g. 'http://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager/annotator' |
47 // URL of authentication token server | 47 'annotationServerUrl' : null, |
48 'annotationTokenUrl' : 'http://localhost:8080/test/annotator/token', | 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, | |
49 // annotation user name | 52 // annotation user name |
50 'annotationUser' : 'anonymous', | 53 '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 | |
59 // list of Annotator plugins | 54 // list of Annotator plugins |
60 'annotatorPlugins' : ['Auth', 'Permissions', 'Store', 'DigilibIntegrator'], | 55 'annotatorPlugins' : ['Auth', 'Permissions', 'Store', 'DigilibIntegrator'], |
61 // Annotator plugin settings (some values provided in handleSetup) | 56 // Annotator plugin settings (some values provided in handleSetup) |
62 'annotatorPluginSettings' : { | 57 'annotatorPluginSettings' : { |
63 'Auth' : { | 58 'Auth' : { |
94 'limit': 20, | 89 'limit': 20, |
95 //'uri': getAnnotationPageUrl() | 90 //'uri': getAnnotationPageUrl() |
96 } | 91 } |
97 } | 92 } |
98 } | 93 } |
99 | |
100 }; | 94 }; |
101 | 95 |
102 var actions = { | 96 var actions = { |
103 /** | 97 /** |
104 * show/hide annotations | 98 * show/hide annotations |
127 auth.requestToken(); | 121 auth.requestToken(); |
128 // save new token in cookie | 122 // save new token in cookie |
129 auth.withToken(function (tkn) { | 123 auth.withToken(function (tkn) { |
130 data.dlOpts.annotationToken = auth.token; | 124 data.dlOpts.annotationToken = auth.token; |
131 digilib.fn.storeOptions(data); | 125 digilib.fn.storeOptions(data); |
132 // reload annotations | 126 // clear annotations |
133 data.annotations = []; | 127 data.annotations = []; |
134 renderAnnotations(data); | 128 renderAnnotations(data); |
129 // reload annotations | |
135 annotator.plugins.Store.pluginInit(); | 130 annotator.plugins.Store.pluginInit(); |
136 }); | 131 }); |
137 }, | 132 }, |
138 | 133 |
139 /** | 134 /** |
155 | 150 |
156 /** | 151 /** |
157 * set a region-annotation by clicking (or giving a position and a text) | 152 * set a region-annotation by clicking (or giving a position and a text) |
158 * | 153 * |
159 * @param data | 154 * @param data |
160 * @param mpos | 155 * @param rect |
161 * @param text | 156 * @param text |
162 */ | 157 */ |
163 setAnnotationRegion : function (data, rect, text) { | 158 setAnnotationRegion : function (data, rect, text) { |
164 if (rect == null) { | 159 if (rect == null) { |
165 // interactive | 160 // interactive |
216 /** | 211 /** |
217 * add a mark-annotation where clicked. | 212 * add a mark-annotation where clicked. |
218 */ | 213 */ |
219 var setAnnotationMark = function(data) { | 214 var setAnnotationMark = function(data) { |
220 var $scaler = data.$scaler; | 215 var $scaler = data.$scaler; |
221 // unbind other handler TODO: do we need to do this? | |
222 $scaler.off(".dlZoomDrag"); | |
223 // start event capturing | 216 // start event capturing |
224 $scaler.one('mousedown.dlSetAnnotationMark', function(evt) { | 217 $scaler.one('mousedown.dlSetAnnotationMark', function(evt) { |
225 // event handler adding a new mark | 218 // event handler adding a new mark |
226 console.log("setAnnotationMark at=", evt); | 219 console.log("setAnnotationMark at=", evt); |
227 var annotator = data.annotator; | 220 var annotator = data.annotator; |
246 // event handler adding a new mark | 239 // event handler adding a new mark |
247 console.log("setAnnotationRegion at=", rect); | 240 console.log("setAnnotationRegion at=", rect); |
248 // mark selected areas | 241 // mark selected areas |
249 annotator.selectedAreas = [rect]; | 242 annotator.selectedAreas = [rect]; |
250 // create and edit new annotation | 243 // create and edit new annotation |
251 var mpos = rect.getPt1(); | 244 var pos = rect.getPt1(); |
252 var pos = data.imgTrafo.transform(mpos); | 245 var mpos = data.imgTrafo.transform(pos); |
253 var annotation = annotator.createAnnotation(); | 246 var annotation = annotator.createAnnotation(); |
254 annotator.showEditor(annotation, pos.getAsCss()); | 247 annotator.showEditor(annotation, mpos.getAsCss()); |
255 }); | 248 }); |
256 }; | 249 }; |
257 | 250 |
258 /** | 251 /** |
259 * place annotations on the image | 252 * place annotations on the image |
260 */ | 253 */ |
261 var renderAnnotations = function (data) { | 254 var renderAnnotations = function (data) { |
262 console.debug("renderAnnotations!"); | |
263 if (data.annotations == null || data.annotator == null || data.$img == null || data.imgTrafo == null) | 255 if (data.annotations == null || data.annotator == null || data.$img == null || data.imgTrafo == null) |
264 return; | 256 return; |
265 var annotations = data.annotations; | 257 var annotations = data.annotations; |
266 var cssPrefix = data.settings.cssPrefix; | 258 var cssPrefix = data.settings.cssPrefix; |
267 var $elem = data.$elem; | 259 var $elem = data.$elem; |
268 // try to show annotation user state | 260 // show annotation user state |
269 $elem.find('div#'+cssPrefix+'button-annotationuser').attr('title', 'annotation user: '+data.settings.annotationUser); | 261 $elem.find('div#'+cssPrefix+'button-annotationuser').attr('title', 'annotation user: '+data.settings.annotationUser); |
270 // clear annotations | 262 // clear annotations |
271 $elem.find('div.' + cssPrefix + 'annotationmark').remove(); | 263 $elem.find('div.'+cssPrefix+'annotationmark,div.'+cssPrefix+'annotationregion').remove(); |
272 if (!data.settings.isAnnotationsVisible) return; | 264 if (!data.settings.isAnnotationsVisible) return; |
265 // re-render | |
273 for (var i = 0; i < annotations.length; i++) { | 266 for (var i = 0; i < annotations.length; i++) { |
274 renderAnnotation(data, annotations[i]); | 267 renderAnnotation(data, annotations[i]); |
275 } | 268 } |
276 }; | 269 }; |
277 | 270 |
278 /** | 271 /** |
279 * place single annotation on the image | 272 * place single annotation on the image |
280 */ | 273 */ |
281 var renderAnnotation = function (data, annot) { | 274 var renderAnnotation = function (data, annot) { |
282 console.debug("renderAnnotation: annotation=", annot); | |
283 if (annot == null || annot.annotation == null || annot.annotation.areas == null | 275 if (annot == null || annot.annotation == null || annot.annotation.areas == null |
284 || data.$img == null || data.imgTrafo == null) | 276 || data.$img == null || data.imgTrafo == null) |
285 return; | 277 return; |
286 if (!data.settings.isAnnotationsVisible) return; | 278 if (!data.settings.isAnnotationsVisible) return; |
287 var cssPrefix = data.settings.cssPrefix; | 279 var cssPrefix = data.settings.cssPrefix; |
301 //addRegionAttributes(data, $regionDiv, attr); | 293 //addRegionAttributes(data, $regionDiv, attr); |
302 } else { | 294 } else { |
303 var pos = area.getPosition(); | 295 var pos = area.getPosition(); |
304 if (!data.zoomArea.containsPosition(pos)) return; | 296 if (!data.zoomArea.containsPosition(pos)) return; |
305 var screenRect = data.imgTrafo.transform(pos); | 297 var screenRect = data.imgTrafo.transform(pos); |
306 console.debug("renderannotations: pos=", pos); | |
307 // create annotation | 298 // create annotation |
308 var html = '<div class="'+cssPrefix+'annotationmark '+cssPrefix+'overlay annotator-hl">'+idx+'</div>'; | 299 var html = '<div class="'+cssPrefix+'annotationmark '+cssPrefix+'overlay annotator-hl">'+idx+'</div>'; |
309 $annotation = $(html); | 300 $annotation = $(html); |
310 } | 301 } |
311 // save annotation in data for Annotator | 302 // save annotation in data for Annotator |
372 }; | 363 }; |
373 | 364 |
374 /** | 365 /** |
375 * install additional buttons | 366 * install additional buttons |
376 */ | 367 */ |
377 var installButtons = function(data) { | 368 var installButtons = function(data, buttonSet) { |
378 var settings = data.settings; | 369 var settings = data.settings; |
379 var mode = settings.interactionMode; | 370 var mode = settings.interactionMode; |
380 var buttonSettings = settings.buttonSettings[mode]; | 371 var buttonSettings = settings.buttonSettings[mode]; |
381 // configure buttons through digilib "annotationSet" option | |
382 var buttonSet = settings.annotationSet || annotationSet; | |
383 // set annotationSet to [] or '' for no buttons (when showing annotations only) | 372 // set annotationSet to [] or '' for no buttons (when showing annotations only) |
384 if (buttonSet.length && buttonSet.length > 0) { | 373 if (buttonSet.length && buttonSet.length > 0) { |
385 buttonSettings.annotationSet = buttonSet; | 374 buttonSettings.annotationSet = buttonSet; |
386 buttonSettings.buttonSets.push('annotationSet'); | 375 buttonSettings.buttonSets.push('annotationSet'); |
387 } | 376 } |
393 var install = function(plugin) { | 382 var install = function(plugin) { |
394 digilib = plugin; | 383 digilib = plugin; |
395 console.debug('installing annotator plugin. digilib:', digilib); | 384 console.debug('installing annotator plugin. digilib:', digilib); |
396 // import geometry classes | 385 // import geometry classes |
397 geom = digilib.fn.geometry; | 386 geom = digilib.fn.geometry; |
398 FULL_AREA = geom.rectangle(0, 0, 1, 1); | |
399 // add defaults, actions, buttons | 387 // add defaults, actions, buttons |
400 $.extend(digilib.defaults, defaults); | 388 $.extend(digilib.defaults, defaults); |
401 $.extend(digilib.actions, actions); | 389 $.extend(digilib.actions, actions); |
402 $.extend(digilib.buttons, buttons); | 390 $.extend(digilib.buttons, buttons); |
403 }; | 391 }; |
404 | 392 |
405 /** plugin initialization */ | 393 /** plugin initialization */ |
406 var init = function(data) { | 394 var init = function(data) { |
407 console.debug('initialising annotator plugin. data:', data); | 395 console.debug('initialising annotator plugin. data:', data); |
408 var $data = $(data); | 396 var $data = $(data); |
409 // set up | 397 var settings = data.settings; |
398 // set up list of annotation wrappers | |
410 data.annotations = []; | 399 data.annotations = []; |
400 // set up buttons | |
411 if (digilib.plugins.buttons != null) { | 401 if (digilib.plugins.buttons != null) { |
412 installButtons(data); | 402 if (settings.annotationsReadOnly) { |
403 installButtons(data, settings.annotationReadOnlySet); | |
404 } else { | |
405 installButtons(data, settings.annotationSet); | |
406 } | |
413 } | 407 } |
414 if (data.dlOpts.annotationUser != null) { | 408 if (data.dlOpts.annotationUser != null) { |
415 // get annotation user from cookie | 409 // get annotation user from cookie |
416 data.settings.annotationUser = data.dlOpts.annotationUser; | 410 settings.annotationUser = data.dlOpts.annotationUser; |
417 } | 411 } |
418 // install event handler | 412 // install event handler |
419 $data.bind('setup', handleSetup); | 413 $data.bind('setup', handleSetup); |
420 $data.bind('update', handleUpdate); | 414 $data.bind('update', handleUpdate); |
421 }; | 415 }; |
422 | 416 |
423 /** | 417 /** |
424 * setup creates Annotator object. | 418 * setup creates Annotator object (after HTML setup by digilib). |
425 */ | 419 */ |
426 var handleSetup = function(evt) { | 420 var handleSetup = function(evt) { |
427 console.debug("annotations: handleSetup"); | 421 console.debug("annotations: handleSetup"); |
428 var data = this; | 422 var data = this; |
429 var settings = data.settings; | 423 var settings = data.settings; |
430 // set up annotator (after html has been set up) | 424 // set up annotator (after html has been set up) |
431 var uri = getAnnotationPageUrl(data); | 425 var uri = getAnnotationPageUrl(data); |
432 var annotator = new Annotator(data.$elem.get(0)); | 426 var elem = data.$elem.get(0); |
427 var opts = {'readOnly' : data.settings.annotationsReadOnly}; | |
428 var annotator = new Annotator(elem, opts); | |
433 // set plugin parameters | 429 // set plugin parameters |
434 var pluginParams = { | 430 var pluginParams = { |
435 'Auth' : { | 431 'Auth' : { |
436 'token' : data.dlOpts.annotationToken, | 432 'token' : data.dlOpts.annotationToken, |
437 'tokenUrl' : settings.annotationTokenUrl, | 433 'tokenUrl' : settings.annotationTokenUrl, |
471 }); | 467 }); |
472 // save annotator reference | 468 // save annotator reference |
473 data.annotator = annotator; | 469 data.annotator = annotator; |
474 // save annotation token in cookie | 470 // save annotation token in cookie |
475 var auth = annotator.plugins.Auth; | 471 var auth = annotator.plugins.Auth; |
476 // save new token in cookie | 472 if (auth != null) { |
477 auth.withToken(function (tkn) { | 473 auth.withToken(function (tkn) { |
478 data.dlOpts.annotationToken = auth.token; | 474 data.dlOpts.annotationToken = auth.token; |
479 digilib.fn.storeOptions(data); | 475 digilib.fn.storeOptions(data); |
480 }); | 476 }); |
477 } | |
481 }; | 478 }; |
482 | 479 |
483 /** | 480 /** |
484 * update renders all annotations. | 481 * update renders all annotations. |
485 */ | 482 */ |