Commit 0574eb49 by Arthur Barrett

initialize annotator on any element by note:init event

parent 71209989
class @StudentNotes
targets: []
class StudentNotes
_debug: true
storeConfig:
prefix: ''
annotationData:
uri: ''
targets: [] # elements with annotator() instances
constructor: () ->
@storeConfig =
prefix: @getPrefix()
annotationData:
uri: @getURIPath()
constructor: ($, el) ->
console.log 'student notes init', arguments, this if @_debug
$(document).ready(@init)
init: ($) =>
if not StudentNotes.ready
$(document).delegate('*', {
'notes:init': @onInitNotes,
'notes:load': @onLoadNotes
})
StudentNotes.ready = true
if $(el).data('notes-ready') isnt 'yes'
$(el).delegate '*', 'notes:init': @onInitNotes
$(el).data('notes-ready', 'yes')
onInitNotes: (event, annotationData=null) =>
found = (target for target in @targets when target is event.target)
event.stopPropagation()
storeConfig = $.extend {}, @storeConfig
$.extend(storeConfig.annotationData, annotationData) if annotationData
found = @targets.some (target) -> target is event.target
if found.length is 0
if found
annotator = $(event.target).data('annotator')
store = annotator.plugins['Store']
store.options.annotationData = annotationData if annotationData
store.loadAnnotations()
else
$(event.target).annotator()
.annotator('addPlugin', 'Tags')
.annotator('addPlugin', 'Store', storeConfig)
.annotator('addPlugin', 'Store', @getStoreConfig(annotationData))
@targets.push(event.target)
onLoadNotes: (event) =>
if event.target in @targets
$(event.target).annotator().annotator('loadAnnotations')
getStoreConfig: (annotationData) ->
storeConfig =
prefix: @getPrefix()
annotationData:
uri: @getURIPath() # defaults to current URI path
$.extend storeConfig.annotationData, annotationData if annotationData
storeConfig
getPrefix: () ->
re = /^(\/courses\/[^/]+\/[^/]+\/[^/]+)/
......@@ -47,3 +43,5 @@ class @StudentNotes
getURIPath: () ->
window.location.href.toString().split(window.location.host)[1]
$(document).ready ($) -> new StudentNotes($, this)
\ No newline at end of file
......@@ -33,8 +33,8 @@
var onComplete = function(url) {
return function() {
annotationData = { 'uri': url }
$(this).trigger('notes:init', [annotationData]);
var annotationData = { 'uri': url }
$('#viewerContainer').trigger('notes:init', [annotationData]);
}
};
......
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