[annotator-dev] How to call loadFromSearch or loadAnnotations function of the Store plugin manually?
Randall Leeds
tilgovi at hypothes.is
Tue May 12 18:55:39 UTC 2015
On Tue, May 12, 2015 at 6:25 AM, Mathias Lin <mathias.lin at westernacher.com>
wrote:
> Hi Randall,
>
> thanks for your info. I tried to follow your example, but still having
> some problems understanding the object hierarchy.
>
> I execute the following in the developer console, but the approach you
> mentioned did not yet succeed in my test.
>
> var content = $('#content').annotator(); // works
>
Ahh, I'm so sorry! I misspoke.
var annotator = new Annotator('#content');
Then you should have the actual instance, rather than a jQuery object or
plugin.
the rest, below, should work, then.
> but:
>
> content.addPlugin('Tags'); // does not work -> Uncaught TypeError:
> content.addPlugin is not a function
> content.annotator.addPlugin('Tags'); // does not work -> Uncaught
> TypeError: content.annotator.addPlugin is not a function
>
> Only this way of adding a plugin works:
>
> content.annotator('addPlugin', 'Tags').annotator('addPlugin', 'Store'); //
> works
>
>
> Still, I don't see how to access the plugins then. Neither of the two ways
> below works:
>
> content.plugins; --> undefined
> content.annotator.plugins; -> undefined
>
>
> FYI - the following line executed in the developer console:
>
> content.annotator;
>
> returns this object:
>
> function (options) {
> var args;
> args = Array.prototype.slice.call(arguments, 1);
> return this.each(function() {
> var instance;
> instance = $.data(this, 'annotator');
> if (options === 'destroy') {
> $.removeData(this, 'annotator');
> return instance != null ? instance.destroy(args) : void 0;
> } else if (instance) {
> return options && instance[options].apply(instance, args);
> } else {
> instance = new Annotator(this, options);
> return $.data(this, 'annotator', instance);
> }
> });
> }
>
>
> Thanks,
> Mathias
>
>
>
>
> From: Randall Leeds [mailto:tilgovi at hypothes.is]
> Sent: Montag, 11. Mai 2015 19:10
> To: Mathias Lin
> Cc: annotator-dev at lists.okfn.org
> Subject: Re: [annotator-dev] How to call loadFromSearch or loadAnnotations
> function of the Store plugin manually?
>
> This is beyond the scope of what plugins were designed for, since they
> mostly just do work in response to events.
> However, it's possible.
> First, get a handle to your annotator instance directly.
> var annotator = $('#content').annotator();
> This object has all the methods you see the jQuery plugin providing,
> without having to call ".annotator()" every time. For instance, you can do
> "annotator.addPlugin(...)".
> Next, you can access the store plugin itself as " annotator.plugins.Store".
> On May 11, 2015 07:44, "Mathias Lin" <mathias.lin at westernacher.com> wrote:
> Hello,
>
> How can I call the loadFromSearch or loadAnnotations function of the Store
> plugin (http://docs.annotatorjs.org/en/v1.2.x/plugins/store.html)
> manually, not only automated when the plugin is added for the first time?
>
> Currently it¹s being executed when the plugin is added:
>
> $('#content').annotator('addPlugin', 'Store', {
> loadFromSearch: {
> 'limit': 0,
> 'all_fields': 1,
> 'uri': 'http://this/document/only'
> }
> });
>
>
> but I need to call it multiple times later on.
>
>
> How to get a reference to the Store-Plugin in order to call its functions?
>
> Thanks,
> Mathias
>
>
> btw:
>
> @Randall:
> I noted you are writing an app to integrated Annotator into pdf.js.
> https://lists.okfn.org/pipermail/annotator-dev/2015-May/001423.html
> I am actually working on exactly the same right now. Would be interesting
> to know about your experience and progress.
> My question above is actually related to that project.
>
> _______________________________________________
> annotator-dev mailing list
> 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/20150512/d57e857c/attachment-0004.html>
More information about the annotator-dev
mailing list