Release 4.2.6+1: fix sidebar RU/EN and theme toggles — applyTheme param shadowed i18n t(), so init threw and click listeners never bound. Windows 4.2.6.1.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+25
-13
@@ -2440,8 +2440,10 @@
|
||||
} catch (_) {}
|
||||
return "light";
|
||||
}
|
||||
function applyTheme(t) {
|
||||
const theme = t === "dark" ? "dark" : "light";
|
||||
// Param must not be named `t` — that shadows the i18n helper and throws on title update,
|
||||
// aborting script init so theme/lang click listeners never bind (4.2.5 regression).
|
||||
function applyTheme(next) {
|
||||
const theme = next === "dark" ? "dark" : "light";
|
||||
document.documentElement.setAttribute("data-theme", theme);
|
||||
try { localStorage.setItem(THEME_KEY, theme); } catch (_) {}
|
||||
if (themeToggle) {
|
||||
@@ -2451,24 +2453,34 @@
|
||||
if (themeSwitch) themeSwitch.checked = theme === "dark";
|
||||
}
|
||||
applyTheme(document.documentElement.getAttribute("data-theme") || readTheme());
|
||||
if (themeToggle) {
|
||||
themeToggle.addEventListener("click", () => {
|
||||
const cur = document.documentElement.getAttribute("data-theme") === "dark" ? "dark" : "light";
|
||||
applyTheme(cur === "dark" ? "light" : "dark");
|
||||
// Event delegation on stable parents (survives future re-renders; not disabled by busy).
|
||||
const sideFoot = document.querySelector(".side-foot");
|
||||
if (sideFoot) {
|
||||
sideFoot.addEventListener("click", (e) => {
|
||||
const langBtn = e.target.closest("button[data-lang]");
|
||||
if (langBtn && sideFoot.contains(langBtn)) {
|
||||
setLang(langBtn.getAttribute("data-lang"));
|
||||
return;
|
||||
}
|
||||
const themeBtn = e.target.closest("#themeToggle, .theme-toggle");
|
||||
if (themeBtn && sideFoot.contains(themeBtn)) {
|
||||
const cur = document.documentElement.getAttribute("data-theme") === "dark" ? "dark" : "light";
|
||||
applyTheme(cur === "dark" ? "light" : "dark");
|
||||
}
|
||||
});
|
||||
}
|
||||
if (themeSwitch) {
|
||||
themeSwitch.addEventListener("change", () => applyTheme(themeSwitch.checked ? "dark" : "light"));
|
||||
}
|
||||
|
||||
function wireLangSeg(root) {
|
||||
if (!root) return;
|
||||
root.querySelectorAll("button[data-lang]").forEach((b) => {
|
||||
b.addEventListener("click", () => setLang(b.getAttribute("data-lang")));
|
||||
const langSegSettings = $("langSegSettings");
|
||||
if (langSegSettings) {
|
||||
langSegSettings.addEventListener("click", (e) => {
|
||||
const langBtn = e.target.closest("button[data-lang]");
|
||||
if (langBtn && langSegSettings.contains(langBtn)) {
|
||||
setLang(langBtn.getAttribute("data-lang"));
|
||||
}
|
||||
});
|
||||
}
|
||||
wireLangSeg($("langSeg"));
|
||||
wireLangSeg($("langSegSettings"));
|
||||
applyTranslations();
|
||||
|
||||
function skippedVersion() {
|
||||
|
||||
Reference in New Issue
Block a user