diff options
| author | rtkay123 <dev@kanjala.com> | 2025-11-23 10:22:38 +0200 |
|---|---|---|
| committer | rtkay123 <dev@kanjala.com> | 2025-11-23 10:22:38 +0200 |
| commit | 7f65b47bfb333632c87927c38b90918bedcf5eae (patch) | |
| tree | 43cac6b698ae7bc88f4a51256d15aac10ea744ac /docs/book/mermaid-init.js | |
| parent | 56a3de7433c2a1735df19f79b9e7c185ef456f88 (diff) | |
| download | sellershut-7f65b47bfb333632c87927c38b90918bedcf5eae.tar.bz2 sellershut-7f65b47bfb333632c87927c38b90918bedcf5eae.zip | |
docs: book
Diffstat (limited to 'docs/book/mermaid-init.js')
| -rw-r--r-- | docs/book/mermaid-init.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/docs/book/mermaid-init.js b/docs/book/mermaid-init.js new file mode 100644 index 0000000..0469ff1 --- /dev/null +++ b/docs/book/mermaid-init.js @@ -0,0 +1,39 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +(() => { + 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(); + } + }); + } +})(); |
