summaryrefslogtreecommitdiff
path: root/layouts
diff options
context:
space:
mode:
authorAditya Telange <21258296+adityatelange@users.noreply.github.com>2020-12-24 12:47:42 +0530
committerAditya Telange <21258296+adityatelange@users.noreply.github.com>2020-12-24 13:00:58 +0530
commit0f994eee95811f5cf6099fb5897dd62be1e6cff2 (patch)
tree964c5481e188acb05afef58ce77ebb7b0eab335e /layouts
parent7c53c14c85bd1f6ea64547d08397ba441e31f9aa (diff)
footer: change scroll behaviour as it was before 80954de
fixes #151 anchored-headings: retain anchor link '#' in URL cc #108 footer: remove '#' with go-to-top Revert "anchored-headings: retain anchor link '#' in URL" This reverts commit 80954de8bd085a3d5876e86c878088f911307c52. Revert "footer: rm unused code" This reverts commit c76233b350fde926c557e49b1a5f0bab8edddc55.
Diffstat (limited to 'layouts')
-rw-r--r--layouts/_default/baseof.html2
-rw-r--r--layouts/partials/footer.html31
2 files changed, 23 insertions, 10 deletions
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html
index 0103ffe..45cf904 100644
--- a/layouts/_default/baseof.html
+++ b/layouts/_default/baseof.html
@@ -12,7 +12,7 @@
{{- if eq $.Site.Params.defaultTheme `dark` -}}
{{- print " dark" }}
{{- end -}}
-">
+" id="top">
{{- partialCached "header.html" . .Page}}
<main class="main">
{{- block "main" . }}
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html
index 2482791..c384c4e 100644
--- a/layouts/partials/footer.html
+++ b/layouts/partials/footer.html
@@ -9,10 +9,14 @@
<span>&middot;</span>
<span>Theme <a href="https://git.io/hugopapermod" rel="noopener" target="_blank">PaperMod</a></span>
</footer>
-<button class="top-link" id="top-link" type="button" aria-label="go to top" title="Go to Top (Alt + G)" accesskey="g">
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 6">
- <path d="M12 6H0l6-6z" /></svg>
-</button>
+<a href="#top">
+ <button class="top-link" id="top-link" type="button" aria-label="go to top" title="Go to Top (Alt + G)"
+ accesskey="g">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 6">
+ <path d="M12 6H0l6-6z" />
+ </svg>
+ </button>
+</a>
{{- partial "extend_footer.html" . -}}
{{ if (and (in site.Params.mainSections .Type) (ne .Layout `archives`) (ne .Layout `search`)) }}
{{- if not .Site.Params.assets.disableFingerprinting }}
@@ -30,6 +34,20 @@
document.getElementById('menu').scrollLeft = localStorage.getItem("menu-scroll-position");
}
}
+ document.querySelectorAll('a[href^="#"]').forEach(anchor => {
+ anchor.addEventListener("click", function (e) {
+ e.preventDefault();
+ var id = this.getAttribute("href").substr(1);
+ document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView({
+ behavior: "smooth"
+ });
+ if (id === "top") {
+ history.replaceState(null, null, " ");
+ } else {
+ history.replaceState(null, null, `#${id}`);
+ }
+ });
+ });
var mybutton = document.getElementById("top-link");
window.onscroll = function () {
if (document.body.scrollTop > 800 || document.documentElement.scrollTop > 800) {
@@ -40,11 +58,6 @@
mybutton.style.opacity = "0";
}
};
- mybutton.onclick = function () {
- document.body.scrollTop = 0;
- document.documentElement.scrollTop = 0;
- window.location.hash = ''
- }
function menu_on_scroll() {
localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft);