Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
Fix active tree item not updating in web help (#425)
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
  • Loading branch information
t1m0thyj committed Apr 20, 2021
1 parent 0e1e0e8 commit 43ebbd4
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions web-help/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,31 @@ const clipboard = new (require("clipboard"))(".btn-copy");
clipboard.on("success", (e: any) => setTooltip(e.trigger, "Copied!"));
clipboard.on("error", (e: any) => setTooltip(e.trigger, "Failed!"));

/**
* Find the currently scrolled to command anchor in iframe
* @returns Element with <a> tag
*/
function findCurrentCmdAnchor() {
const anchors = arrayFrom(document.getElementsByClassName("cmd-anchor"));
let lastAnchor: any;
for (const anchor of anchors) {
const headerBounds = (anchor.nextElementSibling as any).getBoundingClientRect();
if (headerBounds.top > window.innerHeight) {
break;
}
lastAnchor = anchor;
}
return lastAnchor;
}

// If in flat view, select currently scrolled to command in tree
if (isInIframe && (window.location.href.indexOf("/all.html") !== -1)) {
let currentCmdName: string;
window.onscroll = (_: any) => {
const anchors = arrayFrom(document.getElementsByClassName("cmd-anchor"));
for (const anchor of anchors) {
const headerBounds = (anchor.nextElementSibling as any).getBoundingClientRect();
if (0 < headerBounds.bottom) {
if (headerBounds.top < window.innerHeight) {
const cmdName = anchor.getAttribute("name");
if (cmdName && (cmdName !== currentCmdName)) {
window.parent.postMessage(cmdName + ".html", "*");
currentCmdName = cmdName;
}
}
break;
}
const cmdName = findCurrentCmdAnchor().getAttribute("name");
if (cmdName != null && cmdName !== currentCmdName) {
window.parent.postMessage(cmdName + ".html", "*");
currentCmdName = cmdName;
}
};
}

0 comments on commit 43ebbd4

Please sign in to comment.