💄 Add switch theme button function.
This commit is contained in:
@@ -34,6 +34,7 @@ NexT.boot.registerEvents = function() {
|
||||
NexT.boot.refresh = function() {
|
||||
|
||||
NexT.utils.calSiteInfo();
|
||||
NexT.utils.regSwitchThemeBtn();
|
||||
|
||||
if (!NexT.CONFIG.page.isPage) return;
|
||||
|
||||
|
||||
@@ -23,6 +23,16 @@ HTMLElement.prototype.wrap = function(wrapper) {
|
||||
|
||||
NexT.utils = {
|
||||
|
||||
regSwitchThemeBtn: function() {
|
||||
const switchThemeBtn = document.getElementById('switch-theme');
|
||||
if (!switchThemeBtn) return;
|
||||
switchThemeBtn.addEventListener('click', () => {
|
||||
const colorTheme = document.documentElement.getAttribute('data-theme');
|
||||
const theme = colorTheme == null ? 'dark' : colorTheme == 'dark' ? 'light' : 'dark';
|
||||
document.documentElement.setAttribute('data-theme', theme);
|
||||
});
|
||||
},
|
||||
|
||||
domAddClass: function(selector, cls) {
|
||||
const doms = document.querySelectorAll(selector);
|
||||
if (doms) {
|
||||
|
||||
Reference in New Issue
Block a user