Thursday, February 27, 2014

Re: GWT and SVG, the 125th... :-)

Working example:

public class SvgEntryPoint implements EntryPoint {      public class SvgWidget extends Widget {        public SvgWidget() {        setElement(Document.get().createDivElement());        // SVG library should draw inside the widget's container element        drawExample(getElement());      }        private native void drawExample(Element container) /*-{        var draw = SVG(container)          // Must be used if JS is injected to top window, see below.        // var draw = $wnd.SVG(container)          draw.text('SVG.JS')      }-*/;      }      public interface MyBundle extends ClientBundle {      @Source("svg.min.js")      TextResource svgJs();    }      public void onModuleLoad() {      MyBundle bundle = GWT.create(MyBundle.class);      // Injects JS code into the GWT iframe. SvgWidget.drawExample() can use SVG() then.      ScriptInjector.fromString(bundle.svgJs().getText()).inject();          // Injects JS code into the top level window. Now SvgWidget.drawExample() MUST use $wnd.SVG()      // to reference the top level window. Only calling SVG() would mean to call it on the GWT iframe      // to which the JS code has never been injected to.        //ScriptInjector.fromString(bundle.svgJs().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();        RootPanel.get().add(new SvgWidget());    }    }


-- J.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment