Fix js for toc

This commit is contained in:
Ryan Watters 2017-02-14 22:29:09 -08:00
parent 7768124fb2
commit ed50c7dbd0
4 changed files with 15 additions and 14 deletions

View File

@ -1,6 +1,6 @@
--- ---
title: The Benefits of Static title: The Benefits of Static
linktitle: Benefits of Static linktitle: The Benefits of Static
description: description:
date: 2017-02-01 date: 2017-02-01
publishdate: 2017-02-01 publishdate: 2017-02-01

View File

@ -5,10 +5,9 @@ description:
date: 2017-02-01 date: 2017-02-01
publishdate: 2017-02-01 publishdate: 2017-02-01
lastmod: 2017-02-01 lastmod: 2017-02-01
tags: [wercker]
weight: weight:
draft: false draft: false
type:
layout:
slug: slug:
aliases: [] aliases: []
notes: notes:

View File

@ -1,17 +1,19 @@
//removes toc if not enough headings //removes toc if not enough headings
(function() { (function() {
let tocLinks = document.querySelectorAll('#TableOfContents > ul a'); let tocLinks = document.querySelectorAll('#TableOfContents > ul a');
if(tocLinks && tocLinks.length < 2){ let toc = document.getElementById('toc');
document.getElementById('toc').remove(); console.log(tocLinks);
}else if (tocLinks && tocLinks.length > 1){ if (toc && (tocLinks.length < 2)) {
document.getElementById('toc-toggle').addEventListener('click',toggleToc,false); toc.remove();
} else if (tocLinks.length > 1) {
document.getElementById('toc-toggle').addEventListener('click', toggleToc, false);
} }
})(); })();
function toggleToc(evt) { function toggleToc(evt) {
evt.preventDefault(); evt.preventDefault();
evt.stopPropagation(); evt.stopPropagation();
console.log("hello"); console.log("hello");
document.getElementById('toc').classList.toggle('toc-open'); document.getElementById('toc').classList.toggle('toc-open');
document.getElementById('toc-toggle').classList.toggle('toc-open'); document.getElementById('toc-toggle').classList.toggle('toc-open');
} }

File diff suppressed because one or more lines are too long