Package org.parttio.vaadinjsloader
Class JSLoader
java.lang.Object
org.parttio.vaadinjsloader.JSLoader
Dynamic JavaScript library loader for Vaadin.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetLoadedVersion(com.vaadin.flow.component.Component component, String library) Returns the version of the library that has been loaded for the given UI.static booleanCheck if the given library has been loaded for the UI.static booleanCheck if the given library and version has been loaded for the UI.static voidload(com.vaadin.flow.component.Component component, String libraryName, String version, String libraryFile, String urlPattern) Deprecated.static voidLoads a minified JavaScript library dynamically from cdnjs.com.static voidloadCdnjs(com.vaadin.flow.component.Component component, String libraryName, String version, boolean minified) Loads a JavaScript library dynamically from cdnjs.com.static voidloadFiles(com.vaadin.flow.component.Component component, String urlPattern, String libraryName, String version, String... file) Loads a JavaScript and CSS files dynamically from given CDN URL.static voidloadUnpkg(com.vaadin.flow.component.Component component, String libraryName, String version, String... libraryFile) Loads a JavaScript library dynamically from unpkg.com.
-
Field Details
-
CDNJS
- See Also:
-
CDNJS_MIN
- See Also:
-
URL_PATTERN_UNPKGCOM
- See Also:
-
URL_PATTERN_UNPKGCOM_FILES
- See Also:
-
-
Constructor Details
-
JSLoader
public JSLoader()
-
-
Method Details
-
load
public static void load(com.vaadin.flow.component.Component component, String libraryName, String version, String libraryFile, String urlPattern) Deprecated.Use {loadFiles(Component, String, String, String, String...)} instead.Loads a JavaScript and CSS files dynamically from given CDN URL. Pattern is used to construct the URL for the library. The pattern can contain named placeholders{library}for the library name and{version}for the version. The placeholders are replaced with the actual values before the URL is loaded. E.g. for unpkg.com:https://unpkg.com/{library}@{version}/dist/{library}- Parameters:
component- the UI instance to load the library forurlPattern- the base URL pattern to use for loading the librarylibraryName- the name of the library to loadversion- the version of the library to loadlibraryFile- the JavaScript file to load or null
-
loadFiles
public static void loadFiles(com.vaadin.flow.component.Component component, String urlPattern, String libraryName, String version, String... file) Loads a JavaScript and CSS files dynamically from given CDN URL. Pattern is used to construct the URL for the library. The pattern can contain named placeholders{library}for the library name and{version}for the version. The placeholders are replaced with the actual values before the URL is loaded. E.g. for unpkg.com:https://unpkg.com/{library}@{version}/dist/{library}- Parameters:
component- the UI instance to load the library forurlPattern- the base URL pattern to use for loading the librarylibraryName- the name of the library to loadversion- the version of the library to loadfile- the files of the library to load
-
getLoadedVersion
public static String getLoadedVersion(com.vaadin.flow.component.Component component, String library) Returns the version of the library that has been loaded for the given UI.- Parameters:
component- the UI instance to checklibrary- the name of the library to check- Returns:
- the version of the library that has been loaded for the given UI
-
loadCdnjs
public static void loadCdnjs(com.vaadin.flow.component.Component component, String libraryName, String version) Loads a minified JavaScript library dynamically from cdnjs.com.- Parameters:
component- the UI instance to load the library forlibraryName- the name of the library to loadversion- the version of the library to load- See Also:
-
loadCdnjs
public static void loadCdnjs(com.vaadin.flow.component.Component component, String libraryName, String version, boolean minified) Loads a JavaScript library dynamically from cdnjs.com.- Parameters:
component- the UI instance to load the library forlibraryName- the name of the library to loadversion- the version of the library to load
-
loadUnpkg
public static void loadUnpkg(com.vaadin.flow.component.Component component, String libraryName, String version, String... libraryFile) Loads a JavaScript library dynamically from unpkg.com.- Parameters:
component- the UI instance to load the library forlibraryName- the name of the library to loadversion- the version of the library to loadlibraryFile- the file(s) to load or null
-
isLoaded
Check if the given library has been loaded for the UI.- Parameters:
component- the UI instance to checklibrary- the name of the library to check- Returns:
- true if the given library has been loaded for the given UI
-
isLoaded
public static boolean isLoaded(com.vaadin.flow.component.Component component, String library, String version) Check if the given library and version has been loaded for the UI.- Parameters:
component- the UI instance to checklibrary- the name of the library to checkversion- the version of the library to check- Returns:
- true if the given library and version has been loaded for the given UI
-
loadFiles(Component, String, String, String, String...)} instead.