Skip to content

Instantly share code, notes, and snippets.

@tilgovi
Created May 9, 2014 18:07
Show Gist options
  • Select an option

  • Save tilgovi/fd5c980c89092c58fb72 to your computer and use it in GitHub Desktop.

Select an option

Save tilgovi/fd5c980c89092c58fb72 to your computer and use it in GitHub Desktop.
// This is our interaction point
position = null;
$(document.body).on('mouseup', function (event) {
});
var annotator = Annotator.create({
onSelection: function (event) {
// We have to trigger this event ourselves.
// Could be as simple as:
// event = $.Event('selection', event);
// target = Util.getGlobal().getSelection().getRangeAt(0).commonAncestor
// $(target).trigger(event);
// Though I'm not certain jQuery will accept clientX, etc in hash passed to $.Event
annotation = null;
position = Util.getMousePosition(event);
adder.show(position);
},
onCreate: function (annotation) {
position = Util.getMousePosition(event);
editor.show(position);
}.wait()
.then(function () {
annotation = textSelector.describe(selection);
// Fire beforeAnnotationCreated here for legacy plugins?
return editor
.load(selection)
.show(position)
.wait();
})
.then(function () {
return store.save(annotation);
})
.then(function () {
// Fire annotationCreated here for legacy plugins?
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment