Comment by a.revolution.ultra.blue:

Guys, check the other post on client bundle, {...@nenchev / @shahidzaman}, I  
answered both your questions there. @whoever-asked-about-resetting-rules, I  
have some custom implementation that allows for dynamic / updateable rules.  
Remember that all IE browsers only allow a max of 31 stylesheets {inline or  
link}, even in IE8 {would 63 kill them, honestly?}. Also, there is no  
reliable way to remove style elements properly in all browsers, so instead  
I store and clear StyleElements? manually. My implementation uses a few  
custom data classes and whatnot, but you can get the important bits you'll  
need from it.

//Styles is a JS object that stores StyleElements like HashMap
if (styles.xHas( id )){
//If the rule named id already has an element, get it
StyleElement el = styles.xCast( id );

try{
//We start with a text node.  I auto-wrap {braces}, but this can be  
confusing
        Text txt = Document.get().createTextNode( "."+id+"{"
+toWrite.xGetStr( i )+
"}" );
//Next, clear the style elements.  Rules are text nodes
for(int o = el.getChildCount();o-->0;el.removeChild( el.getChild( o ) ));
//xRNA is my own js <--> java overlay type.
xRNA asRna = el.cast();
//If the style element does NOT have a styleSheet property
if (asRna.xFalse( "styleSheet" ))
//Just append the text node to create rule
        el.appendChild( txt );
else
//Otherwise, we set use the browser <style/>.styleSheet object's cssText  
property
        asRna.xGetRna( "styleSheet" ).xSetStr( "cssText" , txt.getNodeValue() );
//Note, I actually use deferred binding to do this now.
}catch(Throwable e){GWT.log( "ack" , e );}
}
//If there is no style element yet
else{
//Make one using the deprecated injectStylesheet method
        styles.xSet( id , StyleInjector.injectStylesheet( "."+id+"{"
+toWrite.xGetStr( i )+
"}" ) );
}

If anyone finds this confusing, I can make a jar and upload somewhere.  Or  
you can wait a month when I release my full API in case I didn't test well  
enough.

It would be very nice to StyleElement extended with a setStyle() method  
that does all this internally instead of my haxored static classes, but...   
What're you gonna do?



For more information:
http://code.google.com/p/google-web-toolkit/wiki/CssResource

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to