Right then, I'm using FullCalendar to display events from multiple sources, some local JSON feeds, others from Google Calendar. I've implemented a feature whereby a single calendar can be displayed / hidden when it's checkbox is true or false respectively.
I'm using this code to achive it:
$('#calendar_list input','#sidebar').live('click', function() {
if($(this).is(":checked")==true) {
// display the calendar
var source = $.fullCalendar.gcalFeed("http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic");
$('#calendar').fullCalendar('addEventSource', source);
} else {
// remove the calendar
var source = $.fullCalendar.gcalFeed("http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic");
$('#calendar').fullCalendar('removeEventSource', source);
}
});
This example if just to show / hide a Google Calendar feed, the problem is it never hides the calendar again... if I click the check box 10 times, (1=off, 2=on, 3=off, 4=on etc) it displays 5 versions of the same calendar.
The documentation doesn't really seem to give many clues and it seems this problem has plauged a few on the Google Project site for the project.
How to I remove an event souce?! *cries*
Any help would be appreciated.
Right then, I've actually found the solution to my problem, I decided to look back over the Google Project issues and noticed that someone had raised an issue for the same problem I was having, now the documentation says:
Source must be a reference to the original Array/URL/Function. Events from the source will immediately be removed from the calendar.
I thought this meant to remove a calendar I would have to use an identical source to the one I added, so if I added source /getEvents.php
I would have to remove it in the same way, instead what it actually means is that I have to use the exact same source.
So I set the source as an item in an array (calendar id as the key) and then I can add / remove the calendar based on this, this has now solved the problem.
You should rerender events after adding/removing a source, or maybe try to refetch events if that doesn't work. That might be the problem.
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