mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-05 15:32:55 +02:00
Add landmark method
This commit is contained in:
parent
7596f180d8
commit
3f16c7492e
1 changed files with 23 additions and 1 deletions
|
@ -7,9 +7,12 @@ import {qs, qsa, querySelectorByType, filterChildren, getParentByTagName} from "
|
|||
class Navigation {
|
||||
constructor(xml) {
|
||||
this.toc = [];
|
||||
this.landmarks = [];
|
||||
this.tocByHref = {};
|
||||
this.tocById = {};
|
||||
|
||||
this.landmarks = [];
|
||||
this.landmarksByType = {};
|
||||
|
||||
this.length = 0;
|
||||
if (xml) {
|
||||
this.parse(xml);
|
||||
|
@ -93,6 +96,24 @@ class Navigation {
|
|||
return this.toc[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a landmark by type
|
||||
* List of types: https://idpf.github.io/epub-vocabs/structure/
|
||||
* @param {string} type
|
||||
* @return {object} landmarkItems
|
||||
*/
|
||||
landmark(type) {
|
||||
var index;
|
||||
|
||||
if(!type) {
|
||||
return this.landmarks;
|
||||
}
|
||||
|
||||
index = this.landmarksByType[type];
|
||||
|
||||
return this.landmarks[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse toc from a Epub > 3.0 Nav
|
||||
* @private
|
||||
|
@ -186,6 +207,7 @@ class Navigation {
|
|||
item = this.landmarkItem(navItems[i]);
|
||||
if (item) {
|
||||
list.push(item);
|
||||
this.landmarksByType[item.type] = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue