I am trying to extend functionality of the FullCalender JS plugin. I am quite new to javascript OOP concepts as well as jQuery plugin development. In a first step I am wondering how to use and access the FullCalendar plugin. The fullCalendar
method can be called on any DOM Element while the calendar parameters can be given as JSON object:
$('#calendar').fullCalendar({
editable: true, // a parameter
events: "./events.php", // some events
eventRender: function(event, element) { // a callback
// do something here
}
});
I tried calling this creation method again and change the callback eventRender
but it does not work. I guess its because the calendar allows only one instance active on the DOM element. But how can I change parameters and callbacks without destroying and recreating the calendar?
Furthermore I tried to access the calendar object directly but I guess due to encapsulation it is not exposed through the FullCalendar. In contrast I see that the fullCalendar
function can be called with a string specifying a method to be called on the Calendar. Is this a common mechanism on plugin encapsulation?
Regarding the first part, FullCalendar merges the options during initialization
var options = mergeOptions({}, defaults, instanceOptions);
so you can only change eventRender
by
var currentHandler
$('#calendar').fullCalendar({
eventRender: function(event, element) { // a callback
currentHandler(event, element)
}
});
and then change currentHandler
implementation (i.e. currentHandler = myFirstHandler
)
When it comes to calling plugin methods, yes this is a common practice and was described here How to create a jQuery plugin with methods?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With