Skip to content

Commit

Permalink
added some accessibility features.
Browse files Browse the repository at this point in the history
  • Loading branch information
w-sx committed Oct 30, 2024
1 parent 2b26d26 commit abafdbd
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{{- end }}

{{- if (not site.Params.disableScrollToTop) }}
<a href="#top" aria-label="go to top" title="Go to Top (Alt + G)" class="top-link" id="top-link" accesskey="g">
<a href="#top" title="回到顶部" class="top-link" id="top-link" accesskey="g">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 6" fill="currentColor">
<path d="M12 6H0l6-6z" />
</svg>
Expand All @@ -44,7 +44,7 @@

document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener("click", function (e) {
e.preventDefault();
//e.preventDefault();
var id = this.getAttribute("href").substr(1);
if (!window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView({
Expand All @@ -54,6 +54,7 @@
document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView();
}
if (id === "top") {
document.querySelector('a').focus();
history.replaceState(null, null, " ");
} else {
history.pushState(null, null, `#${id}`);
Expand Down Expand Up @@ -85,12 +86,18 @@
if (document.body.className.includes("dark")) {
document.body.classList.remove('dark');
localStorage.setItem("pref-theme", 'light');
document.getElementById("theme-toggle").title = '浅色模式';
} else {
document.body.classList.add('dark');
localStorage.setItem("pref-theme", 'dark');
document.getElementById("theme-toggle").title = '深色模式';
}
})

if (document.body.classList.contains('dark')) {
document.getElementById("theme-toggle").title = '深色模式';
} else {
document.getElementById("theme-toggle").title = '浅色模式';
}
</script>
{{- end }}

Expand Down Expand Up @@ -142,4 +149,4 @@
}
});
</script>
{{- end }}
{{- end }}

0 comments on commit abafdbd

Please sign in to comment.