What's new? | Help | Directory | Sign in
Google
google-web-toolkit-incubator
Likely additions to Google Web Toolkit
  
  
  
  
    
Search
for
Updated Jun 30, 2008 by b...@google.com
Labels: Type-Library
StyleInjector  
Combines ImmutableResourceBundle with CSS styleshees

Goal

Details

In your gwt.xml file:

<inherits name="com.google.gwt.libideas.ImmutableResources" />
<inherits name="com.google.gwt.libideas.StyleInjector" />

Define your ImmutableResourceBundle:

public interface Resources extends ImmutableResourceBundle {
  public static final Resources INSTANCE =
      GWT.create(Resources.class);

  @Resource("myBackground.png")
  public DataResource backgroundFunction();

  @Resource("myCss.css")
  public CssResource css();
}

The CSS contents (see CssResource for more information):

/* The format is @url <id> <function name>; */
@url backgroundUrl backgroundFunction;
body {
  background: backgroundUrl repeat-x;
}

In your onModuleLoad:

StyleInjector.injectStylesheet(Resources.INSTANCE.css().getText());

You now have your stylesheet applied to the document while taking advantage of strongly-named or inlined resource URLs. Because the standard I18N-style of resource naming is applied to the DataResource instance, it is possible to provide localized CSS background images without the need for multiple, per-locale stylesheets. It is now possible to have myBackground_fr.png and myBackground_en.png substituted based on the locale deferred binding property.

It is possible to update the contents of a previously-injected stylesheet using the setContents() method:

StyleElement elt = StyleInjector.injectStylesheet("CSS contents");
StyleInjector.setContents(elt, "New CSS contents");

Comment by jdwyah, Feb 01, 2008

fyi: The module should be <inherits name="com.google.gwt.libideas.StyleInjector" />

Comment by chris.f.jones, Jun 12, 2008

How would one add a background image to css from an ImageBundle? using StyleInjector?

Comment by pcourt, Jul 04, 2008

Not sure of the correct place to post this, but the compiler throws out warnings when you use -moz-??? tags in your CSS.


Sign in to add a comment