Add fragment IDs to site FAQs

This commit is contained in:
hensm
2019-09-25 16:16:29 +01:00
parent 33f58e5a95
commit 1917c273be
2 changed files with 20 additions and 0 deletions

View File

@@ -1,5 +1,19 @@
"use strict";
// Set FAQ fragment IDs
for (const faq of document.querySelectorAll(".faq")) {
const summary = faq.querySelector(".faq__summary");
const formattedSummary = summary.textContent.trim().replace(/ /g, "_");
faq.id = formattedSummary;
if (window.location.hash) {
faq.open = decodeURIComponent(
window.location.hash.slice(1)) === formattedSummary;
}
}
function updateThemeClass (mediaQuery) {
if (mediaQuery.matches) {
document.documentElement.classList.remove("theme-dark");