1
0
Fork 0
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:
Fred Chasen 2017-11-06 12:09:59 -08:00
parent 7596f180d8
commit 3f16c7492e

View file

@ -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;
}
}