Skip to content

Commit 7bab2d0

Browse files
lamATnginxnginx-jack
authored andcommitted
feat: added JS to automatically open sidebar v2 to current page
1 parent c9d2c3a commit 7bab2d0

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

assets/js/sidebar-v2.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
document.addEventListener("DOMContentLoaded", function() {
2+
function expandToCurrentPage() {
3+
var currentPage = document.getElementById("current-page");
4+
if (currentPage) {
5+
var parentLabel = currentPage.closest("li");
6+
while (parentLabel) {
7+
var checkbox = parentLabel.querySelector(".toggle-checkbox");
8+
if (checkbox) {
9+
checkbox.checked = true;
10+
}
11+
parentLabel = parentLabel.closest("ul").closest("li");
12+
}
13+
}
14+
}
15+
16+
expandToCurrentPage();
17+
})

layouts/partials/scripts.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@
6868
<!-- Load Product Selector javascript -->
6969
{{ $jsProductSelector := resources.Get "js/product-selector.js" | minify | fingerprint "sha512" }}
7070
<script src="{{ $jsProductSelector.RelPermalink }}" type="text/javascript" integrity="{{ $jsProductSelector.Data.Integrity }}"></script>
71+
72+
<!-- Load Sidebar v2 javascript -->
73+
{{ $jsSidebarV2 := resources.Get "js/sidebar-v2.js" | minify | fingerprint "sha512" }}
74+
<script src="{{ $jsSidebarV2.RelPermalink }}" type="text/javascript" integrity="{{ $jsSidebarV2.Data.Integrity }}"></script>

layouts/partials/sidebar-list-pages.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
{{ partial "sidebar-list-pages.html" (dict "context" . "currentUrl" $currentUrl) }}
1616
{{ else if eq .Kind "page" }}
1717
{{ if eq $currentUrl .Permalink }}
18-
<span class="box current partial"></span>
18+
<span class="box current partial" id="current-page"></span>
1919
{{ else }}
2020
<span class="box-link partial"></span>
2121
{{ end }}

layouts/partials/sidebar-v2.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<ul>
3838
{{ range $products }}
3939
<li>
40-
<a href="{{ .url }}" target="_blank">{{ .title }}</a>
40+
<a href="{{ .url }}">{{ .title }}</a>
4141
</li>
4242
{{ end }}
4343
</ul>

0 commit comments

Comments
 (0)