-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22343 from hawkeye116477/gh-pages
Improve website
- Loading branch information
Showing
26 changed files
with
669 additions
and
783 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,77 @@ | ||
/*! | ||
* Color mode toggler for Bootstrap's docs (https://getbootstrap.com/) | ||
* Copyright 2011-2022 The Bootstrap Authors | ||
* Licensed under the Creative Commons Attribution 3.0 Unported License. | ||
* Modified by hawkeye116477 | ||
*/ | ||
|
||
(() => { | ||
'use strict' | ||
|
||
const storedTheme = localStorage.getItem('theme'); | ||
const oldStoredTheme = localStorage.getItem('darkSwitch'); | ||
|
||
const getPreferredTheme = () => { | ||
if (oldStoredTheme) { | ||
localStorage.setItem("theme", oldStoredTheme); | ||
localStorage.removeItem("darkSwitch"); | ||
return oldStoredTheme; | ||
} | ||
else if (storedTheme) { | ||
return storedTheme; | ||
} | ||
else { | ||
return "auto"; | ||
} | ||
} | ||
|
||
const setTheme = function (theme) { | ||
if (theme === 'auto') { | ||
document.documentElement.setAttribute('data-bs-theme', (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) | ||
} else { | ||
document.documentElement.setAttribute('data-bs-theme', theme) | ||
} | ||
} | ||
|
||
setTheme(getPreferredTheme()) | ||
|
||
const showActiveTheme = theme => { | ||
const activeSelectors = document.querySelectorAll('.theme-icon-active') | ||
const activeButtons = document.querySelectorAll(`[data-bs-theme-value="${theme}"]`) | ||
if (activeButtons.length > 0) { | ||
const activeIcon = activeButtons[0].querySelector('span') | ||
|
||
document.querySelectorAll('[data-bs-theme-value]').forEach(element => { | ||
element.classList.remove('active') | ||
}) | ||
|
||
for (let i = 0; i < activeSelectors.length; ++i) { | ||
activeSelectors[i].innerHTML = activeIcon.innerHTML | ||
} | ||
|
||
for (let i = 0; i < activeButtons.length; ++i) { | ||
activeButtons[i].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) | ||
}) | ||
}) | ||
}) | ||
})() |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.