Tuesday, March 4, 2014

Re: Problems using native JavaScript library (Snap)

I find it very strange that you do not use $wnd.SVG() or $wnd.Snap(), but just SVG() or Snap().
When injecting your script, make sure you inject it into the top window (setWindow(ScriptInjector.TOP_WINDOW)), then reference your globals within $wnd.
I suppose your errors come from using nodes cross-document (the container in the top window, the SVG in the hidden iframe that sandboxes the GWT compiled code)

On Tuesday, March 4, 2014 2:16:46 PM UTC+1, Magnus wrote:
Hi,

I am currently testing two SVG libraries for use within my GWT application:

The first one, SVGJS, is now working for me, following a good explanation in this group (thanks to Jens).
The basic idea is to pass an existing DOM element as a container to a JSNI method, which in turn passes this element to the library's SVG constructor:

private native void drawExample(Element container) /*-{        var draw = SVG(container)        draw.text('SVG.JS')      }-*/;  


This approach did not work for me with the other library, SnapSVG.
When I do exactly the same:

private native void drawExample(Element container) /*-{        var s = Snap(container);        var c = s.circle(150,150,150);      }-*/;

Then I get the JavaScript error:
"Object [object Object] has no method 'circle'"

I assume that there is no suitable constructor so that s is null.

When I do this:

private native void drawExample(Element container) /*-{        var s = Snap(400,400);        var c = s.circle(150,150,150);        container.appendChild(s);      }-*/;

Then I get the error:
"An attempt was made to reference a Node in a context where it does not exist."

Note that I am testing within a DialogBox and passing its getElement() as container to the method above.

How can you connect the generated SVG object to a widget within a DialogBox?

Thank you
Magnus

--
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