Skip to content

Instantly share code, notes, and snippets.

@itskingori
Last active December 18, 2020 17:21
Show Gist options
  • Save itskingori/2f5d4984fdfe1f1c1646 to your computer and use it in GitHub Desktop.
Save itskingori/2f5d4984fdfe1f1c1646 to your computer and use it in GitHub Desktop.
Example AnnotatorJS Plugin showing events
Annotator.Plugin.Example = function (element, options) {
var myPlugin = {};
myPlugin.pluginInit = function () {
// This annotator instance
this.annotator
// LOADING
.subscribe("annotationsLoaded", function (annotations) {
console.log("annotationsLoaded called when the annotations have been loaded.");
console.log(annotations);
})
// CREATE
.subscribe("beforeAnnotationCreated", function (annotation) {
console.log("beforeAnnotationCreated called immediately before an annotation is created. If you need to modify the annotation before it is saved use this event.");
console.log(annotation);
})
.subscribe("annotationCreated", function (annotation) {
console.log("annotationCreated called when the annotation is created use this to store the annotations.");
console.log(annotation);
})
// UPDATE
.subscribe("beforeAnnotationUpdated", function (annotation) {
console.log("beforeAnnotationUpdated as annotationCreated, but just before an existing annotation is saved.");
console.log(annotation);
})
.subscribe("annotationUpdated", function (annotation) {
console.log("annotationUpdated as beforeAnnotationUpdated, but for an existing annotation which has just been edited.");
console.log(annotation);
})
// DELETE
.subscribe("annotationDeleted", function (annotation) {
console.log("annotationDeleted called when the user deletes an annotation.");
console.log(annotation);
})
// VIEWER
.subscribe("annotationViewerShown", function (viewer, annotations) {
console.log("annotationViewerShown called when the annotation viewer is shown and provides the annotations being displayed.");
console.log(viewer);
console.log(annotations);
})
.subscribe("annotationViewerTextField", function (field, annotation) {
console.log("annotationViewerTextField called when the text field displaying the annotation comment in the viewer is created.");
console.log(field);
console.log(annotation);
})
// EDITOR
.subscribe("annotationEditorShown", function (editor, annotation) {
console.log("annotationEditorShown called when the annotation editor is presented to the user.");
console.log(editor);
console.log(annotation);
})
.subscribe("annotationEditorHidden", function (editor) {
console.log("annotationEditorHidden called when the annotation editor is hidden, both when submitted and when editing is cancelled.");
console.log(editor);
})
.subscribe("annotationEditorSubmit", function (editor, annotation) {
console.log("annotationEditorSubmit called when the annotation editor is submitted.");
console.log(editor);
console.log(annotation);
})
};
return myPlugin;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment