mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2024-11-27 12:03:49 +01:00
dda55f87e2
* fix: take out [data-scheme="dark"] from :root Taking out the [data-scheme="dark"] from :root allows us to fix the precedence of CSS when the [data-scheme="dark"] is placed in the <html> tag. This is needed in order to make the dark styles accesible from the <html> elment, this will allow us to change the vertical scrollbar styles following the dark and light schemes. * change document.body.dataset.scheme to document.documentElement.dataset.scheme When the dark mode is on or when the light mode is on, the [data-scheme="light"] or [data-scheme="dark"], respectively, will be placed in the <html> tag. Allowing us to access the dark and light color schemes from the <html> to change the vertical scrollbar styles according to the current color scheme. * feat: change the page vertical scrollbar styles This change will make the vertical scrollbar styles to follow the dark and light color scheme modes. Also, this change will make the vertical scrollbar to look consistent in both, Chromium and Firefox. * make the scrollbar-track background-color transparent The body has this transition: 'transition: background-color 0.3s ease 0s'. Making the scrollbar-track background-color transparent allow us to appreciate that transition in the scrollbar-track when switching the background-color. * Move [data-scheme=dark] back to :root block * fix(comment/waline): detect dark mode from html tag * feat: apply custom scrollbar style to all elements Co-authored-by: Jimmy Cai <jimmehcai@gmail.com>
39 lines
1.4 KiB
HTML
39 lines
1.4 KiB
HTML
{{- $defaultColorScheme := default "auto" .Site.Params.colorScheme.default -}}
|
|
{{- if not (default false .Site.Params.colorScheme.toggle) -}}
|
|
{{/* If toggle is disabled, force default scheme */}}
|
|
<script>
|
|
(function() {
|
|
const colorSchemeKey = 'StackColorScheme';
|
|
localStorage.setItem(colorSchemeKey, "{{ $defaultColorScheme }}");
|
|
})();
|
|
</script>
|
|
{{- else -}}
|
|
{{/* Otherwise set to default scheme only if no preference is set by user */}}
|
|
<script>
|
|
(function() {
|
|
const colorSchemeKey = 'StackColorScheme';
|
|
if(!localStorage.getItem(colorSchemeKey)){
|
|
localStorage.setItem(colorSchemeKey, "{{ $defaultColorScheme }}");
|
|
}
|
|
})();
|
|
</script>
|
|
{{- end -}}
|
|
|
|
<script>
|
|
(function() {
|
|
const colorSchemeKey = 'StackColorScheme';
|
|
const colorSchemeItem = localStorage.getItem(colorSchemeKey);
|
|
const supportDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches === true;
|
|
|
|
if (colorSchemeItem == 'dark' || colorSchemeItem === 'auto' && supportDarkMode) {
|
|
/**
|
|
* Enable dark mode if:
|
|
* 1. If dark mode is set already (in local storage)
|
|
* 2. Auto mode & prefere color scheme is dark
|
|
*/
|
|
document.documentElement.dataset.scheme = 'dark';
|
|
} else {
|
|
document.documentElement.dataset.scheme = 'light';
|
|
}
|
|
})();
|
|
</script>
|