An event helper class written with TypeScript for the jQuery Plugin Boilerplate It contains generic functions that simplify event handling within all kinds of plugins
The naming convention pattern should be: [?prefix].[action].[?area].[pluginName]
prefix(optional) - the prefix mostly describes the temporal state likebeforeorafteraction- this is the most important part of the event name. It describes the action of that specific eventarea(optional) - if the action is not global or clear on its own, add an area where this action occurs.pluginName- surprise surprise.... this is the name of the plugin
init.sliderslide.carouselafter.init.accordionchange.header.tablebefore.slide.carouselafter.change.header.table
This static function is used to automatically wrap jQuery events before and after a given function.
Because it uses jQuery Events you can stop the ongoing process within the initial before event by setting event.preventDefault()
$element- the jQuery element on which the event is firedeventName- the desired event name excluding thebefore/afterprefixesfn- the functionparams(optional) - optional params that will be added to the events
import EventHelper from "jquery-plugin-events";EventHelper.wrapEvents('action.pluginName', () => {
console.log('action goes here');
}, this.$element, this, ['some param']);this.$element.on('before.action.pluginName', (e) => {
console.log('before action');
// prevent method and after-event of being executed
// e.preventDefault();
});
this.$element.on('after.action.pluginName', () => {
console.log('after action');
});