From edea003b2fe803994997bb74dfeb29afe8c85ed7 Mon Sep 17 00:00:00 2001 From: John Factotum <50942278+johnfactotum@users.noreply.github.com> Date: Tue, 16 May 2023 16:21:56 +0800 Subject: [PATCH] Add option to show start of main body text as defined in landmarks --- view.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/view.js b/view.js index 784ee16..448f98b 100644 --- a/view.js +++ b/view.js @@ -78,12 +78,16 @@ export class View extends HTMLElement { this.renderer.open(book) this.#root.append(this.renderer) } - async init({ lastLocation }) { - if (lastLocation) { - const resolved = this.resolveNavigation(lastLocation) - if (resolved) await this.renderer.goTo(resolved) - else await this.renderer.next() - } else await this.renderer.next() + goToTextStart() { + return this.goTo(this.book.landmarks + ?.find(m => m.type.includes('bodymatter') || m.type.includes('text')) + ?.href ?? this.book.sections.findIndex(s => s.linear !== 'no')) + } + async init({ lastLocation, showTextStart }) { + const resolved = lastLocation ? this.resolveNavigation(lastLocation) : null + if (resolved) await this.renderer.goTo(resolved) + else if (showTextStart) await this.goToTextStart() + else await this.renderer.next() } #emit(name, detail, cancelable) { return this.dispatchEvent(new CustomEvent(name, { detail, cancelable }))