mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-02 14:49:16 +02:00
Merge 7dbe06815b
into f09089cf77
This commit is contained in:
commit
077933d62e
3 changed files with 19 additions and 3 deletions
|
@ -547,7 +547,7 @@ class Book {
|
||||||
|
|
||||||
return this.load(navPath, "xml")
|
return this.load(navPath, "xml")
|
||||||
.then((xml) => {
|
.then((xml) => {
|
||||||
this.navigation = new Navigation(xml);
|
this.navigation = new Navigation(xml, navPath);
|
||||||
this.pageList = new PageList(xml);
|
this.pageList = new PageList(xml);
|
||||||
return this.navigation;
|
return this.navigation;
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import {qs, qsa, querySelectorByType, filterChildren, getParentByTagName} from "./utils/core";
|
import {qs, qsa, querySelectorByType, filterChildren, getParentByTagName} from "./utils/core";
|
||||||
|
import Path from './utils/path'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Navigation Parser
|
* Navigation Parser
|
||||||
* @param {document} xml navigation html / xhtml / ncx
|
* @param {document} xml navigation html / xhtml / ncx
|
||||||
*/
|
*/
|
||||||
class Navigation {
|
class Navigation {
|
||||||
constructor(xml) {
|
constructor(xml, navPath='') {
|
||||||
this.toc = [];
|
this.toc = [];
|
||||||
this.tocByHref = {};
|
this.tocByHref = {};
|
||||||
this.tocById = {};
|
this.tocById = {};
|
||||||
|
@ -14,6 +15,9 @@ class Navigation {
|
||||||
this.landmarksByType = {};
|
this.landmarksByType = {};
|
||||||
|
|
||||||
this.length = 0;
|
this.length = 0;
|
||||||
|
if (navPath) {
|
||||||
|
this.tocPath = new Path(navPath)
|
||||||
|
}
|
||||||
if (xml) {
|
if (xml) {
|
||||||
this.parse(xml);
|
this.parse(xml);
|
||||||
}
|
}
|
||||||
|
@ -198,7 +202,8 @@ class Navigation {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let src = content.getAttribute("href") || "";
|
const href = content.getAttribute("href") || "";
|
||||||
|
let src = this.tocPath.join(href)
|
||||||
|
|
||||||
if (!id) {
|
if (!id) {
|
||||||
id = src;
|
id = src;
|
||||||
|
|
|
@ -58,6 +58,17 @@ class Path {
|
||||||
return (what.charAt(what.length-1) === "/");
|
return (what.charAt(what.length-1) === "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Join a paths
|
||||||
|
*
|
||||||
|
* https://nodejs.org/api/path.html#pathjoinpaths
|
||||||
|
* @param {string} what
|
||||||
|
* @returns {string} joined path
|
||||||
|
*/
|
||||||
|
join (what) {
|
||||||
|
return path.join(this.directory, what);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve a path against the directory of the Path
|
* Resolve a path against the directory of the Path
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue