Skip to content
New issue

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

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

Already on GitHub? # to your account

added JS to automatically open sidebar v2 to current page #118

Merged
merged 5 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
17 changes: 17 additions & 0 deletions assets/js/sidebar-v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
document.addEventListener("DOMContentLoaded", function() {
function expandToCurrentPage() {
const currentPage = document.getElementById("current-page");
if (currentPage) {
let parentLabel = currentPage.closest("li");
while (parentLabel) {
var checkbox = parentLabel.querySelector(".toggle-checkbox");
nginx-jack marked this conversation as resolved.
Show resolved Hide resolved
nginx-jack marked this conversation as resolved.
Show resolved Hide resolved
if (checkbox) {
checkbox.checked = true;
}
parentLabel = parentLabel.closest("ul").closest("li");
}
}
}

expandToCurrentPage();
})
4 changes: 4 additions & 0 deletions layouts/partials/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@
<!-- Load Product Selector javascript -->
{{ $jsProductSelector := resources.Get "js/product-selector.js" | minify | fingerprint "sha512" }}
<script src="{{ $jsProductSelector.RelPermalink }}" type="text/javascript" integrity="{{ $jsProductSelector.Data.Integrity }}"></script>

<!-- Load Sidebar v2 javascript -->
{{ $jsSidebarV2 := resources.Get "js/sidebar-v2.js" | minify | fingerprint "sha512" }}
<script src="{{ $jsSidebarV2.RelPermalink }}" type="text/javascript" integrity="{{ $jsSidebarV2.Data.Integrity }}"></script>
2 changes: 1 addition & 1 deletion layouts/partials/sidebar-list-pages.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{{ partial "sidebar-list-pages.html" (dict "context" . "currentUrl" $currentUrl) }}
{{ else if eq .Kind "page" }}
{{ if eq $currentUrl .Permalink }}
<span class="box current partial"></span>
<span class="box current partial" id="current-page"></span>
{{ else }}
<span class="box-link partial"></span>
{{ end }}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/sidebar-v2.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<ul>
{{ range $products }}
<li>
<a href="{{ .url }}" target="_blank">{{ .title }}</a>
<a href="{{ .url }}">{{ .title }}</a>
</li>
{{ end }}
</ul>
Expand Down