Skip to content

Commit

Permalink
Allow disabling ScrollToTop button
Browse files Browse the repository at this point in the history
- refactor corresponding code

usage =>
in site config:
params:
    disableScrollToTop: true

closes: adityatelange#321
  • Loading branch information
adityatelange committed Mar 25, 2021
1 parent a2b3be0 commit ddf004b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
<span>&middot;</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">
<path d="M12 6H0l6-6z" />
</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)) }}
Expand All @@ -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();
Expand All @@ -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) {
Expand All @@ -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", () => {
Expand Down

0 comments on commit ddf004b

Please sign in to comment.