Skip to content

How to (sort of) add code to fullcalendar’s renderEvents handler?

I’m using fullcalendar 1.6.3 along with Drupal 7 (thus the need, for now, to be back on 1.6.3). I have some code that I’d like to run every time the view of my calendar changes (via ajax requests) — forward or backward in time, or between month/week/day view.

Based on some tests, I could do this by hacking the source for renderEvents:

function renderEvents(modifiedEventID) { // TODO: remove modifiedEventID hack
    if (elementVisible()) {
        currentView.setEventData(events); // for View.js, TODO: unify with renderEvents
        currentView.renderEvents(events, modifiedEventID); // actually render the DOM elements
        // my_code_here();

but that would of course be Wrong. Unfortunately, I can’t figure out any other way to do it, probably because of some obvious gap in my Javascript knowledge. I tried setting up an event handler on eventAfterAllRender:

var eventAfterAllRenderEvent = new Event('eventAfterAllRender');
document.addEventListener('eventAfterAllRender', function (e) {my_code_here() }, false);

but that (for me) only runs on page load, not after the ajax events.

This is probably more of a Javascript question than a fullcalendar question, but is there any advice out there? I’m really trying to not hack core; thanks!


According to the documentation eventAfterAllRender is a callback, so you can do this:

    eventAfterAllRender: function (view) {
        // add your code here