recogito / recogito-js

A JavaScript library for text annotation
BSD 3-Clause "New" or "Revised" License
363 stars 42 forks source link

Creating annotation does not seem to work when target element is in iframe #59

Closed reckart closed 2 years ago

reckart commented 2 years ago

RecogitoJS seems to be rendering ok when applying it to the contents of an IFRAME. However, selecting text to create an annotation does not seem to be working. Not that in the specific case, RecogitoJS is initialized outside the iframe but then told to annotate an element within the iframe.

Specifically, SelectionHandler.js :: _onMouseUp seems to be obtaining the selection from the wrong document. I.e. it is obtaining the selection from the document outside of the iframe when the selection that has been made was within the iframe:

_onMouseUp = evt => {
    if (this.isEnabled) {
      const selection = getSelection(); // << e.g. here

Instead, the selection should probably be obtained from the document which owns the target element of the mouse event, e.g. evt.target.ownerDocument.getSelection().

reckart commented 2 years ago

As a "workaround", I am loading recogito within the iframe now - that works.

rsimon commented 2 years ago

Ah - thanks for spotting (and testing). I never even considered the case of using it in an iframe. But your suggested solution to use evt.target.ownerDocument seems both straightforward & cleaner!

rsimon commented 2 years ago

This issue is now fixed, plus a bunch of other issues that didn't work inside an iframe. (I hope I caught everything ;-) Let me know if you experience any other issues!

Cheers, R