diff --git a/assets/book-header.js b/assets/book-header.js
new file mode 100644
index 0000000..fd3eee5
--- /dev/null
+++ b/assets/book-header.js
@@ -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;
+ }
+ });
+})();
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html
index a6c4c07..15f8390 100644
--- a/layouts/_default/baseof.html
+++ b/layouts/_default/baseof.html
@@ -21,6 +21,13 @@
{{ partial "docs/inject/content-before" . }}
{{ template "main" . }}
+
+
+ {{ $script := resources.Get "book-header.js" | resources.Minify }}
+ {{ with $script.Content }}
+
+ {{ end }}
+
{{ partial "docs/inject/content-after" . }}