Class JSLoader

java.lang.Object
org.parttio.vaadinjsloader.JSLoader

public class JSLoader extends Object
Dynamic JavaScript library loader for Vaadin.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    static boolean
    isLoaded(com.vaadin.flow.component.Component component, String library)
    Check if the given library has been loaded for the UI.
    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.
    static void
    load(com.vaadin.flow.component.Component component, String libraryName, String version, String file, String urlPattern)
    Loads a JavaScript library dynamically from given CDN.
    static void
    loadCdnjs(com.vaadin.flow.component.Component component, String libraryName, String version)
    Loads a minified JavaScript library dynamically from cdnjs.com.
    static void
    loadCdnjs(com.vaadin.flow.component.Component component, String libraryName, String version, boolean minified)
    Loads a JavaScript library dynamically from cdnjs.com.
    static void
    loadUnpkg(com.vaadin.flow.component.Component component, String libraryName, String version)
    Loads a JavaScript library dynamically from unpkg.com.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • JSLoader

      public JSLoader()
  • Method Details

    • load

      public static void load(com.vaadin.flow.component.Component component, String libraryName, String version, String file, String urlPattern)
      Loads a JavaScript library dynamically from given CDN. 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 for
      libraryName - the name of the library to load
      version - the version of the library to load
      file - the file of the library to load
      urlPattern - the base URL pattern to use for loading the library
    • 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 check
      library - 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 for
      libraryName - the name of the library to load
      version - 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 for
      libraryName - the name of the library to load
      version - the version of the library to load
    • loadUnpkg

      public static void loadUnpkg(com.vaadin.flow.component.Component component, String libraryName, String version)
      Loads a JavaScript library dynamically from unpkg.com.
      Parameters:
      component - the UI instance to load the library for
      libraryName - the name of the library to load
      version - the version of the library to load
    • isLoaded

      public static boolean isLoaded(com.vaadin.flow.component.Component component, String library)
      Check if the given library has been loaded for the UI.
      Parameters:
      component - the UI instance to check
      library - 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 check
      library - the name of the library to check
      version - the version of the library to check
      Returns:
      true if the given library and version has been loaded for the given UI