I basically have an AJAX-fetched skin (html/css) that's loaded into a dummy element (id=SkinContainer) when the page is loaded, and then the content of one of its divs (contentdiv) is fetched with another AJAXHTTPRequest.
At any rate, when the page is loaded, the user can click a button to swap the theme/skin. Below is the (working) code for my theme swap, but I'm wondering whether or not it's the best way to do this:
function themeSwap() {
var oldTheme = themeSelect;
themeSelect++;
if (themeSelect>2 || themeSelect<1) {themeSelect=1;}
$('html').addClass('js');
var tempContentDiv = document.getElementById("contentdiv");
var tempContent = tempContentDiv.innerHTML;
ReplaceJSCSSFile("css/skin" + oldTheme + ".css", "css/skin" + themeSelect + ".css", "css");
AJAX_LoadResponseIntoElement("skinContainer", "skin" + themeSelect + ".txt", function() {themeSwapCallback(tempContent)} );
}
function themeSwapCallback (tempContent) {
initPage();
document.getElementById("contentdiv").innerHTML = tempContent;
setCookie("themeSelection",themeSelect,365);
}
What this basically does is stores the innerHTML of contentdiv into the "tempContent" variable, loads the new skin into skinContainer with an AJAX fetch, and then restores the original content by setting contentdiv's innerHTML to "tempContent."
The reason why it has to use an AJAX fetch on top of the CSS swap is because the structure of the elements changes.
Have I finally have this done correctly? or is this still not perfect? :(