mirror of
https://github.com/Wonderfall/hugo-WonderMod.git
synced 2024-11-21 18:11:37 +01:00
Allow disabling ScrollToTop button
- refactor corresponding code usage => in site config: params: disableScrollToTop: true closes: #321
This commit is contained in:
parent
a2b3be0169
commit
ddf004b709
@ -9,6 +9,7 @@
|
||||
<span>·</span>
|
||||
<span>Theme <a href="https://git.io/hugopapermod" rel="noopener" target="_blank">PaperMod</a></span>
|
||||
</footer>
|
||||
{{- if (not .Site.Params.disableScrollToTop) }}
|
||||
<a href="#top" aria-label="go to top" title="Go to Top (Alt + G)">
|
||||
<button class="top-link" id="top-link" type="button" accesskey="g">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 6" fill="currentColor">
|
||||
@ -16,6 +17,7 @@
|
||||
</svg>
|
||||
</button>
|
||||
</a>
|
||||
{{- end }}
|
||||
{{- partial "extend_footer.html" . -}}
|
||||
{{- $isHLJSdisabled := (.Site.Params.assets.disableHLJS | default .Params.disableHLJS ) }}
|
||||
{{- if (and (eq .Kind "page") (ne .Layout "archives") (ne .Layout "search") (not $isHLJSdisabled)) }}
|
||||
@ -34,6 +36,11 @@
|
||||
document.getElementById('menu').scrollLeft = localStorage.getItem("menu-scroll-position");
|
||||
}
|
||||
}
|
||||
|
||||
function menu_on_scroll() {
|
||||
localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft);
|
||||
}
|
||||
|
||||
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
||||
anchor.addEventListener("click", function (e) {
|
||||
e.preventDefault();
|
||||
@ -52,6 +59,11 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
{{- if (not .Site.Params.disableScrollToTop) }}
|
||||
<script>
|
||||
var mybutton = document.getElementById("top-link");
|
||||
window.onscroll = function () {
|
||||
if (document.body.scrollTop > 800 || document.documentElement.scrollTop > 800) {
|
||||
@ -63,11 +75,9 @@
|
||||
}
|
||||
};
|
||||
|
||||
function menu_on_scroll() {
|
||||
localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft);
|
||||
}
|
||||
|
||||
</script>
|
||||
{{- end }}
|
||||
|
||||
{{- if (not .Site.Params.disableThemeToggle) }}
|
||||
<script>
|
||||
document.getElementById("theme-toggle").addEventListener("click", () => {
|
||||
|
Loading…
Reference in New Issue
Block a user