writing raphaeljs addon

Hi,

I am trying to call raphael.js functions from inside a jsni function in the client-side code of my widget. However I seem not to be able to do it. I can’t understand what scope I am in as calling alert() and console.log() work, but any call to an external library is failing. Btw I know for sure that my code is accessible, as I am able to call it from getWindow().executeJavascript().

I have indeed included the libraries I need with the following code in my application’s Servlet:

	protected void writeAjaxPageHtmlHeader(BufferedWriter page, String title, String themeUri, HttpServletRequest request) throws IOException {
		page.append("<script src=\"/home/VAADIN/themes/flx/js/jquery-1.4.4.min.js\"></script>");
		page.append("<script src=\"/home/VAADIN/themes/flx/js/raphael.js\"></script>");
		super.writeAjaxPageHtmlHeader(page, title, themeUri, request);
	}

So, to sum it up: I am trying to create an addon that uses raphael.js but I seem to be totally unable to access the library. How do I enable access to the library?

Most likely you’re referencing your script in the wrong context, as you said yourself.

All GWT client side JavaScript is run inside an invisible IFRAME, not in the actual page that is showing. To access the actual page’s DOM (and external JavaScript living on that page), you need to use the special GWT variables inside your JSNI methods.

// To access the window object
$wnd

// To access the document object
$doc

Alert and console calls were working because they are global and not depending on the context where they are called.

Hope this helps. Eagerly awaiting for the add-on, Raphael.js is quite neat :slight_smile: