diff options
author | amazingrise <8315221+AmazingRise@users.noreply.github.com> | 2020-06-14 17:15:33 +0300 |
---|---|---|
committer | amazingrise <8315221+AmazingRise@users.noreply.github.com> | 2020-06-14 17:15:33 +0300 |
commit | 106622dbda3705a6cad77ccc845defd32b9d3611 (patch) | |
tree | 4177c73158a9c31e5728773ff933534a2f9d8669 | |
parent | 75c270eebb9e97f982965164814f1fa3ec46f49a (diff) |
Fixed wrong collapsing when currentIndex is -1.
-rw-r--r-- | static/js/toc-collapse.js | 20 |
1 files 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(); |