comparison webapp/src/main/webapp/jquery/jquery.digilib.annotator.js @ 1153:dcf55ac4ed4e

add autozoom on click (from regions plugin)
author hertzhaft
date Tue, 27 Nov 2012 14:42:18 +0100
parents 13be1a009bbc
children 3cfeec734282
comparison
equal deleted inserted replaced
1152:13be1a009bbc 1153:dcf55ac4ed4e
12 12
13 // affine geometry 13 // affine geometry
14 var geom = null; 14 var geom = null;
15 // plugin object with digilib data 15 // plugin object with digilib data
16 var digilib = null; 16 var digilib = null;
17 // the functions made available by digilib
18 var fn = {};
19 // the normal zoom area
20 var FULL_AREA = null;
17 21
18 var buttons = { 22 var buttons = {
19 annotations : { 23 annotations : {
20 onclick : "toggleAnnotations", 24 onclick : "toggleAnnotations",
21 tooltip : "show or hide annotations", 25 tooltip : "show or hide annotations",
45 * show/hide annotations 49 * show/hide annotations
46 */ 50 */
47 toggleAnnotations : function (data) { 51 toggleAnnotations : function (data) {
48 var show = !data.settings.isAnnotationsVisible; 52 var show = !data.settings.isAnnotationsVisible;
49 data.settings.isAnnotationsVisible = show; 53 data.settings.isAnnotationsVisible = show;
50 digilib.fn.highlightButtons(data, 'annotations', show); 54 fn.highlightButtons(data, 'annotations', show);
51 renderAnnotations(data); 55 renderAnnotations(data);
52 }, 56 },
53 57
54 /** 58 /**
55 * set user account for annotations 59 * set user account for annotations
67 auth._unsafeToken = null; 71 auth._unsafeToken = null;
68 auth.requestToken(); 72 auth.requestToken();
69 // save new token in cookie 73 // save new token in cookie
70 auth.withToken(function (tkn) { 74 auth.withToken(function (tkn) {
71 data.dlOpts.annotationToken = auth.token; 75 data.dlOpts.annotationToken = auth.token;
72 digilib.fn.storeOptions(data); 76 fn.storeOptions(data);
73 // clear annotations 77 // clear annotations
74 data.annotations = []; 78 data.annotations = [];
75 renderAnnotations(data); 79 renderAnnotations(data);
76 // reload annotations 80 // reload annotations
77 annotator.plugins.Store.pluginInit(); 81 annotator.plugins.Store.pluginInit();
120 var settings = data.settings; 124 var settings = data.settings;
121 var uri = settings.annotationPageUri; 125 var uri = settings.annotationPageUri;
122 if (uri == null) { 126 if (uri == null) {
123 // default uri with digilibBaseUrl 127 // default uri with digilibBaseUrl
124 uri = settings.digilibBaseUrl + settings.digilibFrontendPath; 128 uri = settings.digilibBaseUrl + settings.digilibFrontendPath;
125 uri += '?' + digilib.fn.getParamString(data.settings, ['fn', 'pn'], digilib.defaults); 129 uri += '?' + fn.getParamString(data.settings, ['fn', 'pn'], digilib.defaults);
126 } else if (typeof uri === 'function') { 130 } else if (typeof uri === 'function') {
127 // call function 131 // call function
128 uri = uri(data); 132 uri = uri(data);
129 } 133 }
130 return uri; 134 return uri;
131 }; 135 };
132 136
133 /** 137 /**
134 * sets annotation user and password in digilib and Annotator.Auth plugin. 138 * sets annotation user and password in digilib and Annotator.Auth plugin.
135 * auth is Auth plugin instance. 139 * auth is Auth plugin instance.
136 */ 140 */
137 var setAnnotationUser = function (data, auth, user, password) { 141 var setAnnotationUser = function (data, auth, user, password) {
160 } 164 }
161 } 165 }
162 // set user in digilib 166 // set user in digilib
163 data.settings.annotationUser = user; 167 data.settings.annotationUser = user;
164 data.dlOpts.annotationUser = user; 168 data.dlOpts.annotationUser = user;
165 digilib.fn.storeOptions(data); 169 fn.storeOptions(data);
166 // set params for Auth plugin 170 // set params for Auth plugin
167 auth.options.requestData.user = user; 171 auth.options.requestData.user = user;
168 // set params for Permissions plugin 172 // set params for Permissions plugin
169 var perms = data.annotator.plugins.Permissions; 173 var perms = data.annotator.plugins.Permissions;
170 if (perms != null) { 174 if (perms != null) {
198 /** 202 /**
199 * add a region-annotation where clicked. 203 * add a region-annotation where clicked.
200 */ 204 */
201 var setAnnotationRegion = function(data) { 205 var setAnnotationRegion = function(data) {
202 var annotator = data.annotator; 206 var annotator = data.annotator;
203 digilib.fn.defineArea(data, function (data, rect) { 207 fn.defineArea(data, function (data, rect) {
204 if (rect == null) return; 208 if (rect == null) return;
205 // event handler adding a new mark 209 // event handler adding a new mark
206 console.log("setAnnotationRegion at=", rect); 210 console.log("setAnnotationRegion at=", rect);
207 // mark selection shape 211 // mark selection shape
208 var shape = {'type' : 'rectangle', 'units' : 'fraction', 'geometry' : rect}; 212 var shape = {'type' : 'rectangle', 'units' : 'fraction', 'geometry' : rect};
295 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>';
296 $annotation = $(html); 300 $annotation = $(html);
297 } 301 }
298 // save annotation in data for Annotator 302 // save annotation in data for Annotator
299 $annotation.data('annotation', annotation); 303 $annotation.data('annotation', annotation);
300 // add css class from annotations collection 304 $annotation.data('rect', area);
305 // add shared css class from annotations collection
301 if (annotation.cssclass != null) { 306 if (annotation.cssclass != null) {
302 $annotation.addClass(annotation.cssclass); 307 $annotation.addClass(annotation.cssclass);
303 } 308 }
304 // add individual css class for this annotation 309 // add individual css class from this annotation
305 if (shape.cssclass != null) { 310 if (shape.cssclass != null) {
306 $annotation.addClass(shape.cssclass); 311 $annotation.addClass(shape.cssclass);
307 } 312 }
308 // save reference to div 313 // save reference to div
309 annot.$div = $annotation; 314 annot.$div = $annotation;
310 $elem.append($annotation); 315 $elem.append($annotation);
311 // hook up Annotator events 316 // hook up Annotator events
312 $annotation.on("mouseover", annotator.onHighlightMouseover); 317 $annotation.on("mouseover", annotator.onHighlightMouseover);
313 $annotation.on("mouseout", annotator.startViewerHideTimer); 318 $annotation.on("mouseout", annotator.startViewerHideTimer);
319 $annotation.on('click.dlAnnotation', function (event) {
320 $(data).trigger('annotationClick', [$annotation]);
321 });
314 screenRect.adjustDiv($annotation); 322 screenRect.adjustDiv($annotation);
315 }; 323 };
316 324
317 /** 325 /**
318 * returns setupAnnotation function using the given data. 326 * returns setupAnnotation function using the given data.
392 */ 400 */
393 var getAnnotationUser = function (data) { 401 var getAnnotationUser = function (data) {
394 return data.settings.annotationUser; 402 return data.settings.annotationUser;
395 }; 403 };
396 404
405 /**
406 * zoom in, display the annotation in the middle of the screen.
407 */
408 //
409 var zoomToAnnotation = function (data, $div) {
410 var settings = data.settings;
411 var rect = $div.data('rect');
412 var za = rect.copy();
413 var w = settings.annotationAutoWidth;
414 if (za.width == null || za.width == 0) za.width = w;
415 if (za.height == null || za.height == 0) za.height = w;
416 var factor = settings.annotationAutoZoomFactor;
417 za.width *= factor;
418 za.height *= factor;
419 za.setProportion(1, true); // avoid extreme zoomArea proportions
420 za.setCenter(rect.getCenter()).stayInside(FULL_AREA);
421 fn.setZoomArea(data, za);
422 fn.redisplay(data);
423 };
424
425 // event handler, gets called when a annotationClick event is triggered
426 var handleAnnotationClick = function (evt, $div) {
427 var data = this;
428 var settings = data.settings;
429 console.debug("annotations: handleAnnotationClick", $div);
430 if (typeof settings.annotationOnClick === 'function') {
431 // execute callback
432 return settings.annotationOnClick(data, $div);
433 }
434 if (typeof settings.annotationOnClick === 'string') {
435 // execute action
436 return actions[settings.annotationOnClick](data, $div);
437 }
438 };
439
397 /** 440 /**
398 * install additional buttons 441 * install additional buttons
399 */ 442 */
400 var installButtons = function(data, buttonSet) { 443 var installButtons = function(data, buttonSet) {
401 var settings = data.settings; 444 var settings = data.settings;
416 'annotationReadOnlySet' : ['annotations', 'lessoptions'], 459 'annotationReadOnlySet' : ['annotations', 'lessoptions'],
417 // URL of annotation server .e.g. 'http://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager/annotator' 460 // URL of annotation server .e.g. 'http://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager/annotator'
418 'annotationServerUrl' : null, 461 'annotationServerUrl' : null,
419 // show numbers in rectangle annotations 462 // show numbers in rectangle annotations
420 'showAnnotationNumbers' : true, 463 'showAnnotationNumbers' : true,
464 // default width for annotation when only point is given
465 'annotationAutoWidth' : 0.005,
466 // zoomfactor for displaying larger area around region (for autoZoomOnClick)
467 'annotationAutoZoomFactor' : 3,
468 // zoom in and center on click on the annotation area
469 'annotationOnClick' : zoomToAnnotation,
421 // are the annotations read-only 470 // are the annotations read-only
422 'annotationsReadOnly' : false, 471 'annotationsReadOnly' : false,
423 // URL of authentication token server e.g. 'http://libcoll.mpiwg-berlin.mpg.de/libviewa/template/token' 472 // URL of authentication token server e.g. 'http://libcoll.mpiwg-berlin.mpg.de/libviewa/template/token'
424 'annotationTokenUrl' : null, 473 'annotationTokenUrl' : null,
425 // URL of safe authentication token server e.g. 'https://libcoll.mpiwg-berlin.mpg.de/libviewa/template/token' 474 // URL of safe authentication token server e.g. 'https://libcoll.mpiwg-berlin.mpg.de/libviewa/template/token'
485 * plugin installation. called by digilib on plugin object. 534 * plugin installation. called by digilib on plugin object.
486 */ 535 */
487 var install = function(plugin) { 536 var install = function(plugin) {
488 digilib = plugin; 537 digilib = plugin;
489 console.debug('installing annotator plugin. digilib:', digilib); 538 console.debug('installing annotator plugin. digilib:', digilib);
539 // import digilib functions
540 $.extend(fn, digilib.fn);
490 // import geometry classes 541 // import geometry classes
491 geom = digilib.fn.geometry; 542 geom = fn.geometry;
492 // add defaults, actions, buttons 543 // add defaults, actions, buttons
493 $.extend(digilib.defaults, defaults); 544 $.extend(digilib.defaults, defaults);
494 $.extend(digilib.actions, actions); 545 $.extend(digilib.actions, actions);
495 $.extend(digilib.buttons, buttons); 546 $.extend(digilib.buttons, buttons);
496 }; 547 };
498 /** plugin initialization */ 549 /** plugin initialization */
499 var init = function(data) { 550 var init = function(data) {
500 console.debug('initialising annotator plugin. data:', data); 551 console.debug('initialising annotator plugin. data:', data);
501 var $data = $(data); 552 var $data = $(data);
502 var settings = data.settings; 553 var settings = data.settings;
554 FULL_AREA = geom.rectangle(0, 0, 1, 1);
503 // set up list of annotation wrappers 555 // set up list of annotation wrappers
504 data.annotations = []; 556 data.annotations = [];
505 // set up buttons 557 // set up buttons
506 if (digilib.plugins.buttons != null) { 558 if (digilib.plugins.buttons != null) {
507 if (settings.annotationsReadOnly) { 559 if (settings.annotationsReadOnly) {
512 } 564 }
513 if (data.dlOpts.annotationUser != null) { 565 if (data.dlOpts.annotationUser != null) {
514 // get annotation user from cookie 566 // get annotation user from cookie
515 settings.annotationUser = data.dlOpts.annotationUser; 567 settings.annotationUser = data.dlOpts.annotationUser;
516 } 568 }
569
517 // install event handler 570 // install event handler
518 $data.bind('setup', handleSetup); 571 $data.bind('setup', handleSetup);
519 $data.bind('update', handleUpdate); 572 $data.bind('update', handleUpdate);
573 $data.on('annotationClick', handleAnnotationClick);
520 }; 574 };
521 575
522 /** 576 /**
523 * setup creates Annotator object (after HTML setup by digilib). 577 * setup creates Annotator object (after HTML setup by digilib).
524 */ 578 */
566 // save annotation token in cookie 620 // save annotation token in cookie
567 var auth = annotator.plugins.Auth; 621 var auth = annotator.plugins.Auth;
568 if (auth != null) { 622 if (auth != null) {
569 auth.withToken(function (tkn) { 623 auth.withToken(function (tkn) {
570 data.dlOpts.annotationToken = auth.token; 624 data.dlOpts.annotationToken = auth.token;
571 digilib.fn.storeOptions(data); 625 fn.storeOptions(data);
572 }); 626 });
573 } 627 }
574 }; 628 };
575 629
576 /** 630 /**