List of usage examples for com.google.gwt.dom.client ScriptElement setPropertyBoolean
@Override
public void setPropertyBoolean(String name, boolean value)
From source file:com.vaadin.client.ResourceLoader.java
License:Apache License
/** * Load a script and notify a listener when the script is loaded. Calling * this method when the script is currently loading or already loaded * doesn't cause the script to be loaded again, but the listener will still * be notified when appropriate./*from ww w . ja v a2 s .co m*/ * * * @param scriptUrl * url of script to load * @param resourceLoadListener * listener to notify when script is loaded * @param async * What mode the script.async attribute should be set to * @since 7.2.4 */ public void loadScript(final String scriptUrl, final ResourceLoadListener resourceLoadListener, boolean async) { final String url = WidgetUtil.getAbsoluteUrl(scriptUrl); ResourceLoadEvent event = new ResourceLoadEvent(this, url, false); if (loadedResources.contains(url)) { if (resourceLoadListener != null) { resourceLoadListener.onLoad(event); } return; } if (preloadListeners.containsKey(url)) { // Preload going on, continue when preloaded preloadResource(url, new ResourceLoadListener() { @Override public void onLoad(ResourceLoadEvent event) { loadScript(url, resourceLoadListener); } @Override public void onError(ResourceLoadEvent event) { // Preload failed -> signal error to own listener if (resourceLoadListener != null) { resourceLoadListener.onError(event); } } }); return; } if (addListener(url, resourceLoadListener, loadListeners)) { ScriptElement scriptTag = Document.get().createScriptElement(); scriptTag.setSrc(url); scriptTag.setType("text/javascript"); scriptTag.setPropertyBoolean("async", async); addOnloadHandler(scriptTag, new ResourceLoadListener() { @Override public void onLoad(ResourceLoadEvent event) { fireLoad(event); } @Override public void onError(ResourceLoadEvent event) { fireError(event); } }, event); head.appendChild(scriptTag); } }