-
Notifications
You must be signed in to change notification settings - Fork 168
Dark Mode #2730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Dark Mode #2730
Changes from 3 commits
27bacf3
48aba54
2a6f37c
0c8170d
4783ce9
2c8a249
4babe91
d97acaf
e0f93f4
aca2b16
cd73639
02e5ee2
fa6c817
3f320ad
97ce9e1
397aea0
28ddcf0
56bc3b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /*! | ||
| * Adapted color mode toggler from Bootstrap's docs (https://getbootstrap.com/) | ||
| */ | ||
|
|
||
| (() => { | ||
| 'use strict' | ||
|
|
||
| const storedTheme = localStorage.getItem('theme') | ||
|
|
||
| const getPreferredTheme = () => { | ||
| console.log("getPreferredTheme"); | ||
| if (storedTheme) { | ||
| return storedTheme | ||
| } | ||
|
|
||
| return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light' | ||
| } | ||
|
|
||
| const setTheme = function (theme) { | ||
| console.log("setTheme"); | ||
| console.log(theme); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove these, I think the document.setAttribute below should always work and not trigger too many debugging scenarios (applies to all |
||
| /*if (theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches) { | ||
| document.documentElement.setAttribute('data-bs-theme', 'dark') | ||
| } else {*/ | ||
| document.documentElement.setAttribute('data-bs-theme', theme) | ||
| //} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commented code (repeated below) |
||
| } | ||
|
|
||
| setTheme(getPreferredTheme()) | ||
|
|
||
| const showActiveTheme = theme => { | ||
| console.log("showActiveTheme"); | ||
| console.log(theme); | ||
| const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`) | ||
|
|
||
| document.querySelectorAll('[data-bs-theme-value]').forEach(element => { | ||
| element.classList.remove('active') | ||
| }) | ||
|
|
||
| btnToActive.classList.add('active') | ||
| } | ||
|
|
||
| /* window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { | ||
| if (storedTheme !== 'light' || storedTheme !== 'dark') { | ||
| setTheme(getPreferredTheme()) | ||
| } | ||
| })*/ | ||
|
|
||
| window.addEventListener('DOMContentLoaded', () => { | ||
| showActiveTheme(getPreferredTheme()) | ||
|
|
||
| document.querySelectorAll('[data-bs-theme-value]') | ||
| .forEach(toggle => { | ||
| toggle.addEventListener('click', () => { | ||
| const theme = toggle.getAttribute('data-bs-theme-value') | ||
| localStorage.setItem('theme', theme) | ||
| setTheme(theme) | ||
| showActiveTheme(theme) | ||
| }) | ||
| }) | ||
| }) | ||
| })() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing trailing newline |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this about? This reads like copyright trouble