1
0
mirror of https://github.com/suk-ws/ph-Bookshelf.git synced 2024-12-05 09:26:52 +08:00

实现了 Collections 和 章节 的折叠展开功能

This commit is contained in:
A.C.Sukazyo Eyre 2021-04-28 14:11:38 +08:00
parent 7192f09c9a
commit 2d608b6f2d
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
6 changed files with 41 additions and 3 deletions

29
assets/gitbook-fix.css Normal file
View File

@ -0,0 +1,29 @@
.fold > ul {
max-height: 0;
overflow: hidden;
transition-duration: 0.5s;
}
.fold.on > ul {
max-height: unset;
}
.book .book-summary ul.summary li a, .book .book-summary ul.summary li span {
padding-left: 30px;
cursor: pointer;
}
.book .book-summary .exc-trigger {
position: absolute;
left: 12px;
top: 12px;
}
.book .book-summary .on > a .exc-trigger:before {
content: "\f078";
}
.book .book-summary .exc-trigger:before {
content: "\f054";
}

View File

@ -21,3 +21,11 @@ window.onload = function () {
} }
}; };
for (let node of document.getElementsByClassName("fold")) {
node.childNodes[0].addEventListener("click", function () {
if (node.classList.contains("on")) {
node.classList.remove("on");
} else node.classList.add("on");
});
}

View File

@ -24,6 +24,7 @@ class SiteMeta {
public static function getGitbookStylesheetsList (): array { public static function getGitbookStylesheetsList (): array {
return array( return array(
"/assets/gitbook/style.css", "/assets/gitbook/style.css",
"/assets/gitbook-fix.css",
); );
} }

View File

@ -72,7 +72,7 @@ class BookCollection {
public function getHtml (): string { public function getHtml (): string {
$str = ""; $str = "";
if ($this->name != self::ROOT) $str .= "<li><a class='book-collection' href='#'>$this->name</a><ul class='book-collection summary'>"; if ($this->name != self::ROOT) $str .= "<li class='book-collection fold'><a class='book-collection' href='#'>$this->name<i class='exc-trigger fa'></i></a><ul class='book-collection summary'>";
foreach ($this->array as $node) { foreach ($this->array as $node) {
$str .= $node->getHtml(); $str .= $node->getHtml();
} }

View File

@ -66,7 +66,7 @@ class Chapter {
public function getSummaryHtml (): string { public function getSummaryHtml (): string {
$str = ""; $str = "";
if ($this->parent != null) $str .= "<li class='chapter'><a class='page-chapter' href='#'>$this->name</a><ul class='page-chapter summary'>"; if ($this->parent != null) $str .= "<li class='chapter fold'><a class='page-chapter' href='#'>$this->name<i class='exc-trigger fa'></i></a><ul class='page-chapter summary'>";
foreach ($this->childs as $node) { foreach ($this->childs as $node) {
$str .= $node->getSummaryHtml(); $str .= $node->getSummaryHtml();
} }

View File

@ -72,7 +72,7 @@ class LinkCollection {
public function getHtml (): string { public function getHtml (): string {
$str = ""; $str = "";
if ($this->name != self::ROOT) $str .= "<li><a class='link-collection chapter' href='#'>$this->name</a><ul class='link-collection articles'>"; if ($this->name != self::ROOT) $str .= "<li class='link-collection fold'><a class='link-collection chapter' href='#'>$this->name<i class='exc-trigger fa'></i></a><ul class='link-collection articles'>";
foreach ($this->array as $node) { foreach ($this->array as $node) {
$str .= $node->getHtml(); $str .= $node->getHtml();
} }