Mercurial > hg > digilib
changeset 1584:817a5c42cb1b
annotator plugin: render annotations only on store event, include annotation data created on storage (e.g. id)
author | hertzhaft |
---|---|
date | Fri, 02 Dec 2016 19:13:28 +0100 |
parents | a07a557b6e39 |
children | f322ac84adf7 |
files | webapp/src/main/webapp/jquery/jquery.digilib.annotator.js webapp/src/main/webapp/jquery/jquery.digilib.vector.js |
diffstat | 2 files changed, 21 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/webapp/src/main/webapp/jquery/jquery.digilib.annotator.js Fri Dec 02 18:13:05 2016 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.annotator.js Fri Dec 02 19:13:28 2016 +0100 @@ -307,7 +307,7 @@ /** - * Show editor and save annotation. + * Show editor, edit and save new annotation. */ var addAnnotationContent = function (data, shape, screenPos) { var annotator = data.annotator; @@ -316,23 +316,32 @@ var annotation = annotator.createAnnotation(); annotation.editing = true; var cleanup = function () { + annotator.unsubscribe('annotationStore', store); annotator.unsubscribe('annotationEditorSubmit', save); annotator.unsubscribe('annotationEditorHidden', cancel); delete annotation.editing; }; var save = function () { - console.log("annotation save."); - cleanup(); - annotator.setupAnnotation(annotation); + console.log("annotation save"); // Fire annotationCreated events so that plugins can react to them annotator.publish('annotationCreated', [annotation]); + }; + var store = function (orig, stored) { + if (stored == null) { + console.warn('Annotation Store did not return the stored annotation'); + stored = annotation; + } + console.debug("annotation stored", stored); + cleanup(); renderAnnotations(data); + annotator.setupAnnotation(stored); }; var cancel = function () { - console.log("annotation cancel."); + console.log("annotation cancel"); cleanup(); renderAnnotations(data); }; + annotator.subscribe('annotationStored', store); annotator.subscribe('annotationEditorSubmit', save); annotator.subscribe('annotationEditorHidden', cancel); annotator.showEditor(annotation, screenPos.getAsCss());
--- a/webapp/src/main/webapp/jquery/jquery.digilib.vector.js Fri Dec 02 18:13:05 2016 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.vector.js Fri Dec 02 19:13:28 2016 +0100 @@ -217,9 +217,9 @@ svgElement: svgElement, svgAttr: svgAttr, createScreenCoords: createScreenCoords, - startEditShape: startEditShape, - undoEditShape: undoEditShape, - finishEditShape: finishEditShape, + startShapeEdit: startShapeEdit, + undoShapeEdit: undoShapeEdit, + finishShapeEdit: finishShapeEdit, redrawShape: redrawShape }); }; @@ -608,7 +608,7 @@ * @param data * @param shape */ - var startEditShape = function (data, shape) { + var startShapeEdit = function (data, shape) { shape.properties.editable = true; shape.savecoords = shape.geometry.coordinates.slice(0); // clone coords redrawShape(data, shape); @@ -620,7 +620,7 @@ * @param data * @param shape */ - var finishEditShape = function (data, shape) { + var finishShapeEdit = function (data, shape) { shape.properties.editable = false; redrawShape(data, shape); }; @@ -631,9 +631,9 @@ * @param data * @param shape */ - var undoEditShape = function (data, shape) { + var undoShapeEdit = function (data, shape) { shape.geometry.coordinates = shape.savecoords; - finishEditShape(data, shape); + finishShapeEdit(data, shape); }; /**