Skip to content

Commit ddf004b

Browse files
committed
Allow disabling ScrollToTop button
- refactor corresponding code usage => in site config: params: disableScrollToTop: true closes: #321
1 parent a2b3be0 commit ddf004b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

layouts/partials/footer.html

+14-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
<span>&middot;</span>
1010
<span>Theme <a href="https://git.io/hugopapermod" rel="noopener" target="_blank">PaperMod</a></span>
1111
</footer>
12+
{{- if (not .Site.Params.disableScrollToTop) }}
1213
<a href="#top" aria-label="go to top" title="Go to Top (Alt + G)">
1314
<button class="top-link" id="top-link" type="button" accesskey="g">
1415
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 6" fill="currentColor">
1516
<path d="M12 6H0l6-6z" />
1617
</svg>
1718
</button>
1819
</a>
20+
{{- end }}
1921
{{- partial "extend_footer.html" . -}}
2022
{{- $isHLJSdisabled := (.Site.Params.assets.disableHLJS | default .Params.disableHLJS ) }}
2123
{{- if (and (eq .Kind "page") (ne .Layout "archives") (ne .Layout "search") (not $isHLJSdisabled)) }}
@@ -34,6 +36,11 @@
3436
document.getElementById('menu').scrollLeft = localStorage.getItem("menu-scroll-position");
3537
}
3638
}
39+
40+
function menu_on_scroll() {
41+
localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft);
42+
}
43+
3744
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
3845
anchor.addEventListener("click", function (e) {
3946
e.preventDefault();
@@ -52,6 +59,11 @@
5259
}
5360
});
5461
});
62+
63+
</script>
64+
65+
{{- if (not .Site.Params.disableScrollToTop) }}
66+
<script>
5567
var mybutton = document.getElementById("top-link");
5668
window.onscroll = function () {
5769
if (document.body.scrollTop > 800 || document.documentElement.scrollTop > 800) {
@@ -63,11 +75,9 @@
6375
}
6476
};
6577

66-
function menu_on_scroll() {
67-
localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft);
68-
}
69-
7078
</script>
79+
{{- end }}
80+
7181
{{- if (not .Site.Params.disableThemeToggle) }}
7282
<script>
7383
document.getElementById("theme-toggle").addEventListener("click", () => {

0 commit comments

Comments
 (0)