Handlers
Handlers are sort of like options, but they are functions that get called whenever something special happens. In the following example, an alert box will appear whenever the user clicks on a day:
const calendar = new Calendar(calendarEl, {
dateClick: function() {
alert('a day has been clicked!');
}
}); Dynamically adding Handlers#
You can attach handlers after the calendar initializes using the on and off methods.
calendar.on( handlerName, func )
calendar.off( handlerName, func )
The below example dynamically binds a dateClick handler, and later removes it. To remove a handler, pass off the same function that was given to on:
function handleDateClick(info) {
console.log('clicked on ' + info.dateStr);
}
calendar.on('dateClick', handleDateClick);
// later...
calendar.off('dateClick', handleDateClick);