mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-09-09 11:29:14 -04:00
Add method for getting TOC item for any location
This commit is contained in:
@@ -280,6 +280,20 @@ export class View {
|
|||||||
console.error(`Could not go to ${target}`)
|
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() {
|
goLeft() {
|
||||||
return this.book.dir === 'rtl' ? this.renderer.next() : this.renderer.prev()
|
return this.book.dir === 'rtl' ? this.renderer.next() : this.renderer.prev()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user