UX Improvements: Close TOC when navigating.

This commit is contained in:
Jeffrey N. 2024-12-31 00:55:30 -05:00
parent bbd7f33640
commit 01b52eaa95
2 changed files with 25 additions and 0 deletions

18
assets/book-header.js Normal file
View File

@ -0,0 +1,18 @@
(function () {
let tocLinks = document.querySelectorAll("#TableOfContents li");
let tocInput = document.getElementById("toc-control");
tocLinks.forEach(l =>
l.addEventListener("click",
() => tocInput.checked = false));
})();
(function () {
let menuLabel = document.querySelector("label[for='menu-control']");
let menuInput = document.getElementById("menu-control");
let tocInput = document.getElementById("toc-control");
menuLabel.addEventListener("click",
function () {
if (!menuInput.checked) {
tocInput.checked = false;
}
});
})();

View File

@ -21,6 +21,13 @@
{{ partial "docs/inject/content-before" . }} {{ partial "docs/inject/content-before" . }}
{{ template "main" . }} <!-- Page Content --> {{ template "main" . }} <!-- Page Content -->
<!-- Improve .book-header usability on mobile devices -->
{{ $script := resources.Get "book-header.js" | resources.Minify }}
{{ with $script.Content }}
<script>{{ . | safeJS }}</script>
{{ end }}
{{ partial "docs/inject/content-after" . }} {{ partial "docs/inject/content-after" . }}
<footer class="book-footer"> <footer class="book-footer">