Skip to content

Navigation filter #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<div class="container-fluid">
<div class="row">
<nav class="col-12 col-md-3 col-xl-2 d-none d-md-block bg-light sidebar-sticky">
<input type="text" name="navigation-filter" id="navigation-filter">
<div id="navigation" class="sidebar-content">
</div>
</nav>
Expand All @@ -78,6 +79,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/4.3.0/anchor.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.2/highlight.min.js"></script>
<script src="/assets/js/app.js"></script>
<script src="/assets/js/navigation.js"></script>
<script src="/assets/js/search.js"></script>
</body>
</html>
11 changes: 0 additions & 11 deletions src/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,4 @@ $(() => {

// highlight.js
hljs.highlightAll();

$("#navigation").load(`${config.rootPath}navigation.html`, function() {
$(".sidebar-sticky .icon").on("click", function (e) {
$(this).siblings("ul").toggle();
this.classList.toggle("icon-opened");
});
$(`.sidebar-content a[href='${window.location.pathname}']`)
.attr("class", "active-link")
.parents('ul')
.show();
})
});
16 changes: 16 additions & 0 deletions src/assets/js/navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$(() => {
$("#navigation").load(`${config.rootPath}navigation.html`, () => {
// Toggle child lists
$(".sidebar-sticky .icon").on("click", function () {
this.classList.toggle("icon-opened");
// FIXME: use vanilla JS and CSS instead of jQuery
$(this).siblings("ul").toggle(500);
});

// Activate current page
$(`.sidebar-content a[href='${window.location.pathname}']`)
.attr("class", "active-link")
.parents('ul')
.show();
})
});