Getting Started
This page explains how Preline JavaScript works, its methodology, and provides some examples.
Preline JavaScript plugins include autoInit
static method, it's useful when you need to reinitialize all elements on the page.
window.HSStaticMethods.autoInit();
This method can also be used with certain collections of initialized elements.
window.HSStaticMethods.autoInit(['carousel', 'dropdown']);
AJAX example:
To use static methods inside TS files, it is necessary to declare the interface inside the files where method is called, this will prevent possible warnings and errors.
...
import { IStaticMethods } from "preline/preline";
declare global {
interface Window {
HSStaticMethods: IStaticMethods;
}
}
...
window.HSStaticMethods.autoInit();
To prevent an element from auto-initializing, you can add the --prevent-on-load-init
CSS class.
This can be useful if you want to initialize elements using an event other than load.