Skip to content

Commit 3b9a5db

Browse files
author
yinghuochong-coder
committed
日常提交
1 parent 03ba756 commit 3b9a5db

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

book_template/theme/toc.js.hbs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,25 @@ class MDBookSidebarScrollbox extends HTMLElement {
2222
if (href && !href.startsWith("#") && !/^(?:[a-z+]+:)?\/\//.test(href)) {
2323
link.href = path_to_root + href;
2424
}
25+
26+
var parent = link.parentElement;
27+
if (parent && parent.classList.contains("chapter-item")) {
28+
parent.classList.toggle("expanded");
29+
}
30+
2531
// The "index" page is supposed to alias the first chapter in the book.
2632
if (link.href === current_page || (i === 0 && path_to_root === "" && current_page.endsWith("/index.html"))) {
2733
link.classList.add("active");
28-
29-
var parent = link.parentElement;
30-
if (parent && parent.classList.contains("chapter-item")) {
31-
parent.classList.add("expanded");
32-
}
34+
3335
while (parent) {
3436
if (parent.tagName === "LI" && parent.previousElementSibling) {
3537
if (parent.previousElementSibling.classList.contains("chapter-item")) {
36-
parent.previousElementSibling.classList.add("expanded");
38+
parent.previousElementSibling.classList.toggle("expanded");
3739
}
3840
}
3941
parent = parent.parentElement;
4042
}
43+
/**/
4144
}
4245
}
4346
// Track and set sidebar scroll position

0 commit comments

Comments
 (0)