mirror of https://github.com/ColorlibHQ/AdminLTE
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.8 KiB
46 lines
1.8 KiB
<script src="{{ '/assets/plugins/jquery/jquery.min.js' | prepend: site.baseurl }}"></script> |
|
<script src="{{ '/assets/plugins/bootstrap/js/bootstrap.bundle.min.js' | prepend: site.baseurl }}"></script> |
|
<script src="{{ '/assets/plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js' | prepend: site.baseurl }}"></script> |
|
<script src="{{ '/assets/js/adminlte.min.js' | prepend: site.baseurl }}"></script> |
|
<script> |
|
var toggleSwitch = document.querySelector('.theme-switch input[type="checkbox"]'); |
|
var currentTheme = localStorage.getItem('theme'); |
|
var mainHeader = document.querySelector('.main-header'); |
|
|
|
if (currentTheme) { |
|
if (currentTheme === 'dark') { |
|
if (!document.body.classList.contains('dark-mode')) { |
|
document.body.classList.add("dark-mode"); |
|
} |
|
if (mainHeader.classList.contains('navbar-light')) { |
|
mainHeader.classList.add('navbar-dark'); |
|
mainHeader.classList.remove('navbar-light'); |
|
} |
|
toggleSwitch.checked = true; |
|
} |
|
} |
|
|
|
function switchTheme(e) { |
|
if (e.target.checked) { |
|
if (!document.body.classList.contains('dark-mode')) { |
|
document.body.classList.add("dark-mode"); |
|
} |
|
if (mainHeader.classList.contains('navbar-light')) { |
|
mainHeader.classList.add('navbar-dark'); |
|
mainHeader.classList.remove('navbar-light'); |
|
} |
|
localStorage.setItem('theme', 'dark'); |
|
} else { |
|
if (document.body.classList.contains('dark-mode')) { |
|
document.body.classList.remove("dark-mode"); |
|
} |
|
if (mainHeader.classList.contains('navbar-dark')) { |
|
mainHeader.classList.add('navbar-light'); |
|
mainHeader.classList.remove('navbar-dark'); |
|
} |
|
localStorage.setItem('theme', 'light'); |
|
} |
|
} |
|
|
|
toggleSwitch.addEventListener('change', switchTheme, false); |
|
</script>
|
|
|