diff options
author | rtkay123 <dev@kanjala.com> | 2025-08-08 06:58:06 +0200 |
---|---|---|
committer | rtkay123 <dev@kanjala.com> | 2025-08-08 06:58:06 +0200 |
commit | 98c42ac8a5a2f129e6d0f63f550fefdc9a868daf (patch) | |
tree | dca6b0cfa27b9d0f21d1c61011f88b604936600c /docs/book/mermaid-init.js | |
parent | a05316c51f9ca3bfeb8b587b27275816cab19d48 (diff) | |
download | warden-98c42ac8a5a2f129e6d0f63f550fefdc9a868daf.tar.bz2 warden-98c42ac8a5a2f129e6d0f63f550fefdc9a868daf.zip |
docs: book
Diffstat (limited to 'docs/book/mermaid-init.js')
-rw-r--r-- | docs/book/mermaid-init.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/docs/book/mermaid-init.js b/docs/book/mermaid-init.js new file mode 100644 index 0000000..15a7f4e --- /dev/null +++ b/docs/book/mermaid-init.js @@ -0,0 +1,35 @@ +(() => { + const darkThemes = ['ayu', 'navy', 'coal']; + const lightThemes = ['light', 'rust']; + + const classList = document.getElementsByTagName('html')[0].classList; + + let lastThemeWasLight = true; + for (const cssClass of classList) { + if (darkThemes.includes(cssClass)) { + lastThemeWasLight = false; + break; + } + } + + const theme = lastThemeWasLight ? 'default' : 'dark'; + mermaid.initialize({ startOnLoad: true, theme }); + + // Simplest way to make mermaid re-render the diagrams in the new theme is via refreshing the page + + for (const darkTheme of darkThemes) { + document.getElementById(darkTheme).addEventListener('click', () => { + if (lastThemeWasLight) { + window.location.reload(); + } + }); + } + + for (const lightTheme of lightThemes) { + document.getElementById(lightTheme).addEventListener('click', () => { + if (!lastThemeWasLight) { + window.location.reload(); + } + }); + } +})(); |