[annotator-dev] Hide annotator and reload annotations
Randall Leeds
tilgovi at hypothes.is
Fri Feb 14 22:11:13 UTC 2014
On Fri, Feb 14, 2014 at 6:58 AM, Steph Skardal <steph at endpoint.com> wrote:
> On 02/14/2014 02:11 AM, Riccardo Tasso wrote:
>
>> it would be nice having something like this:
>>
>> $(button).on('click', function() {
>>
>> var text = $(this.element).find('.text').first();
>> if(text.annotator == undefined) { // everytime I turn on I reload
>> annotations
>> text.annotator();
>> text.annotator('addPlugin', 'MyAnnotatorPlugin');
>> ...
>> } else {
>> text.annotator.destroy();
>> // at this point text.annotator is undefined
>> }
>> });
>>
>
>
> +1 on this request
This should work if you spell it `text.annotator('destroy')`.
But see this caveat: https://github.com/okfn/annotator/issues/265
I'm strongly considering that should deprecate the jquery interface for v2.
There's simply no good reason I see for it and it destroys introspection
IMO. Having the annotator object and being able to enumerate its methods
one can inspect the surface API in their browser dev tools.
`.annotator('<method_name>', <params ...>)` is unnecessary.
Annotator does store the Annotator instance object under the jquery data
key 'annotator'. So you might consider instead something like this instead:
```
var text = $(this.element).find('.text').first()
, annotator = text.data('annotator')
;
if(text.data('annotator') == undefined) {
annotator = new Annotator(text);
annotator.addPlugin('MyAnnotatorPlugin');
} else {
annotator.destroy();
}
```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/annotator-dev/attachments/20140214/e34bd38c/attachment-0004.html>
More information about the annotator-dev
mailing list