Fix for loaded theme not being selected in the theme box

This commit is contained in:
ebolam
2022-10-18 12:21:09 -04:00
parent f7272e8826
commit d63193ede7

View File

@@ -389,7 +389,6 @@ function do_story_text_updates(action) {
} }
function do_prompt(data) { function do_prompt(data) {
console.log(data);
var elements_to_change = document.getElementsByClassName("var_sync_story_prompt"); var elements_to_change = document.getElementsByClassName("var_sync_story_prompt");
for (item of elements_to_change) { for (item of elements_to_change) {
//clear out the item first //clear out the item first
@@ -717,6 +716,15 @@ function var_changed(data) {
option.value = option_data; option.value = option_data;
item.append(option); item.append(option);
} }
if (item.id == 'selected_theme') {
//Fix the select box
theme = getCookie("theme", "monochrome");
for (element of item.childNodes) {
if (element.value == theme) {
element.selected = true;
}
}
}
} else if (item.tagName.toLowerCase() === 'input') { } else if (item.tagName.toLowerCase() === 'input') {
item.value = fix_text(data.value); item.value = fix_text(data.value);
} else { } else {
@@ -2708,6 +2716,7 @@ function calc_token_usage(
} }
function Change_Theme(theme) { function Change_Theme(theme) {
setCookie("theme", theme);
const Acss = document.getElementById("CSSTheme_A"); const Acss = document.getElementById("CSSTheme_A");
const Bcss = document.getElementById("CSSTheme_B"); const Bcss = document.getElementById("CSSTheme_B");
let new_css = 'CSSTheme_B'; let new_css = 'CSSTheme_B';
@@ -2723,12 +2732,12 @@ function Change_Theme(theme) {
rel: "stylesheet", rel: "stylesheet",
href: `/themes/${theme}.css` href: `/themes/${theme}.css`
} }
); );
// We must wait for the style to load before we read it // We must wait for the style to load before we read it
css.onload = function() { css.onload = function() {
recolorTokens(); //Delete the old CSS item
create_theming_elements();
if (new_css == 'CSSTheme_A') { if (new_css == 'CSSTheme_A') {
if (Bcss) { if (Bcss) {
Bcss.remove(); Bcss.remove();
@@ -2738,16 +2747,19 @@ function Change_Theme(theme) {
Acss.remove(); Acss.remove();
} }
} }
} //Fix the select box
theme = getCookie("theme", "monochrome");
setCookie("theme", theme); console.log("Selecting Theme: "+theme);
select = document.getElementById("selected_theme"); console.log(document.getElementById("selected_theme").childNodes);
for (element of select.childNodes) { for (element of document.getElementById("selected_theme").childNodes) {
if (element.value == theme) { console.log(element);
element.selected = true; if (element.value == theme) {
} else { element.selected = true;
element.selected = false; console.log("changed theme");
}
} }
recolorTokens();
create_theming_elements();
} }
} }