diff --git a/CHANGELOG.md b/CHANGELOG.md index 85cd568..e43465b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://codeberg.org/daudix/duckquill/compare/v5.2.0...main) +### Added + +- Add `defer` attribute to scripts. + ### Changed - Restly the heading anchors. diff --git a/static/closable.js b/static/closable.js index 4b73bc8..dc90c3f 100644 --- a/static/closable.js +++ b/static/closable.js @@ -1,29 +1,27 @@ -document.addEventListener("DOMContentLoaded", function () { - const closable = document.querySelectorAll("details.closable"); +const closable = document.querySelectorAll("details.closable"); - closable.forEach((detail) => { - detail.addEventListener("toggle", () => { - if (detail.open) setTargetDetail(detail); - }); - }); - - function setTargetDetail(targetDetail) { - closable.forEach((detail) => { - if (detail !== targetDetail) { - detail.open = false; - } - }); - } - - document.addEventListener("click", function (event) { - const isClickInsideDetail = [...closable].some((detail) => - detail.contains(event.target) - ); - - if (!isClickInsideDetail) { - closable.forEach((detail) => { - detail.open = false; - }); - } +closable.forEach((detail) => { + detail.addEventListener("toggle", () => { + if (detail.open) setTargetDetail(detail); }); }); + +function setTargetDetail(targetDetail) { + closable.forEach((detail) => { + if (detail !== targetDetail) { + detail.open = false; + } + }); +} + +document.addEventListener("click", function (event) { + const isClickInsideDetail = [...closable].some((detail) => + detail.contains(event.target) + ); + + if (!isClickInsideDetail) { + closable.forEach((detail) => { + detail.open = false; + }); + } +}); diff --git a/static/theme-switcher.js b/static/theme-switcher.js index 0e40b8c..51b5c98 100644 --- a/static/theme-switcher.js +++ b/static/theme-switcher.js @@ -24,73 +24,71 @@ window.defaultTheme = defaultTheme; })(); -// Deferred Icon Update and Theme Switching -document.addEventListener("DOMContentLoaded", function () { - function setTheme(theme, saveToLocalStorage = false) { - if (theme === "system") { - document.documentElement.removeAttribute("data-theme"); - } else { - document.documentElement.setAttribute("data-theme", theme); - } - - if (saveToLocalStorage) { - localStorage.setItem("theme", theme); - } else { - localStorage.removeItem("theme"); - } - - // Update icon class based on the selected theme. - updateIconClass(theme); - - // Update the active button based on the selected theme. - updateActiveButton(theme); +// Icon Update and Theme Switching +function setTheme(theme, saveToLocalStorage = false) { + if (theme === "system") { + document.documentElement.removeAttribute("data-theme"); + } else { + document.documentElement.setAttribute("data-theme", theme); } - function resetTheme() { - // Reset the theme to the default or system preference if no default is set. - setTheme(window.defaultTheme || "system"); + if (saveToLocalStorage) { + localStorage.setItem("theme", theme); + } else { + localStorage.removeItem("theme"); } - function switchTheme(theme) { - if (theme === "system") { - resetTheme(); - } else { - setTheme(theme, true); - } + // Update icon class based on the selected theme. + updateIconClass(theme); + + // Update the active button based on the selected theme. + updateActiveButton(theme); +} + +function resetTheme() { + // Reset the theme to the default or system preference if no default is set. + setTheme(window.defaultTheme || "system"); +} + +function switchTheme(theme) { + if (theme === "system") { + resetTheme(); + } else { + setTheme(theme, true); } +} - function updateIconClass(theme) { - const iconElement = document.querySelector("#theme-switcher summary .icon"); +function updateIconClass(theme) { + const iconElement = document.querySelector("#theme-switcher summary .icon"); - // Remove any existing theme classes - iconElement.classList.remove("light", "dark"); + // Remove any existing theme classes + iconElement.classList.remove("light", "dark"); - // Add the appropriate class based on the selected theme - if (theme === "light") { - iconElement.classList.add("light"); - } else if (theme === "dark") { - iconElement.classList.add("dark"); - } + // Add the appropriate class based on the selected theme + if (theme === "light") { + iconElement.classList.add("light"); + } else if (theme === "dark") { + iconElement.classList.add("dark"); } +} - function updateActiveButton(theme) { - // Remove .active class from all buttons - document.querySelectorAll('#theme-switcher button').forEach(button => { - button.classList.remove('active'); - }); +function updateActiveButton(theme) { + // Remove .active class from all buttons + document.querySelectorAll('#theme-switcher button').forEach(button => { + button.classList.remove('active'); + }); - // Add .active class to the button corresponding to the current theme - const activeButton = document.querySelector(`#theme-${theme}`); - if (activeButton) { - activeButton.classList.add('active'); - } + // Add .active class to the button corresponding to the current theme + const activeButton = document.querySelector(`#theme-${theme}`); + if (activeButton) { + activeButton.classList.add('active'); } +} - // Update icon class on page load based on current theme - const currentTheme = localStorage.getItem("theme") || window.defaultTheme || "system"; - updateIconClass(currentTheme); - updateActiveButton(currentTheme); +// Update icon class on page load based on current theme +const currentTheme = localStorage.getItem("theme") || window.defaultTheme || "system"; +updateIconClass(currentTheme); +updateActiveButton(currentTheme); - // Make the switchTheme function accessible globally - window.switchTheme = switchTheme; -}); +// Make the switchTheme function accessible globally +window.switchTheme = switchTheme; diff --git a/templates/partials/head.html b/templates/partials/head.html index e70ad18..c6c6848 100644 --- a/templates/partials/head.html +++ b/templates/partials/head.html @@ -104,7 +104,7 @@ {%- if scripts | length > 0 %} {%- for script in scripts %} - + {%- endfor %} {%- endif %}