mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Navigation href fallback for parent detection
The navItem function assumes that every item has an id attribute. In practice this is not always the case, this will use the href attribute as fallback for the id attribute.
This commit is contained in:
parent
7fd362bb82
commit
6d328c02dc
1 changed files with 12 additions and 0 deletions
|
@ -162,6 +162,10 @@ class Navigation {
|
||||||
}
|
}
|
||||||
|
|
||||||
let src = content.getAttribute("href") || "";
|
let src = content.getAttribute("href") || "";
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
id = src;
|
||||||
|
}
|
||||||
let text = content.textContent || "";
|
let text = content.textContent || "";
|
||||||
let subitems = [];
|
let subitems = [];
|
||||||
let parentItem = getParentByTagName(item, "li");
|
let parentItem = getParentByTagName(item, "li");
|
||||||
|
@ -169,12 +173,20 @@ class Navigation {
|
||||||
|
|
||||||
if (parentItem) {
|
if (parentItem) {
|
||||||
parent = parentItem.getAttribute("id");
|
parent = parentItem.getAttribute("id");
|
||||||
|
if (!parent) {
|
||||||
|
const parentContent = filterChildren(parentItem, "a", true);
|
||||||
|
parent = parentContent && parentContent.getAttribute("href");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!parent && parentItem) {
|
while (!parent && parentItem) {
|
||||||
parentItem = getParentByTagName(parentItem, "li");
|
parentItem = getParentByTagName(parentItem, "li");
|
||||||
if (parentItem) {
|
if (parentItem) {
|
||||||
parent = parentItem.getAttribute("id");
|
parent = parentItem.getAttribute("id");
|
||||||
|
if (!parent) {
|
||||||
|
const parentContent = filterChildren(parentItem, "a", true);
|
||||||
|
parent = parentContent && parentContent.getAttribute("href");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue