Skip to content

Commit

Permalink
Began work on the initialisation method for annotator-full.js. Ticket #…
Browse files Browse the repository at this point in the history
  • Loading branch information
aron committed Jun 29, 2011
1 parent 0f365e1 commit 94ee0df
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/plugin/kitchensink.coffee
@@ -0,0 +1,66 @@
# Public: A initialization function that sets up the Annotator and some of the
# default plugins. Intended for use with the annotator-full package.
#
# NOTE: This method is intened to be called via the jQuery .annotator() method
# although it is available directly on the Annotator instance.
#
# config - An Object containing config options for the AnnotateIt store.
# userId: AnnotateIt User ID.
# userName: Display name string for the annotations.
# accountId: AnnotateIt Account ID.
# authToken: AnnotateIt Auth Token.
# storeUri: API endpoint for the store (default: "http://annotateit.org/api")
#
# Examples
#
# $('#content').annotator().annotator('setupPlugins', {
# userId: 'demo-user',
# userName: 'Demo User',
# accountId: 'some-long-acccount-id',
# authToken: 'an-even-longer-auth-token'
# });
#
# Returns iteself for chaining.
Annotator::setupPlugins = (config={}) ->
# Set up the default plugins.
plugins =
Tags: {}
Filter: {}
Unsupported: {}

# If Showdown is included add the Markdown plugin.
plugins.Markdown = {} if window.Showdown

# Check the options for store credientials and add relevant plugins.
{userId, userName, accountId, authToken} = config
if userId and userName and accountId and authToken
uri = window.location.href.split(/#|\?/).shift()
$.extend plugins,
Store:
prefix: config.storeUri || 'http://annotateit.org/api'
annotationData:
'uri': uri
loadFromSearch:
uri: uri
all_fields: 1
Permissions:
user:
id: options.userId,
name: options.userName
permissions:
read: [options.userId]
update: [options.userId]
delete: [options.userId]
admin: [options.userId]
userId: (user) ->
if user?.id then user.id else ''
userString: (user) ->
if user?.name then user.name else ''

@element.data
'annotator:headers':
'X-Annotator-User-Id': options.userId
'X-Annotator-Account-Id': options.accountId
'X-Annotator-Auth-Token': options.authToken

this.addPlugin(name, options) for own name, options of plugins

0 comments on commit 94ee0df

Please sign in to comment.