Skip to content

Commit 6f0bbaf

Browse files
committed
add reached-end CustomEvent
1 parent 2fac8e1 commit 6f0bbaf

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

fixed-layout.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ export class FixedLayout extends HTMLElement {
301301
}
302302
async next() {
303303
const s = this.rtl ? this.#goLeft() : this.#goRight()
304+
if (!s && this.atEnd) this.dispatchEvent(new CustomEvent("reached-end"));
304305
if (s) this.#reportLocation('page')
305306
else return this.goToSpread(this.#index + 1, this.rtl ? 'right' : 'left', 'page')
306307
}

paginator.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,10 @@ export class Paginator extends HTMLElement {
10341034
Math.min(this.viewSize, distance ? this.start + distance : this.end), null, true)
10351035
return true
10361036
}
1037-
if (this.atEnd) return
1037+
if (this.atEnd) {
1038+
this.dispatchEvent(new CustomEvent('reached-end'))
1039+
return
1040+
}
10381041
const page = this.page + 1
10391042
const pages = this.pages
10401043
return this.#scrollToPage(page, 'page', true).then(() => page >= pages - 1)

view.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ export class View extends HTMLElement {
259259
this.renderer.setAttribute('exportparts', 'head,foot,filter')
260260
this.renderer.addEventListener('load', e => this.#onLoad(e.detail))
261261
this.renderer.addEventListener('relocate', e => this.#onRelocate(e.detail))
262+
this.renderer.addEventListener('reached-end', () => this.#onReachedEnd())
262263
this.renderer.addEventListener('create-overlayer', e =>
263264
e.detail.attach(this.#createOverlayer(e.detail)))
264265
this.renderer.open(book)
@@ -345,6 +346,9 @@ export class View extends HTMLElement {
345346

346347
this.#emit('load', { doc, index })
347348
}
349+
#onReachedEnd() {
350+
this.#emit('reached-end')
351+
}
348352
#handleLinks(doc, index) {
349353
const { book } = this
350354
const section = book.sections[index]

0 commit comments

Comments
 (0)