Skip to content

Commit e0a6c02

Browse files
committed
doc: optimizes and simplifies the setupSidebarScroll() function
1 parent c5645ad commit e0a6c02

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

doc/api_assets/api.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,15 @@
188188
}
189189

190190
function setupSidebarScroll() {
191-
const sidebar = document.querySelector('#column2');
192-
if (!sidebar) return;
191+
const sidebarLinks = document.querySelectorAll('#column2 a');
193192

194-
const currentModule = window.location.pathname.split('/').pop();
195-
if (!currentModule) return;
193+
let link;
194+
for (link of sidebarLinks) {
195+
if (link.pathname === window.location.pathname) break;
196+
}
196197

197-
const link = sidebar.querySelector(`a[href="${currentModule}"]`);
198198
if (!link) return;
199-
199+
200200
link.scrollIntoView({ block: 'center' });
201201
}
202202

0 commit comments

Comments
 (0)