From 309a378303f2f5d9064004663fb8613428ee9fce Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Thu, 6 May 2021 14:58:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=20books=20=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E6=8A=98=E5=8F=A0=E5=92=8C=E8=87=AA=E5=8A=A8=E6=8A=98=E5=8F=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加了一个折叠浮动按钮,可以使 books 折叠起来 - 默认 books 会处于折叠状态,除了在全站主页时会自动展开 --- assets/gitbook-fix.css | 41 +++++++++++++++++++++++++++++++++++++++ assets/gitbook-fix.js | 13 +++++++++++++ src/Element/Bookshelf.php | 4 ++-- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/assets/gitbook-fix.css b/assets/gitbook-fix.css index 2fbfbf1..9ea7dfe 100644 --- a/assets/gitbook-fix.css +++ b/assets/gitbook-fix.css @@ -27,3 +27,44 @@ .book .book-summary .exc-trigger:before { content: "\f054"; } + +.book-summary ul.summary div.summary-container { + padding: 0; + max-height: 0; + overflow: hidden; +} + +.book-summary ul.summary div.summary-container.on { + padding: 7px 0; + max-height: unset; +} + +.book-summary ul.summary li.divider.block-end { + margin-top: 0; + position: relative; + overflow: unset; +} + +.book-summary ul.summary li.divider.block-start { + margin-bottom: 0; +} + +.book-summary ul.summary li.divider.block-end .summary-container-icon { + position: absolute; + top: 1px; + right: 20px; + padding: 0 5px 2px; + background: rgba(0,0,0,.07); + color: white; + border-bottom: 0; + border-radius: 0 0 5px 5px; + z-index: 1000; +} + +.book-summary ul.summary li.divider.block-end .summary-container-icon .fa:before { + content: "\f078"; +} + +.book-summary ul.summary div.summary-container.on + li.divider.block-end { + transform: rotateX(180deg); +} diff --git a/assets/gitbook-fix.js b/assets/gitbook-fix.js index 860e492..f7aa339 100644 --- a/assets/gitbook-fix.js +++ b/assets/gitbook-fix.js @@ -29,3 +29,16 @@ for (let node of document.getElementsByClassName("fold")) { } else node.classList.add("on"); }); } + +for (const node of document.getElementsByClassName("summary-container")) { + + node.nextElementSibling.innerHTML = node.nextElementSibling.innerHTML + ""; + node.nextElementSibling.getElementsByClassName("summary-container-icon")[0].addEventListener("click", function () { + if (node.classList.contains("on")) { + node.classList.remove("on") + } else { + node.classList.add("on") + } + }) + +} diff --git a/src/Element/Bookshelf.php b/src/Element/Bookshelf.php index 5c0cdbd..d7ee6b6 100644 --- a/src/Element/Bookshelf.php +++ b/src/Element/Bookshelf.php @@ -73,9 +73,9 @@ class Bookshelf { public function getHtml (): string { $str = "";