This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-website.git

commit 996a476878b0fdf6bea181c31cdcf607aa247bc3
Author: Abhishek Mishra <[email protected]>
AuthorDate: Tue Feb 24 16:03:23 2026 +0530

    toggle button fix
---
 _includes/themes/apache/default.html | 41 +++++++++++++++++++++++++++---------
 1 file changed, 31 insertions(+), 10 deletions(-)

diff --git a/_includes/themes/apache/default.html 
b/_includes/themes/apache/default.html
index bf05dd173d..8615ba4d70 100644
--- a/_includes/themes/apache/default.html
+++ b/_includes/themes/apache/default.html
@@ -56,8 +56,9 @@
     <script>
     // Theme Toggle with System Preference
     (function() {
-      const themeBtns = document.querySelectorAll('[id*="themeBtn"]'); // Both 
desktop and mobile buttons
       const html = document.documentElement;
+      const mobileThemeBtn = document.getElementById('themeBtn');
+      const desktopThemeBtn = document.getElementById('desktopThemeBtn');
       
       // Check for saved theme preference or default to system preference
       const savedTheme = localStorage.getItem('theme');
@@ -70,17 +71,37 @@
         currentTheme = window.matchMedia('(prefers-color-scheme: 
dark)').matches ? 'dark' : 'light';
       }
       
+      // Set initial theme
       html.setAttribute('data-theme', currentTheme);
+      document.body.style.transition = 'background-color 0.3s ease, color 0.3s 
ease';
       
-      if (themeBtns.length > 0) {
-        themeBtns.forEach(function(btn) {
-          btn.addEventListener('click', function() {
-            const theme = html.getAttribute('data-theme');
-            const newTheme = theme === 'dark' ? 'light' : 'dark';
-            html.setAttribute('data-theme', newTheme);
-            localStorage.setItem('theme', newTheme);
-          });
-        });
+      // Function to toggle theme
+      function toggleTheme(e) {
+        if (e) {
+          e.preventDefault();
+          e.stopPropagation();
+        }
+        
+        const theme = html.getAttribute('data-theme');
+        const newTheme = theme === 'dark' ? 'light' : 'dark';
+        html.setAttribute('data-theme', newTheme);
+        localStorage.setItem('theme', newTheme);
+        console.log('Theme toggled to:', newTheme);
+      }
+      
+      // Add click listeners to both buttons
+      if (mobileThemeBtn) {
+        mobileThemeBtn.addEventListener('click', toggleTheme);
+        console.log('Mobile theme button listener attached');
+      }
+      
+      if (desktopThemeBtn) {
+        desktopThemeBtn.addEventListener('click', toggleTheme);
+        console.log('Desktop theme button listener attached');
+      }
+      
+      if (!mobileThemeBtn && !desktopThemeBtn) {
+        console.warn('Theme buttons not found');
       }
     })();
     

Reply via email to