Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/generators/legacy-html/assets/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,19 @@ const setupCopyButton = () => {
function setupSidebarScroll() {
const sidebarLinks = document.querySelectorAll('#column2 a');

let link;
for (link of sidebarLinks) {
let activeLink = null;
for (const link of sidebarLinks) {
if (link.pathname === window.location.pathname) {
activeLink = link;
break;
}
}

if (!link) {
if (!activeLink) {
return;
Comment on lines +206 to 215
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a .find?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To use .find(), you first need to convert sidebarLinks into an array (using Array.from()). I can simplify this, would you like me to do that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, opinions @nodejs/web-infra?

}

link.scrollIntoView({ behavior: 'smooth', block: 'center' });
activeLink.scrollIntoView({ behavior: 'smooth', block: 'center' });
}

// Initialize either on DOMContentLoaded or immediately if already loaded
Expand Down
Loading