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.- listenerand- optionsargument types are based on and passed directly to a native- addEventListenermethod.
carousel.off
- Arguments: - {string} eventName
- {function} listener
 
- Returns: - this- this TinyCarousel instance (for chaining purposes)
- Usage: - Method used to remove the event - eventName- listenerthat has been added via- carousel.onmethod.
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 - eventNameon Tiny Carousel instance.- payload- If not an object - will be turned into one as follows: { data: payload }
- Then (or firstly, if payloadwas an object) it will be enhanced withtinyCarouselfield which would contain a reference to the TinyCarousel instance
- Lastly, such formatted object will be passed to the native CustomEventas event`s payload
 
- If not an object - will be turned into one as follows: 
- optionsargument is passed directly to the constructor of- CustomEventand thus might contain fields of the- eventInittype - so,- bubbles,- cancelableor- composed
 
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.- tinyCarouselfield 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 - StandardRequiredPayloadsection.
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.