Skip to content

Commit

Permalink
fixes #2013
Browse files Browse the repository at this point in the history
  • Loading branch information
nelliemckesson committed Sep 14, 2021
1 parent 4bd9bcd commit 2a58a7c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
20 changes: 19 additions & 1 deletion jekyll-assets/_includes/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,26 @@ <h3 class="contentshead" onclick="expandAndCollapse(this)">{{ item.title }}</h3>
{% if item.sections[0] %}
{% if page.url == item.path %}
<div class="itemcontents" id="toc"></div>
<div class="itemcontents noJS">
<ul class="sectlevel1">
{% for entry in item.sections %}
<li>
<a href="{{ site.baseurl }}{{ item.path }}#{{ entry.anchor }}">{{ entry.heading }}</a>
{% if entry.subsections[0] %}
<ul>
{% for subentry in entry.subsections %}
<li>
<a href="{{ site.baseurl }}{{ item.path }}#{{ subentry.anchor }}">{{ subentry.heading }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
</div>
{% else %}
<div class="itemcontents hidden">
<div class="itemcontents">
<ul class="sectlevel1">
{% for entry in item.sections %}
<li>
Expand Down
2 changes: 1 addition & 1 deletion jekyll-assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ nav#contents {
}

nav#contents {
overflow-y: hidden;
overflow-y: auto;
}

nav#mobile-contents {
Expand Down
41 changes: 35 additions & 6 deletions jekyll-assets/scripts/nav.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
function addClassJS(element, myclass) {
var classes = element.className.split(" ");
console.log(classes);
var classes = element.className;
if (classes) {
classes = classes.split(" ");
} else {
classes = [];
}
var i = classes.indexOf(myclass);
if (i < 0) {
classes.push(myclass);
Expand All @@ -9,8 +13,12 @@ function addClassJS(element, myclass) {
}

function removeClassJS(element, myclass) {
var classes = element.className.split(" ");
console.log(classes);
var classes = element.className;
if (classes) {
classes = classes.split(" ");
} else {
classes = [];
}
var i = classes.indexOf(myclass);
if (i >= 0) {
classes.splice(i, 1);
Expand All @@ -21,7 +29,12 @@ function removeClassJS(element, myclass) {
function expandAndCollapse(e) {
var toExpand = e.nextElementSibling;
if (toExpand) {
var classes = toExpand.className.split(" ");
var classes = toExpand.className;
if (classes) {
classes = classes.split(" ");
} else {
classes = [];
}
var currentState = classes.indexOf("hidden");

var expanded = document.querySelectorAll('div.itemcontents:not(.hidden)');
Expand All @@ -40,7 +53,12 @@ function expandAndCollapseMobile(e) {
var toExpand = e.nextElementSibling;
var parent = e.parentNode;
if (toExpand) {
var classes = toExpand.className.split(" ");
var classes = toExpand.className;
if (classes) {
classes = classes.split(" ");
} else {
classes = [];
}
var currentState = classes.indexOf("hidden");

if (currentState > -1) {
Expand All @@ -52,3 +70,14 @@ function expandAndCollapseMobile(e) {
}
}
}

window.addEventListener('load', function() {
var tocitems = document.querySelectorAll("div.itemcontents:not(#toc)");
for (var i=0; i < tocitems.length; i++) {
addClassJS(tocitems[i], "hidden");
}
var currentItemNoJS = document.querySelectorAll("div.itemcontents.noJS");
addClassJS(currentItemNoJS, "hidden");
var contents = document.getElementById("contents");
contents.style.overflowY = 'hidden';
});

0 comments on commit 2a58a7c

Please sign in to comment.