zk_html/index.html

61 lines
1.8 KiB
HTML

<!doctype html>
<html>
<head>
<title>Zk | Home</title>
<link rel="stylesheet" type="text/css" href="/style.css" />
<meta name="viewport" content="width=device-width" />
<meta charset="utf-8" />
</head>
<body>
<main>
<header>
<h1>Zk | Home</h1>
</header>
<article class="content">
<ul>
<li><a href="writing/index.html">Writing</a></li>
<li><a href="tech/index.html">Tech</a></li>
<li><a href="diary/diary.html">Diary</a></li>
<li><a href="stream.html">Stream notes</a></li>
</ul>
<span class="control">Expand all</span>
</article>
<footer>
<p>Page generated on 2020-04-21</p>
</footer>
</main>
<script type="text/javascript">
document.querySelectorAll('li').forEach(el => {
if (el.querySelectorAll('li').length !== 0) {
el.classList.add('has-nested', 'closed');
el.innerHTML = `<span class="toggle"></span> ${el.innerHTML}`;
}
});
document.querySelectorAll('.toc .has-nested').forEach(el => {
el.classList.remove('has-nested', 'closed');
});
document.querySelectorAll('li.has-nested').forEach(el => {
el.querySelector('.toggle').addEventListener('click', () => {
el.classList.toggle('closed');
});
});
let expanded = false;
document.querySelector('.control').addEventListener('click', (e) => {
expanded = !expanded;
if (expanded) {
e.target.innerText = 'Collapse all';
} else {
e.target.innerText = 'Expand all';
}
document.querySelectorAll('.has-nested').forEach((el) => {
if (expanded) {
el.classList.remove('closed');
} else {
el.classList.add('closed')
}
});
});
</script>
</body>
</html>