Commit d6e25c6f authored by Aron Carroll's avatar Aron Carroll

Remove Hypothesis class

This has been replaced with the crossframe service and related modules,
we still have the AngularAnnotator class for the auth service to
hook into but this is little more than a shell now.
parent 9e6d4760
......@@ -33,267 +33,6 @@ class AngularAnnotator extends Annotator
super(document.createElement('div'))
class Hypothesis extends Annotator
events:
'beforeAnnotationCreated': 'beforeAnnotationCreated'
'annotationDeleted': 'annotationDeleted'
'annotationsLoaded': 'digest'
# Plugin configuration
options:
noDocAccess: true
Threading: {}
# Internal state
providers: null
host: null
tool: 'comment'
visibleHighlights: false
this.$inject = ['$document', '$window', 'store']
constructor: ( $document, $window, store ) ->
super ($document.find 'body')
@providers = []
@store = store
# Load plugins
for own name, opts of @options
if not @plugins[name] and name of Annotator.Plugin
this.addPlugin(name, opts)
# Set up the bridge plugin, which bridges the main annotation methods
# between the host page and the panel widget.
whitelist = ['target', 'document', 'uri']
this.addPlugin 'Bridge',
gateway: true
formatter: (annotation) ->
formatted = {}
for k, v of annotation when k in whitelist
formatted[k] = v
formatted
parser: (annotation) ->
parsed = new store.AnnotationResource()
for k, v of annotation when k in whitelist
parsed[k] = v
parsed
onConnect: (source, origin, scope) =>
options =
window: source
origin: origin
scope: "#{scope}:provider"
onReady: => if source is $window.parent then @host = channel
channel = this._setupXDM options
provider = channel: channel, entities: []
channel.call
method: 'getDocumentInfo'
success: (info) =>
provider.entities = (link.href for link in info.metadata.link)
@providers.push provider
@element.scope().$digest()
this.digest()
# Allow the host to define it's own state
unless source is $window.parent
channel.notify
method: 'setTool'
params: this.tool
channel.notify
method: 'setVisibleHighlights'
params: this.visibleHighlights
_setupXDM: (options) ->
# jschannel chokes FF and Chrome extension origins.
if (options.origin.match /^chrome-extension:\/\//) or
(options.origin.match /^resource:\/\//)
options.origin = '*'
provider = Channel.build options
.bind('publish', (ctx, args...) => this.publish args...)
.bind('back', =>
# Navigate "back" out of the interface.
@element.scope().$apply => this.hide()
)
.bind('open', =>
# Pop out the sidebar
@element.scope().$apply => this.show()
)
.bind('showEditor', (ctx, tag) =>
@element.scope().$apply =>
this.showEditor this._getLocalAnnotation(tag)
)
.bind('showAnnotations', (ctx, tags=[]) =>
@element.scope().$apply =>
this.showViewer this._getLocalAnnotations(tags)
)
.bind('updateAnnotations', (ctx, tags=[]) =>
@element.scope().$apply =>
this.updateViewer this._getLocalAnnotations(tags)
)
.bind('focusAnnotations', (ctx, tags=[]) =>
@element.scope().$apply =>
this.focusAnnotations tags
)
.bind('toggleAnnotationSelection', (ctx, tags=[]) =>
@element.scope().$apply =>
this.toggleViewerSelection this._getLocalAnnotations(tags)
)
.bind('setTool', (ctx, name) =>
@element.scope().$apply => this.setTool name
)
.bind('setVisibleHighlights', (ctx, state) =>
@element.scope().$apply => this.setVisibleHighlights state
)
# Look up an annotation based on its bridge tag
_getLocalAnnotation: (tag) -> @plugins.Bridge.cache[tag]
# Look up a list of annotations, based on their bridge tags
_getLocalAnnotations: (tags) -> this._getLocalAnnotation t for t in tags
_setupWrapper: ->
@wrapper = @element.find('#wrapper')
this
_setupDocumentEvents: ->
document.addEventListener 'dragover', (event) =>
@host?.notify
method: 'dragFrame'
params: event.screenX
this
# Override things not used in the angular version.
_setupDynamicStyle: -> this
_setupViewer: -> this
_setupEditor: -> this
# Override things not needed, because we don't access the document
# with this instance
_setupDocumentAccessStrategies: -> this
_scan: -> this
createAnnotation: (annotation) ->
annotation = new @store.AnnotationResource(annotation)
this.publish 'beforeAnnotationCreated', annotation
annotation
deleteAnnotation: (annotation) ->
annotation.$delete(id: annotation.id).then =>
this.publish 'annotationDeleted', annotation
annotation
loadAnnotations: (annotations) ->
annotations = for annotation in annotations
container = @plugins.Threading.idTable[annotation.id]
if container?.message
angular.copy annotation, container.message
this.publish 'annotationUpdated', container.message
continue
else
annotation
super (new @store.AnnotationResource(a) for a in annotations)
# Do nothing in the app frame, let the host handle it.
setupAnnotation: (annotation) -> annotation
# Properly set the selectedAnnotations- and the Count variables
_setSelectedAnnotations: (selected) ->
scope = @element.scope()
count = Object.keys(selected).length
scope.selectedAnnotationsCount = count
if count
scope.selectedAnnotations = selected
else
scope.selectedAnnotations = null
toggleViewerSelection: (annotations=[]) ->
scope = @element.scope()
scope.search.query = ''
selected = scope.selectedAnnotations or {}
for a in annotations
if selected[a.id]
delete selected[a.id]
else
selected[a.id] = true
@_setSelectedAnnotations selected
this
focusAnnotations: (tags) ->
@element.scope().focusedAnnotations = tags
updateViewer: (annotations=[]) ->
# TODO: re-implement
this
showViewer: (annotations=[]) ->
scope = @element.scope()
scope.search.query = ''
selected = {}
for a in annotations
selected[a.id] = true
@_setSelectedAnnotations selected
this.show()
this
showEditor: (annotation) ->
delete @element.scope().selectedAnnotations
this.show()
this
show: ->
@host.notify method: 'showFrame'
hide: ->
@host.notify method: 'hideFrame'
digest: ->
@element.scope().$evalAsync angular.noop
beforeAnnotationCreated: (annotation) ->
annotation.user = @element.injector().get('auth').user
annotation.permissions = {}
@digest()
annotationDeleted: (annotation) ->
scope = @element.scope()
if scope.selectedAnnotations?[annotation.id]
delete scope.selectedAnnotations[annotation.id]
@_setSelectedAnnotations scope.selectedAnnotations
setTool: (name) ->
return if name is @tool
@tool = name
this.publish 'setTool', name
for p in @providers
p.channel.notify
method: 'setTool'
params: name
setVisibleHighlights: (state) ->
return if state is @visibleHighlights
@visibleHighlights = state
this.publish 'setVisibleHighlights', state
for p in @providers
p.channel.notify
method: 'setVisibleHighlights'
params: state
class DraftProvider
_drafts: null
......
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