Skip to content

Commit 309a378

Browse files
committed
为 books 添加了折叠和自动折叠
- 添加了一个折叠浮动按钮,可以使 books 折叠起来 - 默认 books 会处于折叠状态,除了在全站主页时会自动展开
1 parent a9b9a94 commit 309a378

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

assets/gitbook-fix.css

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,44 @@
2727
.book .book-summary .exc-trigger:before {
2828
content: "\f054";
2929
}
30+
31+
.book-summary ul.summary div.summary-container {
32+
padding: 0;
33+
max-height: 0;
34+
overflow: hidden;
35+
}
36+
37+
.book-summary ul.summary div.summary-container.on {
38+
padding: 7px 0;
39+
max-height: unset;
40+
}
41+
42+
.book-summary ul.summary li.divider.block-end {
43+
margin-top: 0;
44+
position: relative;
45+
overflow: unset;
46+
}
47+
48+
.book-summary ul.summary li.divider.block-start {
49+
margin-bottom: 0;
50+
}
51+
52+
.book-summary ul.summary li.divider.block-end .summary-container-icon {
53+
position: absolute;
54+
top: 1px;
55+
right: 20px;
56+
padding: 0 5px 2px;
57+
background: rgba(0,0,0,.07);
58+
color: white;
59+
border-bottom: 0;
60+
border-radius: 0 0 5px 5px;
61+
z-index: 1000;
62+
}
63+
64+
.book-summary ul.summary li.divider.block-end .summary-container-icon .fa:before {
65+
content: "\f078";
66+
}
67+
68+
.book-summary ul.summary div.summary-container.on + li.divider.block-end {
69+
transform: rotateX(180deg);
70+
}

assets/gitbook-fix.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,16 @@ for (let node of document.getElementsByClassName("fold")) {
2929
} else node.classList.add("on");
3030
});
3131
}
32+
33+
for (const node of document.getElementsByClassName("summary-container")) {
34+
35+
node.nextElementSibling.innerHTML = node.nextElementSibling.innerHTML + "<a class='summary-container-icon'><i class='fa'></i></a>";
36+
node.nextElementSibling.getElementsByClassName("summary-container-icon")[0].addEventListener("click", function () {
37+
if (node.classList.contains("on")) {
38+
node.classList.remove("on")
39+
} else {
40+
node.classList.add("on")
41+
}
42+
})
43+
44+
}

src/Element/Bookshelf.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ public function getRootBook (): BookContented {
7373
public function getHtml (): string {
7474
$str = "<ul id='global-container' class='summary'>";
7575
$str .= $this->links->getHtml();
76-
$str .= "<li class='divider'></li>";
76+
$str .= "<li class='divider block-start'></li><div class='summary-container" . (PageMeta::$isMainPage?" on":"") . "'>";
7777
$str .= $this->books->getHtml();
78-
$str .= "<li class='divider'></li>";
78+
$str .= "</div><li class='divider block-end'></li>";
7979
$str .= PageMeta::$book->getSummaryHtml();
8080
$str .= "<li class='divider'></li><li><a href='https://github.com/Eyre-S/ph-Bookshelf' target='blank' class='gitbook-link'>Generated with ph-Bookshelf</a></li><li><a href='https://www.gitbook.com' target='blank' class='gitbook-link'>Front-End by GitBook</a></li>";
8181
$str .= "</ul>";

0 commit comments

Comments
 (0)