Is there any way (within stock GWT) to
remove CssResources on the fly? I currently use JSNI to do just that when I change themes in my application. The JSNI code was adapted from the Showcase example, btw. The JSNI I'm currently using (or rather, was using before my CssResource adventures) follows and it seems to work great:
static native void removeStyleSheet(String ssID)/*-{
var ss = $doc.getElementById(ssID);
if (ss != null) {
ss.parentNode.removeChild(ss);
}
}-*/;
static native void loadStyleSheet(String cssName, String ssID)/*-{
var ss = $doc.getElementById(ssID);
if (ss != null) {
ss.parentNode.removeChild(ss);
}
var fileref=document.createElement("link");
fileref.setAttribute("id", ssID);
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", cssName);
var hd = $doc.getElementsByTagName("head")[0];
hd.appendChild(fileref);
}-*/;
However, because it would be nice to a) conditionally change background images instead of cascading yet another stylesheet just for a new image, and b) use ClientBundle for the background images, I thought I'd switch to CssResource and StyleInjector. Great idea, except I don't want to infinitely cascade stylesheets or let stylesheets from other themes linger. It is much cleaner to, in one place (called ThemeSelector, oddly enough), swap an old theme stylesheet out and swap a new one in using the above code. The themes then each cascade from the main stylesheet, not each other. So, before I give up and restore the stylesheets and images and code from version control, does anyone have any ideas on this? Am I missing something obvious?
By the way, if you want to see the way theme selection works in practice you can go to my website
http://projectsandy.org and take a look. You don't have to join the program to swap themes, just use the button in the upper right hand corner. And even though I am not a graphics designer by any means I had HUGE fun designing the themes. Eventually I hope to have user-submitted themes.
Thanks.