openannotation / annotator

Annotation tools for the web. Select text, images, or (nearly) anything else, and add your notes.
http://annotatorjs.org
Other
2.67k stars 532 forks source link

Store plugin: how to send variable values in annotationData #714

Open n8willis opened 3 years ago

n8willis commented 3 years ago

Let me start by saying this is very likely to be a jQuery issue, but for the life of me I'm turning up blanks on any answers that're real-world applicable. I've gone back through the entire mailing list archive (via the Wayback Machine...).

I have a deployment where I'm wanting to add some fields to the annotationData, but in which the values may change from annotation to annotation. And I'm not seeing how to set that up in a jQuery script for the annotator. What I need to capture is a straightforward bit of DOM info, but the setup for the Store plugin (apparently) gets evaluated on page load and doesn't see the updates. This is on 1.2, because touch support is a prerequisite.

Here's a minimal, but accurate, example. In thy page:

<script>
  jQuery(function ($) {
      var content = $('#content').annotator();
      content.annotator('addPlugin', 'Store', { prefix:
      'http://localhost:8888/store', annotationData: {'uri': window.location.href,
                                      'winwidth': window.innerWidth }
                            });
  });
</script> 

All I'm after here is to get the window.innerWidth, if it gets changed, but in my tests I get the initial value (correctly) on the first annotation, but changing the window size doesn't result in an updated value being sent with subsequent annotations. The storage backend is getting whatever is sent, so that's not the issue. It's the page.

Is there some easy answer I haven't found?

Like I said, I don't do jQuery stuff normally, and searching for examples just hasn't led anywhere at all; whether that's because search engines don't index stuff like $ in a way that leads to good results or there is something out-of-the-ordinary about the the sample code from the Annotator docs, I don't have any way to know.

zahqresh commented 3 years ago

Have you tried adding an eventListener for this purpose and get a value of window.innerWidth save it to a var and then pass that value to the annotationData?

n8willis commented 3 years ago

Well, like I said, I don't know jQuery, and although I've tried, I haven't succeeded.

You are saying that like it's not a convoluted process (which I believe; I just haven't been able to deduce some working code on my own). Would you mind showing an example snippet that does what you're suggesting?

n8willis commented 3 years ago

Again, it would be helpful if you would include a snippet to illustrate what you're suggesting.

n8willis commented 3 years ago

@zahqresh Really, can you elaborate even a bit on what you're suggesting?

zahqresh commented 3 years ago

Hi, sorry have been busy i'll look at the issue again and get back for more you cant send me an email and we can work on this if you want thank :)

n8willis commented 2 years ago

@zahqresh Hi; any elaboration here?