Mercurial > hg > digilib
changeset 1288:e2a95f3f1b9f
fixed annotations remaining when changing pages.
author | robcast |
---|---|
date | Fri, 14 Mar 2014 17:21:12 +0100 |
parents | f4fb3482f116 |
children | 1fbcfc899d4a |
files | webapp/src/main/webapp/jquery/jquery.digilib.annotator.js |
diffstat | 1 files changed, 32 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/webapp/src/main/webapp/jquery/jquery.digilib.annotator.js Fri Mar 14 16:47:58 2014 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.annotator.js Fri Mar 14 17:21:12 2014 +0100 @@ -96,11 +96,8 @@ auth.withToken(function (tkn) { data.dlOpts.annotationToken = auth.token; fn.storeOptions(data); - // clear annotations - data.annotations = []; - renderAnnotations(data); - // reload annotations - annotator.load(data.annotatorLoadQuery); + // reload annotations + reloadAnnotations(data); }); }, @@ -402,7 +399,7 @@ * * @param annotation the annotation object to delete. */ - var deleteAnnotation = function(data, annotation) { + var deleteAnnotation = function (data, annotation) { // remove annotation mark var annots = data.annotations; for (var i = 0; i < annots.length; ++i) { @@ -422,6 +419,18 @@ /** + * Reload annotations for current page. + */ + var reloadAnnotations = function (data) { + // clear annotations + data.annotations = []; + renderAnnotations(data); + // reload annotations + data.annotator.load(data.annotatorLoadQuery); + }; + + + /** * Our modified version of Annotator. */ var DigilibAnnotator = Annotator.extend({ @@ -652,6 +661,7 @@ } // install event handler $data.bind('setup', handleSetup); + $data.bind('redisplay', handleRedisplay); $data.bind('update', handleUpdate); $data.on('annotationClick', handleAnnotationClick); }; @@ -727,6 +737,22 @@ data.annotatorLoadQuery = query; }; + + /** + * redisplay checks if the page has changes and reloads all annotations. + */ + var handleRedisplay = function(evt) { + console.debug("annotations: handleRedisplay"); + var data = this; + var uri = getAnnotationPageUri(data); + if (uri != data.annotatorLoadQuery.uri) { + // uri changed + data.annotatorLoadQuery.uri = uri; + reloadAnnotations(data); + } + }; + + /** * update renders all annotations. */