mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-10-22 06:49:51 -04:00
Add method for getting TOC item for any location
This commit is contained in:
1 parent
f5bf41def6
commit
ac4e3962df
1 file changed
+14
@@ -280,6 +280,20 @@ export class View {
|
||||
console.error(`Could not go to ${target}`)
|
||||
}
|
||||
}
|
||||
async getTOCItemOf(target) {
|
||||
try {
|
||||
const { index, anchor } = await this.resolveNavigation(target)
|
||||
const doc = await this.book.sections[index].createDocument()
|
||||
const frag = anchor(doc)
|
||||
const isRange = frag instanceof Range
|
||||
const range = isRange ? frag : doc.createRange()
|
||||
if (!isRange) range.selectNodeContents(frag)
|
||||
return this.#tocProgress.getProgress(index, range)
|
||||
} catch(e) {
|
||||
console.error(e)
|
||||
console.error(`Could not get ${target}`)
|
||||
}
|
||||
}
|
||||
goLeft() {
|
||||
return this.book.dir === 'rtl' ? this.renderer.next() : this.renderer.prev()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user