Fix thing but break thing

Fix loading resources being loaded relative to the page instead of the stylesheet because it was loaded as <style> instead of <link>
But how are we gonna know when it loads?
main
Isaiah Odhner 2019-02-18 01:46:50 -05:00
parent 4452dffeb1
commit a9db3af45a
1 changed files with 4 additions and 48 deletions

View File

@ -16,8 +16,6 @@
theme_link.id = "theme-link"; theme_link.id = "theme-link";
document.head.appendChild(theme_link); document.head.appendChild(theme_link);
var theme_style = document.createElement("style");
window.set_theme = set_theme; window.set_theme = set_theme;
window.get_theme = get_theme; window.get_theme = get_theme;
@ -35,34 +33,13 @@
function set_theme(theme) { function set_theme(theme) {
current_theme = theme; current_theme = theme;
var can_probably_refresh_to_switch = true;
try { try {
localStorage[theme_storage_key] = theme; localStorage[theme_storage_key] = theme;
} catch(error) { } catch(error) {}
can_probably_refresh_to_switch = false;
}
return (
fetch(href_for(theme))
.then(function(response) {
response.text().then(function(css) {
replace_existing_theme_with_loaded_css(
theme_link,
theme_style,
css
);
})
}, function(error) {
var error_message = "Failed to load theme.";
if (can_probably_refresh_to_switch) { theme_link.href = href_for(theme);
error_message += " You can probably reload the app to finish switching themes."; // TODO: (how?)
} // $(window).triggerHandler("theme-load");
show_error_message(error_message, error);
})
);
} }
/** /**
@ -72,25 +49,4 @@
function href_for(theme) { function href_for(theme) {
return "styles/themes/" + theme; return "styles/themes/" + theme;
} }
/**
* @param {HTMLElement} theme_link
* @param {HTMLElement} theme_style
* @param {string} css_content
*/
function replace_existing_theme_with_loaded_css(
theme_link,
theme_style,
css_content
) {
if (theme_link.parentElement) {
theme_link.parentElement.removeChild(theme_link);
}
theme_style.textContent = css_content;
document.head.appendChild(theme_style);
$(window).triggerHandler("theme-load");
}
})(); })();