-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
2,440 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
}); | ||
} | ||
})(); |
Oops, something went wrong.