com.vaadin.client.
Class ResourceLoader
- java.lang.Object
-
- com.vaadin.client.ResourceLoader
-
public class ResourceLoader extends Object
ResourceLoader lets you dynamically include external scripts and styles on the page and lets you know when the resource has been loaded.
Since:
7.0.0
Author:
Vaadin Ltd
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ResourceLoader.ResourceLoadEvent
Event fired when a resource has been loaded.
static interface
ResourceLoader.ResourceLoadListener
Event listener that gets notified when a resource has been loaded.
-
Constructor Summary
Constructors Modifier Constructor Description protected
ResourceLoader()
Creates a new resource loader.
-
Method Summary
All Methods Modifier and Type Method Description static void
addOnloadHandler(com.google.gwt.dom.client.Element element, ResourceLoader.ResourceLoadListener listener, ResourceLoader.ResourceLoadEvent event)
Adds an onload listener to the given element, which should be a link or a script tag.
static ResourceLoader
get()
Returns the default ResourceLoader.
void
loadHtmlImport(String htmlUrl, ResourceLoader.ResourceLoadListener resourceLoadListener)
Loads an HTML import and notify a listener when the HTML import is loaded.
void
loadScript(String scriptUrl, ResourceLoader.ResourceLoadListener resourceLoadListener)
Load a script and notify a listener when the script is loaded.
void
loadStylesheet(String stylesheetUrl, ResourceLoader.ResourceLoadListener resourceLoadListener)
Load a stylesheet and notify a listener when the stylesheet is loaded.
protected void
runWhenHtmlImportsReady(Runnable runnable)
Executes a Runnable when all HTML imports are ready.
-
-
-
Constructor Detail
-
ResourceLoader
protected ResourceLoader()
Creates a new resource loader. You should generally not create you own resource loader, but instead use
get()
to get an instance.
-
-
Method Detail
-
get
public static ResourceLoader get()
Returns the default ResourceLoader.
Returns:
the default ResourceLoader
-
loadScript
public void loadScript(String scriptUrl, ResourceLoader.ResourceLoadListener resourceLoadListener)
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.
Parameters:
scriptUrl
- the url of the script to loadresourceLoadListener
- the listener that will get notified when the script is loaded
-
loadHtmlImport
public void loadHtmlImport(String htmlUrl, ResourceLoader.ResourceLoadListener resourceLoadListener)
Loads an HTML import and notify a listener when the HTML import is loaded. Calling this method when the HTML import is currently loading or already loaded doesn't cause the HTML import to be loaded again, but the listener will still be notified when appropriate.
Parameters:
htmlUrl
- url of HTML import to loadresourceLoadListener
- listener to notify when the HTML import is loaded
-
addOnloadHandler
public static void addOnloadHandler(com.google.gwt.dom.client.Element element, ResourceLoader.ResourceLoadListener listener, ResourceLoader.ResourceLoadEvent event)
Adds an onload listener to the given element, which should be a link or a script tag. The listener is called whenever loading is complete or an error occurred.
Parameters:
element
- the element to attach a listener tolistener
- the listener to callevent
- the event passed to the listenerSince:
7.3
-
loadStylesheet
public void loadStylesheet(String stylesheetUrl, ResourceLoader.ResourceLoadListener resourceLoadListener)
Load a stylesheet and notify a listener when the stylesheet is loaded. Calling this method when the stylesheet is currently loading or already loaded doesn't cause the stylesheet to be loaded again, but the listener will still be notified when appropriate.
Parameters:
stylesheetUrl
- the url of the stylesheet to loadresourceLoadListener
- the listener that will get notified when the stylesheet is loaded
-
runWhenHtmlImportsReady
protected void runWhenHtmlImportsReady(Runnable runnable)
Executes a Runnable when all HTML imports are ready. If the browser does not support triggering an event when HTML imports are ready, the Runnable is executed immediately.
Parameters:
runnable
- the code to executeSince:
8.1
-
-