Skip to content

Instantly share code, notes, and snippets.

@tilgovi
Created March 11, 2015 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tilgovi/93a598a466b46c5d2eaa to your computer and use it in GitHub Desktop.
Save tilgovi/93a598a466b46c5d2eaa to your computer and use it in GitHub Desktop.
Annotator cross frame highlights metadata
diff --git a/h/static/scripts/annotator/monkey.coffee b/h/static/scripts/annotator/monkey.coffee
index da800da..51c8561 100644
--- a/h/static/scripts/annotator/monkey.coffee
+++ b/h/static/scripts/annotator/monkey.coffee
@@ -9,6 +9,12 @@ Util = Annotator.Util
delete Annotator.prototype.events[".annotator-hl mouseover"]
delete Annotator.prototype.events[".annotator-hl mouseout"]
+# Add createHighlight
+Annotator.prototype.createHighlight = ->
+ annotation = {$highlight: true}
+ this.publish('beforeAnnotationCreated', [annotation])
+ annotation
+
# Override setupAnnotation
Annotator.prototype.setupAnnotation = (annotation) ->
# If this is a new annotation, we might have to add the targets
diff --git a/h/static/scripts/cross-frame-service.coffee b/h/static/scripts/cross-frame-service.coffee
index 27421bb..5d89c26 100644
--- a/h/static/scripts/cross-frame-service.coffee
+++ b/h/static/scripts/cross-frame-service.coffee
@@ -27,7 +27,7 @@ class CrossFrameService
new Bridge(options)
createAnnotationSync = (bridge) ->
- whitelist = ['target', 'document', 'uri']
+ whitelist = ['$highlight', 'target', 'document', 'uri']
options =
formatter: (annotation) ->
formatted = {}
diff --git a/h/static/scripts/directives/annotation.coffee b/h/static/scripts/directives/annotation.coffee
index 2fed540..02cb3ee 100644
--- a/h/static/scripts/directives/annotation.coffee
+++ b/h/static/scripts/directives/annotation.coffee
@@ -64,8 +64,11 @@ AnnotationController = [
# @returns {boolean} True if the annotation is a highlight.
###
this.isHighlight = ->
- model.target?.length and not model.references?.length and
- not (model.text or model.deleted or model.tags?.length)
+ if model.id
+ model.target?.length and not model.references?.length and
+ not (model.text or model.deleted or model.tags?.length)
+ else
+ model.$highlight
###*
# @ngdoc method
@@ -265,7 +268,7 @@ AnnotationController = [
$scope.$emit('annotationUpdate')
# Save highlights once logged in.
- if highlight and this.isHighlight()
+ if this.isHighlight()
if model.user and not model.id
highlight = false # skip this on future updates
model.permissions = permissions.private()
diff --git a/h/static/scripts/guest.coffee b/h/static/scripts/guest.coffee
index 88c59e7..8f891a8 100644
--- a/h/static/scripts/guest.coffee
+++ b/h/static/scripts/guest.coffee
@@ -243,6 +243,11 @@ module.exports = class Annotator.Guest extends Annotator
this.plugins.CrossFrame.sync([annotation])
annotation
+ createHighlight: ->
+ annotation = super
+ this.plugins.CrossFrame.sync([annotation])
+ annotation
+
showAnnotations: (annotations) =>
@crossframe?.notify
method: "showAnnotations"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment