Update extra.js (#17705)

pull/17706/head
Glenn Jocher 3 days ago committed by GitHub
parent d670bcc2b9
commit 1907095963
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      .github/workflows/docs.yml
  2. 46
      docs/overrides/javascript/extra.js

@ -48,7 +48,7 @@ jobs:
python-version: "3.x"
- uses: astral-sh/setup-uv@v3
- name: Install Dependencies
run: uv pip install --system ruff black tqdm minify-html mkdocs-material "mkdocstrings[python]" mkdocs-jupyter mkdocs-redirects mkdocs-ultralytics-plugin mkdocs-macros-plugin
run: uv pip install --system ruff black tqdm mkdocs-material "mkdocstrings[python]" mkdocs-jupyter mkdocs-redirects mkdocs-ultralytics-plugin mkdocs-macros-plugin
- name: Ruff fixes
continue-on-error: true
run: ruff check --fix --unsafe-fixes --select D --ignore=D100,D104,D203,D205,D212,D213,D401,D406,D407,D413 .

@ -1,39 +1,25 @@
// Light/Dark Mode -----------------------------------------------------------------------------------------------------
const applyTheme = (isDark) => {
document.body.setAttribute(
"data-md-color-scheme",
isDark ? "slate" : "default",
);
document.body.setAttribute(
"data-md-color-primary",
isDark ? "black" : "indigo",
);
// Apply theme colors based on dark/light mode -------------------------------------------------------------------------
document.body.setAttribute('data-md-color-scheme', isDark ? 'slate' : 'default');
document.body.setAttribute('data-md-color-primary', isDark ? 'black' : 'indigo');
};
// Check and apply auto theme
const checkAutoTheme = () => {
const palette = JSON.parse(localStorage.getItem(".__palette") || "{}");
if (palette.index === 0) {
applyTheme(window.matchMedia("(prefers-color-scheme: dark)").matches);
// Check and apply appropriate theme based on system/user preference
const checkTheme = () => {
const palette = JSON.parse(localStorage.getItem('.__palette') || '{}');
if (palette.index === 0) { // Auto mode is selected
applyTheme(window.matchMedia('(prefers-color-scheme: dark)').matches);
}
};
// Event listeners for theme changes
const mediaQueryList = window.matchMedia("(prefers-color-scheme: dark)");
mediaQueryList.addListener(checkAutoTheme);
// Initial theme check
checkAutoTheme();
// Watch for system theme changes
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', checkTheme);
// Auto theme input listener
document.addEventListener("DOMContentLoaded", () => {
const autoThemeInput = document.getElementById("__palette_1");
autoThemeInput?.addEventListener("click", () => {
if (autoThemeInput.checked) {
setTimeout(checkAutoTheme);
}
});
// Initialize theme handling on page load
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('__palette_1')?.addEventListener('change', e =>
e.target.checked && setTimeout(checkTheme)
);
checkTheme();
});
// Inkeep --------------------------------------------------------------------------------------------------------------

Loading…
Cancel
Save