Commit d442316c authored by Randall Leeds's avatar Randall Leeds

Avoid duplicate events firing on creation

Some cleanup of the editor hide/show entanglement with creation events
is very desperately needed.

Closes #761
parent ceb3d7d2
......@@ -426,7 +426,45 @@ class Annotator.Host extends Annotator
method: 'addToken'
params: token
#Save the event for restarting edit
onAdderClick: (event) =>
"""
Differs from upstream in a few ways:
- Don't fire annotationCreated events: that's the job of the sidebar
- Save the event for retriggering if login interrupts the flow
"""
event?.preventDefault()
# Save the event for restarting edit
@event = event
super
# Hide the adder
@adder.hide()
position = @adder.position()
# Show a temporary highlight so the user can see what they selected
# Also extract the quotation and serialize the ranges
annotation = this.setupAnnotation(this.createAnnotation())
$(annotation.highlights).addClass('annotator-hl-temporary')
# Subscribe to the editor events
# Make the highlights permanent if the annotation is saved
save = =>
do cleanup
$(annotation.highlights).removeClass('annotator-hl-temporary')
# Remove the highlights if the edit is cancelled
cancel = =>
do cleanup
this.deleteAnnotation(annotation)
# Don't leak handlers at the end
cleanup = =>
this.unsubscribe('annotationEditorHidden', cancel)
this.unsubscribe('annotationEditorSubmit', save)
this.subscribe('annotationEditorHidden', cancel)
this.subscribe('annotationEditorSubmit', save)
# Display the editor.
this.showEditor(annotation, position)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment