Sha256: 5006582664c9cc26e7804d75b12f97e3e7878432e0a45b50c1ff7313119a6425

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

(function () {
  const themeSelector = document.getElementById("themeSelector");
  const themeOptions = document.getElementById("themeOptions");
  const root = document.querySelector("html");

  function clickHandler(color) {
    return (event) => {
      const mode = root.className.split("-")[0];
      const newTheme = `${mode}-${color.split("-")[1]}`;
      window.localStorage.setItem("theme", newTheme);
      root.className = newTheme;
      const selectedColor = event.target.getAttribute("data-color");
    };
  }

  themeSelector.addEventListener("click", () => {
    themeOptions.style.maxWidth = !themeOptions.style.maxWidth
      ? "800px"
      : themeOptions.style.maxWidth === "0px"
      ? "800px"
      : "0px";
    themeOptions.style.paddingTop =
      themeOptions.style.maxWidth !== "0px" ? "50px" : "0px";
  });

  document.querySelectorAll(".theme-option").forEach((option) => {
    option.addEventListener("click", clickHandler(option.dataset.themeClass));
  });

  const darkModeToggle = document.getElementById("darkModeToggle");

  darkModeToggle.checked = theme.startsWith("dark") ? true : false;
  darkModeToggle.addEventListener("change", () => {
    let activeMode = root.className;
    if (activeMode.startsWith("dark")) {
      activeMode = root.className.replace("dark", "light");
    } else {
      activeMode = root.className.replace("light", "dark");
    }
    root.className = activeMode;
    window.localStorage.setItem("theme", activeMode);
  });
})();

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jekyll-theme-doodle-5.1.5 assets/theme-assets/js/theme.js
jekyll-theme-doodle-5.1.3 assets/theme-assets/js/theme.js