Agregar soporte para tema claro/oscuro
This commit is contained in:
21
templates/footer.php
Executable file → Normal file
21
templates/footer.php
Executable file → Normal file
@@ -5,6 +5,27 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-lite.min.js"></script>
|
||||
<script>
|
||||
(function() {
|
||||
const html = document.documentElement;
|
||||
const toggleBtn = document.getElementById('theme-toggle');
|
||||
const icon = toggleBtn.querySelector('i');
|
||||
|
||||
function updateIcon(theme) {
|
||||
icon.className = theme === 'dark' ? 'bi bi-sun-fill' : 'bi bi-moon-fill';
|
||||
}
|
||||
|
||||
updateIcon(html.getAttribute('data-bs-theme'));
|
||||
|
||||
toggleBtn.addEventListener('click', function() {
|
||||
const currentTheme = html.getAttribute('data-bs-theme');
|
||||
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
|
||||
html.setAttribute('data-bs-theme', newTheme);
|
||||
document.cookie = 'theme=' + newTheme + ';path=/;max-age=31536000';
|
||||
updateIcon(newTheme);
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
<?php if (isset($extraScripts)): ?>
|
||||
<?= $extraScripts ?>
|
||||
<?php endif; ?>
|
||||
|
||||
Reference in New Issue
Block a user