-
Notifications
You must be signed in to change notification settings - Fork 922
/
Copy pathsidebar.html
38 lines (37 loc) · 1.65 KB
/
sidebar.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<script>
/* Persist the scroll position of the section menu. See Docsy issue #257. */
function persistScrollPosition() {
var a = document.querySelector("#td-section-nav");
addEventListener("beforeunload", function() {
localStorage.setItem("menu.scrollTop", a.scrollTop)
});
a.scrollTop = localStorage.getItem("menu.scrollTop");
}
</script>
{{/* The "active" toggle here may delay rendering, so we only cache this side bar menu for bigger sites. */ -}}
{{ $sidebarCacheLimit := .Site.Params.ui.sidebar_cache_limit | default 2000 -}}
{{ $shouldCache := ge (len .Site.Pages) $sidebarCacheLimit -}}
{{ $sidebarCacheTypeRoot := .Site.Params.ui.sidebar_cache_type_root | default false -}}
{{ if $shouldCache -}}
{{ $mid := printf "m-%s" (.RelPermalink | anchorize) }}
<script>
$(function() {
$("#td-section-nav a").removeClass("active");
$("#td-section-nav #{{ $mid }}").addClass("active");
$("#td-section-nav #{{ $mid }}-li span").addClass("td-sidebar-nav-active-item");
$("#td-section-nav #{{ $mid }}").parents("li").addClass("active-path");
$("#td-section-nav li.active-path").addClass("show");
$("#td-section-nav li.active-path").children("input").prop('checked', true);
$("#td-section-nav #{{ $mid }}-li").siblings("li").addClass("show");
$("#td-section-nav #{{ $mid }}-li").children("ul").children("li").addClass("show");
$("#td-sidebar-menu").toggleClass("d-none");
persistScrollPosition();
});
</script>
{{ partialCached "sidebar-tree.html" . .FirstSection.RelPermalink }}
{{ else -}}
{{ partial "sidebar-tree.html" . }}
<script>
persistScrollPosition();
</script>
{{- end }}