[ci skip] Automated deployment to GitHub Pages on 1680299752521
This commit is contained in:
commit
393c7f862b
135 changed files with 21650 additions and 0 deletions
58
theme/dark-theme/dark-theme.js
Normal file
58
theme/dark-theme/dark-theme.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
function ThemeManager(options) {
|
||||
var defaultTheme = options.defaultTheme;
|
||||
var enableAutoDetectTheme = options.enableAutoDetectTheme.toLowerCase() === 'true';
|
||||
|
||||
var darkThemeMatch = window.matchMedia(
|
||||
defaultTheme === 'light' ?
|
||||
'(prefers-color-scheme: dark)' :
|
||||
'(prefers-color-scheme: dark), (prefers-color-scheme: no-preference)'
|
||||
);
|
||||
|
||||
function setEnabledAndDisableMediaQuery(elementId, enabled) {
|
||||
var element = document.getElementById(elementId);
|
||||
element.disabled = !enabled;
|
||||
element.media = '';
|
||||
}
|
||||
|
||||
function detectThemeAndSwitchStyle() {
|
||||
var theme = localStorage.getItem('themeOverride');
|
||||
if (theme !== 'light' && theme !== 'dark') {
|
||||
if (theme === 'browser' || enableAutoDetectTheme) {
|
||||
theme = darkThemeMatch.matches ? 'dark' : 'light';
|
||||
} else {
|
||||
theme = defaultTheme;
|
||||
}
|
||||
}
|
||||
|
||||
// (Dis|En)able the styles according to the user's desired theme. Get rid
|
||||
// of the media queries, since we are handling it in JS.
|
||||
setEnabledAndDisableMediaQuery('dark-theme-style', theme === 'dark');
|
||||
setEnabledAndDisableMediaQuery('pygments-dark-theme', theme === 'dark');
|
||||
setEnabledAndDisableMediaQuery('pygments-light-theme', theme === 'light');
|
||||
|
||||
if (theme === 'dark') {
|
||||
document.body.classList.add('dark-theme');
|
||||
document.body.classList.remove('light-theme');
|
||||
} else {
|
||||
document.body.classList.add('light-theme');
|
||||
document.body.classList.remove('dark-theme');
|
||||
}
|
||||
}
|
||||
|
||||
this.switch = function(themeOverride) {
|
||||
localStorage.setItem('themeOverride', themeOverride);
|
||||
detectThemeAndSwitchStyle();
|
||||
};
|
||||
|
||||
// If there's an override, then apply it, otherwise, don't incur the
|
||||
// overhead of determining whether or not to switch themes.
|
||||
var themeOverride = localStorage.getItem('themeOverride');
|
||||
if (themeOverride === 'light' || themeOverride === 'dark') {
|
||||
detectThemeAndSwitchStyle();
|
||||
}
|
||||
|
||||
// If theme auto-detection is enabled, then add a listenr on the matchMedia.
|
||||
darkThemeMatch.addListener(detectThemeAndSwitchStyle);
|
||||
}
|
||||
|
||||
window.theme = new ThemeManager(document.getElementById('dark-theme-script').dataset);
|
1
theme/dark-theme/dark-theme.min.js
vendored
Normal file
1
theme/dark-theme/dark-theme.min.js
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
function ThemeManager(e){var t=e.defaultTheme,r="true"===e.enableAutoDetectTheme.toLowerCase(),a=window.matchMedia("light"===t?"(prefers-color-scheme: dark)":"(prefers-color-scheme: dark), (prefers-color-scheme: no-preference)");function d(e,t){e=document.getElementById(e);e.disabled=!t,e.media=""}function m(){var e=localStorage.getItem("themeOverride");d("dark-theme-style","dark"===(e="light"!==e&&"dark"!==e?"browser"===e||r?a.matches?"dark":"light":t:e)),d("pygments-dark-theme","dark"===e),d("pygments-light-theme","light"===e),"dark"===e?(document.body.classList.add("dark-theme"),document.body.classList.remove("light-theme")):(document.body.classList.add("light-theme"),document.body.classList.remove("dark-theme"))}this.switch=function(e){localStorage.setItem("themeOverride",e),m()};e=localStorage.getItem("themeOverride");"light"!==e&&"dark"!==e||m(),a.addListener(m)}window.theme=new ThemeManager(document.getElementById("dark-theme-script").dataset);
|
Loading…
Add table
Add a link
Reference in a new issue