From 106622dbda3705a6cad77ccc845defd32b9d3611 Mon Sep 17 00:00:00 2001 From: amazingrise <8315221+AmazingRise@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:15:33 +0800 Subject: Fixed wrong collapsing when currentIndex is -1. --- static/js/toc-collapse.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/static/js/toc-collapse.js b/static/js/toc-collapse.js index a2780f9..8af46b9 100644 --- a/static/js/toc-collapse.js +++ b/static/js/toc-collapse.js @@ -23,15 +23,24 @@ var spy = function () { navElem.removeClass('toc-active'); } }) - if (currentIndex == -1) { - currentIndex = elems.length - 1; - } //console.log(elems[currentIndex].id); //Collapse them - collapseOthers("#" + elems[currentIndex].id + "-nav"); + collapseOthers(currentIndex); } -var collapseOthers = function (currentId) { + + + +var collapseOthers = function (currentIndex) { + if (currentIndex == -1) { + $(".collapse").each(function (idx) { + $(this).collapse("hide"); + }); + return; + } + var elems = $(":header"); + currentId = "#" + elems[currentIndex].id + "-nav"; //console.log(currentId); + $(currentId).parents(".collapse").each(function (idx) { $(this).collapse("show"); }); @@ -39,7 +48,6 @@ var collapseOthers = function (currentId) { $(".collapse").not($(currentId).parents()).not($(currentId).parent().next()).each(function (idx) { $(this).collapse("hide"); }); - } $().ready(function () { spy(); -- cgit v1.2.3