Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to retrieve the selection range/CFI from "onselectionchange"? #30

Open
nigini opened this issue Jul 28, 2024 · 1 comment
Open

How to retrieve the selection range/CFI from "onselectionchange"? #30

nigini opened this issue Jul 28, 2024 · 1 comment
Labels
question Further information is requested

Comments

@nigini
Copy link

nigini commented Jul 28, 2024

Hey there. Thanks for developing this library.

I am very interested in replicating some Annotation features from Foliate into the foliate-js demo, so I can read books on my Android device.

The first step is obviously to be able to retrieve the selection from the document and get the CFI range. I have added the following to the Reader.onLoad():

doc.addEventListener('selectionchange', this.#onselect.bind(this))
//Where onselect is:
#onselect(range) {
        let selection = window.getSelection()
        console.log("Selection", selection)
        console.log("Range", range)
}

But neither the selection nor range seem to give me specific enough targets to work with.
Hope you can help me.

@johnfactotum
Copy link
Owner

The book is rendered in an iframe, so you need to use something like event.currentTarget.defaultView.getSelection().

@johnfactotum johnfactotum added the question Further information is requested label Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants