Plugin Custom Events
This plugin triggers CustomEvents for Tiny Carousel core lifecycle events. This allows for the external code to be triggered right when it is necessary. Before or after an exact action - for example after the tiny carousel got initialized.
The plugin also extends Tiny Carousel instance with additional methods. Read more about it in the instance methods section.
TIP
This plugin is often a required dependency for the other parts of Tiny Carousel ecosystem.
To learn on how to install and use plugin, please see our usage guide.
For complete list of custom events raised by this plugin, please head directly to the events section.
Instance methods
carousel.on
Arguments:
{string} eventName
{function} listener
{object | boolean} options <optional>
Returns:
this
- this TinyCarousel instance (for chaining purposes)Usage:
Method used to set a handler triggered for an event
eventName
.listener
andoptions
argument types are based on and passed directly to a nativeaddEventListener
method.
carousel.off
Arguments:
{string} eventName
{function} listener
Returns:
this
- this TinyCarousel instance (for chaining purposes)Usage:
Method used to remove the event
eventName
listener
that has been added viacarousel.on
method.
carousel.dispatch
Arguments:
{string} eventName
{unknown} payload <optional>
{object} options <optional>
Returns:
this
- this TinyCarousel instance (for chaining purposes)Usage:
Method used to dispatch custom event
eventName
on Tiny Carousel instance.payload
- If not an object - will be turned into one as follows:
{ data: payload }
- Then (or firstly, if
payload
was an object) it will be enhanced withtinyCarousel
field which would contain a reference to the TinyCarousel instance - Lastly, such formatted object will be passed to the native
CustomEvent
as event`s payload
- If not an object - will be turned into one as follows:
options
argument is passed directly to the constructor ofCustomEvent
and thus might contain fields of theeventInit
type - so,bubbles
,cancelable
orcomposed
Events
List of events triggered by default when Plugin Custom Events is used:
Event Name | Event Payload |
---|---|
before:init | StandardRequiredPayload |
after:init | StandardRequiredPayload |
before:go-to | GoToEventPayload |
after:go-to | GoToEventPayload |
error:go-to | GoToErrorEventPayload |
before:find-possible-items | StandardRequiredPayload |
after:find-possible-items | StandardRequiredPayload |
Payload Types
StandardRequiredPayload
Properties:
Details:
Standard payload type describing fields which are available in the every event dispatched through
plugin-custom-events
.tinyCarousel
field holds reference to the current TinyCarousel instance.
GoToEventPayload
Properties:
Details:
Data type which holds information about the active slide change process. For the description of the rest of fields, please look into
StandardRequiredPayload
section.
GoToErrorEventPayload
Properties:
{TinyCarousel} tinyCarousel
{SlideInfo} to
{'overflow'} cause
Details:
Data type which hold information about the slide change process which have failed and a cause of its error. Current list of possible causes: `overflow`. For the description of the rest of fields, please look into [`StandardRequiredPayload`](#standardrequiredpayload) section.