fullcalendar/event_data/events_function.txt
2010-01-16 14:29:18 -08:00

55 lines
1.5 KiB
Plaintext

events (as a function)
======================
A custom function for programmatically generating [Event Objects](Event_Object).
<div class='spec' markdown='1'>
function( *start*, *end*, *callback* ) { }
</div>
FullCalendar will call this function whenever it needs new event data.
This is triggered when the user clicks prev/next or switches views.
This function will be given `start` and `end` parameters, which are
Date objects denoting the range the calendar needs events for.
It will also be given `callback`, a function that must be called when
the custom event function has generated its events. It is the event function's
responsibility to make sure `callback` is being called with an array of
[Event Objects](Event_Object).
Here is an example showing how to use an event function to fetch events from
an XML feed:
$('#calendar').fullCalendar({
events: function(start, end, callback) {
$.ajax({
url: 'myxmlfeed.php',
dataType: 'xml',
data: {
// our hypothetical feed requires UNIX timestamps
start: Math.round(start.getTime() / 1000),
end: Math.round(end.getTime() / 1000)
},
success: function(doc) {
var events = [];
$(doc).find('event').each(function() {
event.push({
title: $(this).attr('title'),
start: $(this).attr('start') // will be parsed
});
});
callback(events);
}
});
}
});
However, if you have the choice, JSON is a better idea because you can just specify a
[feed URL](events_json_feed).