nodebb-theme-oxide
Advanced tools
Comparing version 5.0.35 to 5.0.36
@@ -6,37 +6,34 @@ /* globals ajaxify */ | ||
const setTheme = (isDark) => { | ||
const safeBool = Boolean(isDark); | ||
const _updateTheme = (state) => { | ||
const safeState = Boolean(state); | ||
document.documentElement.setAttribute("dark", safeBool); | ||
localStorage.setItem("user:dark", safeBool); | ||
document.documentElement.setAttribute("dark", safeState); | ||
localStorage.setItem("user:dark", safeState); | ||
}; | ||
const toggleTheme = (e) => { | ||
e.stopPropagation(); | ||
const _setTheme = (e, btn) => { | ||
e.preventDefault(); | ||
const { target } = e; | ||
window.darkmode = !window.darkmode; | ||
if (target.className === "off" && target.id === "toggle-theme") { | ||
setTheme(true); | ||
target.className = "on"; | ||
} else { | ||
setTheme(false); | ||
target.className = "off"; | ||
} | ||
const btnState = window.darkmode ? "on" : "off"; | ||
btn.className = btnState; | ||
_updateTheme(window.darkmode); | ||
}; | ||
const addButton = () => { | ||
if (!ajaxify.data.loggedIn) return null; | ||
const isDefault = document.documentElement.dataset.initialDark ? true : false; | ||
if (isDefault) return; | ||
const toggleBtn = document.querySelector("#toggle-theme"); | ||
isDark ? toggleBtn.classList.add("on") : toggleBtn.classList.add("off"); | ||
window.darkmode = localStorage.getItem("user:dark") ? true : false; | ||
_updateTheme(window.darkmode); | ||
toggleBtn.addEventListener("click", toggleTheme, false); | ||
}; | ||
$(window).on("action:ajaxify.end", () => { | ||
if (!ajaxify.data.loggedIn) return null; | ||
const isDark = JSON.parse(localStorage.getItem("user:dark")); | ||
const btn = document.querySelector("#toggle-theme"); | ||
window.darkmode ? (btn.className = "on") : (btn.className = "off"); | ||
localStorage.getItem("user:dark") === null ? setTheme(false) : setTheme(isDark); | ||
$(window).on("action:ajaxify.end", addButton); | ||
btn.addEventListener("click", (e) => _setTheme(e, btn), false); | ||
}); | ||
})(); |
@@ -112,3 +112,3 @@ "use strict"; | ||
config.enableShowIpInUserProfile = enableShowIpInUserProfile === "on"; | ||
config.enableDarkmodeIsDefault = enableDarkmodeIsDefault === "on"; | ||
config.enableDarkmodeIsDefault = enableDarkmodeIsDefault === "off"; | ||
}); | ||
@@ -115,0 +115,0 @@ |
{ | ||
"name": "nodebb-theme-oxide", | ||
"description": "A theme that is based on the GitHub design.", | ||
"version": "5.0.35", | ||
"version": "5.0.36", | ||
"homepage": "https://github.com/youhosi/nodebb-theme-oxide", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
2508968
2958