|
100 | 100 | <div class="container mx-auto flex-1 flex justify-between items-center px-4"> |
101 | 101 | <!-- Logo Text --> |
102 | 102 | <a href="/" class="text-2xl font-bold text-gray-800">skillcoins.de</a> |
103 | | - <!-- Logout Button (nur sichtbar, wenn eingeloggt) --> |
104 | | - <div> |
| 103 | + <div class="flex items-center space-x-4"> |
| 104 | + <!-- Dark Mode Toggle --> |
| 105 | + <button id="theme-toggle" class="btn btn-ghost"> |
| 106 | + <svg id="theme-toggle-light-icon" class="w-6 h-6 hidden" fill="none" stroke="currentColor" |
| 107 | + viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"> |
| 108 | + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" |
| 109 | + d="M12 3v1m0 16v1m8.66-8.66h-1M4.34 12.34h-1m15.31 6.36l-.7-.7M6.34 6.34l-.7-.7m12.02 0l-.7.7M6.34 17.66l-.7.7M12 5a7 7 0 100 14 7 7 0 000-14z"></path> |
| 110 | + </svg> |
| 111 | + <svg id="theme-toggle-dark-icon" class="w-6 h-6 hidden" fill="currentColor" stroke="none" |
| 112 | + viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> |
| 113 | + <path d="M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"></path> |
| 114 | + </svg> |
| 115 | + </button> |
| 116 | + <!-- Logout Button (nur sichtbar, wenn eingeloggt) --> |
105 | 117 | <button id="keycloak-logout" class="btn btn-secondary hidden">Logout</button> |
106 | 118 | </div> |
107 | 119 | </div> |
@@ -132,6 +144,9 @@ <h1 class="text-5xl font-bold">Willkommen bei skillcoins.de</h1> |
132 | 144 | document.addEventListener('DOMContentLoaded', function () { |
133 | 145 | const registerButton = document.getElementById('register-button'); |
134 | 146 | const logoutButton = document.getElementById('keycloak-logout'); |
| 147 | + const themeToggle = document.getElementById('theme-toggle'); |
| 148 | + const lightIcon = document.getElementById('theme-toggle-light-icon'); |
| 149 | + const darkIcon = document.getElementById('theme-toggle-dark-icon'); |
135 | 150 | const apiUrl = 'https://resourceserver.de/v1/graphql'; // Hasura GraphQL endpoint |
136 | 151 |
|
137 | 152 | // Initialize Keycloak |
@@ -199,8 +214,45 @@ <h1 class="text-5xl font-bold">Willkommen bei skillcoins.de</h1> |
199 | 214 | console.error('Failed to initialize Keycloak:', err); |
200 | 215 | }); |
201 | 216 |
|
202 | | - // Überprüfen des Tokens beim Laden der Seite |
203 | | - checkToken(); |
| 217 | + // Dark Mode Toggle Funktionalität |
| 218 | + function applyTheme(theme) { |
| 219 | + if (theme === 'dark') { |
| 220 | + document.documentElement.classList.add('dark'); |
| 221 | + darkIcon.classList.remove('hidden'); |
| 222 | + lightIcon.classList.add('hidden'); |
| 223 | + } else { |
| 224 | + document.documentElement.classList.remove('dark'); |
| 225 | + darkIcon.classList.add('hidden'); |
| 226 | + lightIcon.classList.remove('hidden'); |
| 227 | + } |
| 228 | + } |
| 229 | + |
| 230 | + // Überprüfen und Anwenden des Themes basierend auf localStorage oder Systempräferenz |
| 231 | + function initializeTheme() { |
| 232 | + const storedTheme = localStorage.getItem('theme'); |
| 233 | + if (storedTheme) { |
| 234 | + applyTheme(storedTheme); |
| 235 | + } else { |
| 236 | + // Falls kein gespeichertes Theme vorhanden ist, das System-Theme verwenden |
| 237 | + const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches; |
| 238 | + applyTheme(prefersDark ? 'dark' : 'light'); |
| 239 | + } |
| 240 | + } |
| 241 | + |
| 242 | + // Event Listener für den Dark Mode Toggle Button |
| 243 | + themeToggle.addEventListener('click', function () { |
| 244 | + const isDark = document.documentElement.classList.contains('dark'); |
| 245 | + if (isDark) { |
| 246 | + applyTheme('light'); |
| 247 | + localStorage.setItem('theme', 'light'); |
| 248 | + } else { |
| 249 | + applyTheme('dark'); |
| 250 | + localStorage.setItem('theme', 'dark'); |
| 251 | + } |
| 252 | + }); |
| 253 | + |
| 254 | + // Initialisieren des Themes beim Laden der Seite |
| 255 | + initializeTheme(); |
204 | 256 | }); |
205 | 257 | </script> |
206 | 258 |
|
|
0 commit comments