Files
sistema_funcionando_lastwar/assets/js/main.js
nickpons666 48671dc88e Implementar tema claro/oscuro con Bootstrap 5
- Agregar atributo data-bs-theme al HTML
- Implementar botón toggle con íconos sol/luna en navegación
- Agregar estilos CSS para modo oscuro (variables, componentes, tablas)
- Implementar JavaScript para funcionalidad toggle con persistencia localStorage
- Agregar detección automática del tema del sistema
- Fix específico para columna "Contenido (Previo)" en sent_messages.php
- Mejorar Content Security Policy para archivos .map de Bootstrap
- Configuración de entorno automática para .env.pruebas

Características:
- Toggle claro/oscuro con persistencia
- Detección automática de preferencias del sistema
- Estilos personalizados para componentes en modo oscuro
- Compatibilidad con todas las páginas del sistema
2026-01-17 16:13:19 -06:00

47 lines
1.5 KiB
JavaScript
Executable File

$(document).ready(function(){
$("#menu-toggle").click(function(e) {
e.preventDefault();
$("#wrapper").toggleClass("toggled");
});
$(".overlay").click(function() {
$("#wrapper").removeClass("toggled");
});
// Theme Toggle Functionality
const themeToggle = $('#theme-toggle');
const themeIcon = $('#theme-icon');
const html = $('html');
// Load saved theme or default to light
const savedTheme = localStorage.getItem('theme') || 'light';
setTheme(savedTheme);
themeToggle.on('click', function() {
const currentTheme = html.attr('data-bs-theme') || 'light';
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
setTheme(newTheme);
localStorage.setItem('theme', newTheme);
});
function setTheme(theme) {
html.attr('data-bs-theme', theme);
// Update icon
if (theme === 'dark') {
themeIcon.removeClass('bi-sun-fill').addClass('bi-moon-fill');
themeToggle.attr('title', 'Cambiar a tema claro');
} else {
themeIcon.removeClass('bi-moon-fill').addClass('bi-sun-fill');
themeToggle.attr('title', 'Cambiar a tema oscuro');
}
}
// Check system preference on first load
if (!localStorage.getItem('theme')) {
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
setTheme(prefersDark ? 'dark' : 'light');
localStorage.setItem('theme', prefersDark ? 'dark' : 'light');
}
});