diff --git a/src/manifest/manifest.js b/src/manifest/manifest.js index af93db8..caf7afd 100644 --- a/src/manifest/manifest.js +++ b/src/manifest/manifest.js @@ -35,7 +35,17 @@ class Manifest extends Publication { const contentsUrl = this.contentsUrl; if (contentsUrl) { - this.contents = await this.loadContents(contentsUrl); + this.contents = await this.loadNavigation(contentsUrl, "toc"); + } + + const landmarksUrl = this.landmarksUrl; + if (landmarksUrl) { + this.landmarks = await this.loadNavigation(landmarksUrl, "landmarks"); + } + + const pagelistUrl = this.pagelistUrl; + if (pagelistUrl) { + this.pagelist = await this.loadNavigation(pagelistUrl, "pagelist"); } } @@ -48,13 +58,13 @@ class Manifest extends Publication { return this.unpack(manifest); } - async loadContents(contentsUrl) { + async loadNavigation(contentsUrl, role="toc") { const html = await this.load(contentsUrl, "html"); let items = []; let url = createUrl(contentsUrl); const title = html.querySelector("h1, h2, h3, h4, h5, h6"); - const toc = html.querySelector("*[role='doc-toc']"); + const toc = html.querySelector(`*[role='doc-${role}']`); if (toc) { const links = toc.querySelectorAll("ol > li > a, ul > li > a"); for (const link of links) { diff --git a/src/publication/publication.js b/src/publication/publication.js index 99b7d33..7f0e5a2 100644 --- a/src/publication/publication.js +++ b/src/publication/publication.js @@ -34,7 +34,7 @@ class Publication { resources: new ResourceList(), links: new ResourceList(), uniqueResources: new ResourceList(), - displayOptions: new DisplayOptions() + displayOptions: new DisplayOptions(), }; if (requestMethod) { diff --git a/src/publication/locators.js b/src/rendition/locators.js similarity index 92% rename from src/publication/locators.js rename to src/rendition/locators.js index 373ae72..466b3a1 100644 --- a/src/publication/locators.js +++ b/src/rendition/locators.js @@ -1,7 +1,5 @@ -import {qs, sprint, locationOf, defer} from "../utils/core.js"; -import Queue from "../utils/queue.js"; +import { locationOf } from "../utils/core.js"; import EpubCFI from "../utils/epubcfi.js"; -import { EVENTS } from "../utils/constants.js"; import EventEmitter from "../utils/eventemitter.js"; /** @@ -9,19 +7,19 @@ import EventEmitter from "../utils/eventemitter.js"; * @param {object} [manifest] */ class Locators { - constructor(manifest) { - if (manifest) { - this.unpack(manifest); + constructor(publication) { + if (publication) { + this.unpack(publication); } } - unpack(manifest) { - if (manifest.locations) { - this.unpackLocations(manifest.locations); + unpack(publication) { + if (publication.locations) { + this.unpackLocations(publication.locations); } - if (manifest.pages) { - this.unpackPages(manifest.page); + if (publication.pagelist) { + this.unpackPages(publication.pagelist); } } diff --git a/src/rendition/rendition.js b/src/rendition/rendition.js index 3c8abcf..f48386e 100644 --- a/src/rendition/rendition.js +++ b/src/rendition/rendition.js @@ -19,6 +19,7 @@ import DefaultViewManager from "../managers/default/default.js"; import ContinuousViewManager from "../managers/continuous/continuous.js"; import Publication from "../publication/publication.js"; +import Locators from "./locators.js"; /** * Displays an Epub as a series of Views for each Section. @@ -253,6 +254,8 @@ class Rendition { }); } + this.locators = new Locators(this.publication); + this.direction(this.publication.metadata.direction || this.settings.defaultDirection); // Parse metadata to get layout props @@ -846,22 +849,22 @@ class Rendition { }; if (this.publication.locations.length) { - let locationStart = this.publication.locators.locationFromCfi(start.mapping.start); - let locationEnd = this.publication.locators.locationFromCfi(end.mapping.end); + let locationStart = this.locators.locationFromCfi(start.mapping.start); + let locationEnd = this.locators.locationFromCfi(end.mapping.end); if (locationStart != null) { located.start.location = locationStart; - located.start.percentage = this.publication.locators.percentageFromLocation(locationStart); + located.start.percentage = this.locators.percentageFromLocation(locationStart); } if (locationEnd != null) { located.end.location = locationEnd; - located.end.percentage = this.publication.locators.percentageFromLocation(locationEnd); + located.end.percentage = this.locators.percentageFromLocation(locationEnd); } } if (this.publication.pagelist.length) { - let pageStart = this.publication.locators.pageFromCfi(start.mapping.start); - let pageEnd = this.publication.locators.pageFromCfi(end.mapping.end); + let pageStart = this.locators.pageFromCfi(start.mapping.start); + let pageEnd = this.locators.pageFromCfi(end.mapping.end); if (pageStart != -1) { located.start.page = pageStart;