Page indicator in navigation bar

This commit is contained in:
Nuno Coração
2023-01-14 23:50:34 +00:00
parent 3a81b0a741
commit a194975889
10 changed files with 88 additions and 35 deletions

View File

@@ -18,8 +18,9 @@
{{ .TableOfContents | emojify }}
</div>
</details>
<script>
{{ if .Site.Params.smartTOC }}
<script>
(function () {
var $toc = $('#TableOfContents');
if ($toc.length > 0) {
@@ -31,27 +32,34 @@
var id = "";
h.each(function (i, e) {
e = $(e);
if (e.offset().top - $(window).height()/2 <= currentScroll) {
if (e.offset().top - $(window).height()/3 <= currentScroll) {
id = e.attr('id');
}
});
var active = $toc.find('a.active');
if (active.length == 1 && active.eq(0).attr('href') == '#' + id) return true;
active.each(function (i, e) {
$(e).removeClass('active').siblings('ul').hide();
{{ if .Site.Params.smartTOCHideUnfocusedChildren }}
$(e).removeClass('active').siblings('ul').hide();
{{ else }}
$(e).removeClass('active');
{{ end }}
});
$toc.find('a[href="#' + id + '"]').addClass('active')
$toc.find('a[href="#' + id + '"]').parentsUntil('#TableOfContents').each(function (i, e) {
console.log($(e).children('a'))
$(e).children('a').addClass('active').parents('ul').show();
$(e).children('a').parents('ul').show();
});
}
$window.on('scroll', onScroll);
$(document).ready(function () {
$toc.find('a').parent('li').find('ul').hide();
{{ if .Site.Params.smartTOCHideUnfocusedChildren }}
$toc.find('a').parent('li').find('ul').hide();
{{ end }}
onScroll();
});
}
})();
</script>
</script>
{{ end }}