Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save phuysmans/2be843598eb60cf37e2a723ac27d36ef to your computer and use it in GitHub Desktop.
Save phuysmans/2be843598eb60cf37e2a723ac27d36ef to your computer and use it in GitHub Desktop.
Example AnnotatorJS Plugin showing events
Annotator.Plugin.Voting = function (element, options) {
var voter = {};
voter.pluginInit = function () {
// This annotator instance
this.annotator
// LOADING
.subscribe("annotationsLoaded", function (annotations) {
console.log("annotationsLoaded called when the annotations have been loaded.")
})
// 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.")
})
.subscribe("annotationCreated", function (annotation) {
console.log("annotationCreated called when the annotation is created use this to store the annotations.")
})
// UPDATE
.subscribe("beforeAnnotationUpdated", function (annotation) {
console.log("beforeAnnotationUpdated as annotationCreated, but just before an existing annotation is saved.")
})
.subscribe("annotationUpdated", function (annotation) {
console.log("annotationUpdated as beforeAnnotationUpdated, but for an existing annotation which has just been edited.")
})
// DELETE
.subscribe("annotationDeleted", function (annotation) {
console.log("annotationDeleted called when the user deletes an annotation.")
})
// VIEWER
.subscribe("annotationViewerShown", function (viewer, annotations) {
console.log("annotationViewerShown called when the annotation viewer is shown and provides the annotations being displayed.")
})
.subscribe("annotationViewerTextField", function (field, annotation) {
console.log("annotationViewerTextField called when the text field displaying the annotation comment in the viewer is created.")
})
// EDITOR
.subscribe("annotationEditorShown", function (editor, annotation) {
console.log("annotationEditorShown called when the annotation editor is presented to the user.")
})
.subscribe("annotationEditorHidden", function (editor) {
console.log("annotationEditorHidden called when the annotation editor is hidden, both when submitted and when editing is cancelled.")
})
.subscribe("annotationEditorSubmit", function (editor, annotation) {
console.log("annotationEditorSubmit called when the annotation editor is submitted.")
})
};
return voter;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment