foot.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <script src="{{ '/assets/plugins/jquery/jquery.min.js' | prepend: site.baseurl }}"></script>
  2. <script src="{{ '/assets/plugins/bootstrap/js/bootstrap.bundle.min.js' | prepend: site.baseurl }}"></script>
  3. <script src="{{ '/assets/plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js' | prepend: site.baseurl }}"></script>
  4. <script src="{{ '/assets/js/adminlte.min.js' | prepend: site.baseurl }}"></script>
  5. <script>
  6. var toggleSwitch = document.querySelector('.theme-switch input[type="checkbox"]');
  7. var currentTheme = localStorage.getItem('theme');
  8. var mainHeader = document.querySelector('.main-header');
  9. if (currentTheme) {
  10. if (currentTheme === 'dark') {
  11. if (!document.body.classList.contains('dark-mode')) {
  12. document.body.classList.add("dark-mode");
  13. }
  14. if (mainHeader.classList.contains('navbar-light')) {
  15. mainHeader.classList.add('navbar-dark');
  16. mainHeader.classList.remove('navbar-light');
  17. }
  18. toggleSwitch.checked = true;
  19. }
  20. }
  21. function switchTheme(e) {
  22. if (e.target.checked) {
  23. if (!document.body.classList.contains('dark-mode')) {
  24. document.body.classList.add("dark-mode");
  25. }
  26. if (mainHeader.classList.contains('navbar-light')) {
  27. mainHeader.classList.add('navbar-dark');
  28. mainHeader.classList.remove('navbar-light');
  29. }
  30. localStorage.setItem('theme', 'dark');
  31. } else {
  32. if (document.body.classList.contains('dark-mode')) {
  33. document.body.classList.remove("dark-mode");
  34. }
  35. if (mainHeader.classList.contains('navbar-dark')) {
  36. mainHeader.classList.add('navbar-light');
  37. mainHeader.classList.remove('navbar-dark');
  38. }
  39. localStorage.setItem('theme', 'light');
  40. }
  41. }
  42. toggleSwitch.addEventListener('change', switchTheme, false);
  43. </script>