Open parent document parts when go to part from TOC

This commit is contained in:
Georgy Litvinov 2021-03-05 00:04:59 +01:00
parent 43ff4e44a8
commit b49f169474

View file

@ -26,9 +26,30 @@
var docPartButton = docPart.previousElementSibling; var docPartButton = docPart.previousElementSibling;
var itemName = docPartButton.textContent; var itemName = docPartButton.textContent;
var link = document.createElement("a"); var link = document.createElement("a");
link.setAttribute("href","#" + anchor); link.setAttribute("href", "javascript:goToDocumentPart(\"" + anchor + "\");" );
link.innerText = itemName; link.innerText = itemName;
newTOCElement.appendChild(link); newTOCElement.appendChild(link);
tocElement.appendChild(newTOCElement); tocElement.appendChild(newTOCElement);
return newTOCElement; return newTOCElement;
} }
function goToDocumentPart(targetId){
if (targetId ===""){
return;
}
var targetNode = document.getElementById(targetId);
if (targetNode === null){
console.log("document has no target node to go to")
return;
}
showParents(targetNode);
document.getElementById(targetId).scrollIntoView();
}
function showParents(targetNode){
if (targetNode != null && "complexDocument" !== targetNode.id){
if (targetNode.style.display === "none") {
targetNode.style.display = "block";
}
showParents(targetNode.parentElement);
}
}