From b6aa0459976165d4388095432c0f356e5f053513 Mon Sep 17 00:00:00 2001
From: Wu Cheng-Han
Date: Tue, 2 Aug 2016 10:54:03 +0800
Subject: Update to add expand and collapse toggle for TOC, keep showing second
level TOC if there is only one first level TOC
---
public/js/extra.js | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
(limited to 'public/js')
diff --git a/public/js/extra.js b/public/js/extra.js
index f20d59d8..40496967 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -568,6 +568,20 @@ function removeHash() {
history.pushState("", document.title, window.location.pathname + window.location.search);
}
+var tocExpand = false;
+
+function checkExpandToggle() {
+ var toc = $('.ui-toc-dropdown .toc');
+ var toggle = $('.expand-toggle');
+ if (!tocExpand) {
+ toc.removeClass('expand');
+ toggle.text('Expand all');
+ } else {
+ toc.addClass('expand');
+ toggle.text('Collapse all');
+ }
+}
+
//toc
function generateToc(id) {
var target = $('#' + id);
@@ -581,8 +595,16 @@ function generateToc(id) {
});
if (target.text() == 'undefined')
target.html('');
+ var toggle = $('Expand all');
var backtotop = $('Back to top');
var gotobottom = $('Go to bottom');
+ checkExpandToggle();
+ toggle.click(function (e) {
+ e.preventDefault();
+ e.stopPropagation();
+ tocExpand = !tocExpand;
+ checkExpandToggle();
+ });
backtotop.click(function (e) {
e.preventDefault();
e.stopPropagation();
@@ -597,7 +619,7 @@ function generateToc(id) {
scrollToBottom();
removeHash();
});
- target.append(backtotop).append(gotobottom);
+ target.append(toggle).append(backtotop).append(gotobottom);
}
//smooth all hash trigger scrolling
--
cgit v1.2.3