Fix: Add null check for theme toggle button in script.js
- Prevents errors when theme toggle button is not present on page - Ensures theme toggle works reliably on all pages that load script.js
This commit is contained in:
@@ -35,10 +35,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
// Helper function to update the theme toggle button text
|
// Helper function to update the theme toggle button text
|
||||||
function updateThemeToggleButtonText() {
|
function updateThemeToggleButtonText() {
|
||||||
if (body.classList.contains('dark-mode')) {
|
if (themeToggleButton) {
|
||||||
themeToggleButton.textContent = 'Change to Light Mode';
|
if (body.classList.contains('dark-mode')) {
|
||||||
} else {
|
themeToggleButton.textContent = 'Change to Light Mode';
|
||||||
themeToggleButton.textContent = 'Change to Dark Mode';
|
} else {
|
||||||
|
themeToggleButton.textContent = 'Change to Dark Mode';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,11 +54,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
updateThemeToggleButtonText();
|
updateThemeToggleButtonText();
|
||||||
|
|
||||||
// Toggle the theme on button click
|
// Toggle the theme on button click
|
||||||
themeToggleButton.addEventListener('click', () => {
|
if (themeToggleButton) {
|
||||||
const isDarkMode = body.classList.toggle('dark-mode');
|
themeToggleButton.addEventListener('click', () => {
|
||||||
safeStorage.setItem('theme', isDarkMode ? 'dark' : 'light');
|
const isDarkMode = body.classList.toggle('dark-mode');
|
||||||
updateThemeToggleButtonText(); // Update the button text after toggling
|
safeStorage.setItem('theme', isDarkMode ? 'dark' : 'light');
|
||||||
});
|
updateThemeToggleButtonText(); // Update the button text after toggling
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Date formatting is now handled consistently on the backend
|
// Date formatting is now handled consistently on the backend
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user