Skip to content

Commit 2055353

Browse files
committed
Updated themes to stay on the theme that the user has set
1 parent cdf1369 commit 2055353

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

docs/script.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,39 @@ const rowsPerPage = 10;
77
// Dark mode toggle
88
const darkModeToggle = document.getElementById('darkModeToggle');
99
darkModeToggle.addEventListener('click', () => {
10+
const isDarkMode = document.body.classList.contains('bg-gray-900');
11+
12+
// Toggle classes
1013
document.body.classList.toggle('bg-gray-900');
1114
document.body.classList.toggle('text-white');
1215
const cards = document.querySelectorAll('.bg-white');
1316
cards.forEach(card => {
1417
card.classList.toggle('bg-gray-800');
1518
card.classList.toggle('text-white');
1619
});
17-
18-
// Update glossary section colors
1920
const glossary = document.getElementById('infoBar');
2021
glossary.classList.toggle('bg-gray-800');
2122
glossary.classList.toggle('text-white');
23+
24+
// Save state to localStorage
25+
localStorage.setItem('darkMode', isDarkMode ? 'disabled' : 'enabled');
2226
});
2327

28+
// Handle Theme state
29+
function initializeTheme() {
30+
const isDarkMode = localStorage.getItem('darkMode') === 'enabled';
31+
32+
if (isDarkMode) {
33+
document.body.classList.add('bg-gray-900', 'text-white');
34+
const cards = document.querySelectorAll('.bg-white');
35+
cards.forEach(card => {
36+
card.classList.add('bg-gray-800', 'text-white');
37+
});
38+
const glossary = document.getElementById('infoBar');
39+
glossary.classList.add('bg-gray-800', 'text-white');
40+
}
41+
}
42+
2443
// Data Glossary Toggle
2544
const infoHeader = document.getElementById('infoHeader');
2645
const expandButton = document.getElementById('expandButton');
@@ -1096,8 +1115,13 @@ document.addEventListener('DOMContentLoaded', () => {
10961115
document.getElementById('refreshData').addEventListener('click', fetchData);
10971116

10981117
// Data Glossary Toggle
1118+
const infoHeader = document.getElementById('infoHeader');
1119+
const expandButton = document.getElementById('expandButton');
10991120
if (infoHeader && expandButton) {
11001121
infoHeader.addEventListener('click', toggleGlossary);
11011122
expandButton.addEventListener('click', toggleGlossary);
11021123
}
1124+
1125+
// Initialize theme from localStorage
1126+
initializeTheme();
11031127
});

0 commit comments

Comments
 (0)