Added color theme toggle and saving as preference
into localStorage
This commit is contained in:
@@ -95,6 +95,11 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/js/bootstrap.min.js" integrity="sha384-RuyvpeZCxMJCqVUGFI0Do1mQrods/hhxYlcVfGPOfQtPJh0JCw12tUAZ/Mv10S7D" crossorigin="anonymous"></script>
|
||||
<script defer>
|
||||
const saved_color_theme = localStorage.getItem('saved_color_theme');
|
||||
if (saved_color_theme) {
|
||||
document.documentElement.setAttribute('data-bs-theme', saved_color_theme);
|
||||
}
|
||||
|
||||
document.getElementById("categories_toggle").onclick = function() {
|
||||
categories_menu_item = document.getElementById("categories_menu");
|
||||
if (categories_menu_item.style.display == "none") {
|
||||
@@ -106,8 +111,10 @@
|
||||
};
|
||||
document.getElementById("dark_theme_toggle").onclick = function() {
|
||||
html = document.documentElement;
|
||||
html_color_theme = html.getAttribute('data-bs-theme');
|
||||
html.setAttribute('data-bs-theme', html_color_theme === 'dark' ? 'light' : 'dark')
|
||||
current_color_theme = html.getAttribute('data-bs-theme');
|
||||
new_color_theme = current_color_theme === 'dark' ? 'light' : 'dark';
|
||||
html.setAttribute('data-bs-theme', new_color_theme);
|
||||
localStorage.setItem('saved_color_theme', new_color_theme);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user