[annotator-dev] Creating A JS Plugin For Voting/Likes/Recommend

King'ori J. Maina j at kingori.co
Wed Mar 4 18:56:04 UTC 2015

Hi Steph,

Thanks for your quick response.

I’ve put up a gist here <https://gist.github.com/itsmrwave/2f5d4984fdfe1f1c1646> … it contains the code I was using to determine when exactly the call backs are called. I think I’ve pretty much figured out how events work. Interestingly the “annotationsLoaded” event isn’t in the docs <http://docs.annotatorjs.org/en/v1.2.x/hacking/plugin-development.html#annotator-events> … thanks for that. Might come in handy.

All in all, thanks for the tips.

— King’ori Maina (kingori.co <http://kingori.co/>)

> On Mar 4, 2015, at 8:11 PM, steph <steph at endpoint.com <mailto:steph at endpoint.com>> wrote:
> Hi,
> On 03/04/2015 12:25 PM, King'ori J. Maina wrote:
>> I’ve been able to get some sample plugin code setup and being used by annotator but I’m struggling to figure out how to add the actual functionality of up-voting and down-voting. Getting exhausted while trying to learn/figure out coffee script. The idea was that I have some sample code to refer to as a base implementation of the fundamentals.
>> Any ideas as to a plugin that’s written in vanilla JS that I can poke into and learn?
> Edge Annotator is in vanilla JS, so everything in https://github.com/openannotation/annotator/tree/master/src <https://github.com/openannotation/annotator/tree/master/src> should now be JS only, although some of those don't necessarily demonstrate plugin capabilities.
> Here's one I'm working on: https://github.com/stephskardal/Annotation-Studio/blob/master/app/assets/javascripts/annotator-category.js <https://github.com/stephskardal/Annotation-Studio/blob/master/app/assets/javascripts/annotator-category.js>. It is compatible with Annotator 1.2.*. I've also worked on Annotator 2.0 and the plugin API is not much different. Here are some important bits:
> * pluginInit (https://github.com/stephskardal/Annotation-Studio/blob/master/app/assets/javascripts/annotator-category.js#L26 <https://github.com/stephskardal/Annotation-Studio/blob/master/app/assets/javascripts/annotator-category.js#L26>): called when a plugin is initialized, but before data loaded. Here's where you would call addField on the viewer or editor.
> * hook for annotationsLoaded, called after Annotator finishes loading annotations. Here's where you may manipulate annotations / UI after annotations loaded.
> * hooks for annotationUpdated, annotationCreated, called after annotation updated / created. Here's where you may manipulate the UI based on annotation data.
> * hook for annotationEditorSubmit, called right after user clicks "save", but before data is sent to the backend. Here's where you would modify the annotation data getting sent to the backend.
> * __bind calls on various plugin methods to set scope (https://github.com/stephskardal/Annotation-Studio/blob/master/app/assets/javascripts/annotator-category.js#L17-L22 <https://github.com/stephskardal/Annotation-Studio/blob/master/app/assets/javascripts/annotator-category.js#L17-L22>)
> There are quite a few more hooks, but I think these are likely to be the most popular.
> Another option is to use something like http://js2.coffee/ <http://js2.coffee/> to convert another plugin in CoffeeScript to JS.
> Steph
> _______________________________________________
> annotator-dev mailing list
> annotator-dev at lists.okfn.org <mailto:annotator-dev at lists.okfn.org>
> https://lists.okfn.org/mailman/listinfo/annotator-dev
> Unsubscribe: https://lists.okfn.org/mailman/options/annotator-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/annotator-dev/attachments/20150304/00478446/attachment-0003.html>

More information about the annotator-dev mailing list