fixed issues 554, 586, and 616

This commit is contained in:
Adam Shaw 2010-10-11 14:16:34 -07:00
parent 82aacbb9d8
commit 453fcf07e3
5 changed files with 202 additions and 30 deletions

View file

@ -26,6 +26,7 @@ function EventManager(options, eventSources) {
// locals
var fetchID = 0;
var eventStart, eventEnd;
var events = [];
var loadingLevel = 0;
@ -64,45 +65,49 @@ function EventManager(options, eventSources) {
// Fetch from ALL sources. Clear 'events' array and populate
function fetchEvents(callback) {
var view = getView();
events = [];
eventStart = cloneDate(view.visStart);
eventEnd = cloneDate(view.visEnd);
var queued = eventSources.length,
sourceDone = function() {
fetchEventSources(eventSources, callback);
}
// appends to the events array
function fetchEventSources(sources, callback) {
var savedID = ++fetchID;
var queued = sources.length;
var view = getView();
eventStart = cloneDate(view.visStart); // we don't need to make local copies b/c
eventEnd = cloneDate(view.visEnd); // eventStart/eventEnd is only assigned/manipulated here
function sourceDone(source, sourceEvents) {
if (savedID == fetchID && eventStart >= view.visStart && eventEnd <= view.visEnd) {
// same fetchEventSources call, and still in correct date range
if ($.inArray(source, eventSources) != -1) { // source hasn't been removed since we started
for (var i=0; i<sourceEvents.length; i++) {
normalizeEvent(sourceEvents[i]);
sourceEvents[i].source = source;
}
events = events.concat(sourceEvents);
}
if (!--queued) {
if (callback) {
callback(events);
}
}
}, i=0;
for (; i<eventSources.length; i++) {
fetchEventSource(eventSources[i], sourceDone);
}
}
for (var i=0; i<sources.length; i++) {
_fetchEventSource(sources[i], sourceDone);
}
}
// Fetch from a particular source. Append to the 'events' array
function fetchEventSource(src, callback) {
var prevView = getView(),
prevDate = getDate(),
reportEvents = function(a) {
if (prevView == getView() && +prevDate == +getDate() && // protects from fast switching
$.inArray(src, eventSources) != -1) { // makes sure source hasn't been removed
for (var i=0; i<a.length; i++) {
normalizeEvent(a[i]);
a[i].source = src;
function _fetchEventSource(src, callback) {
function reportEvents(a) {
callback(src, a);
}
events = events.concat(a);
if (callback) {
callback(a);
}
}
},
reportEventsAndPop = function(a) {
function reportEventsAndPop(a) {
reportEvents(a);
popLoading();
};
}
if (typeof src == 'string') {
var params = {};
params[options.startParam] = Math.round(eventStart.getTime() / 1000);
@ -130,6 +135,11 @@ function EventManager(options, eventSources) {
}
function fetchEventSource(src, callback) {
fetchEventSources([src], callback);
}
function refetchEvents() {
fetchEvents(rerenderEvents);
}

View file

@ -1,7 +1,6 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<link rel='stylesheet' type='text/css' href='../demos/redmond/theme.css' />
<script type='text/javascript' src='../src/_loader.js?debug'></script>
<script type='text/javascript' src='../src/gcal/_loader.js'></script>
<script type='text/javascript'>

50
tests/issue_554.html Normal file
View file

@ -0,0 +1,50 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type='text/javascript' src='../src/_loader.js?debug'></script>
<script type='text/javascript' src='../src/gcal/_loader.js'></script>
<script type='text/javascript'>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
year: 2010,
month: 9,
date: 31,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaDay'
},
events: $.fullCalendar.gcalFeed('http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic')
});
});
</script>
<style type='text/css'>
body {
margin-top: 40px;
text-align: center;
font-size: 13px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
#calendar {
width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<button onclick="$('#calendar').fullCalendar('gotoDate',2010,10,11);$('#calendar').fullCalendar('changeView','agendaDay')">gotoDate + changeView</button>
<div id='calendar'></div>
</body>
</html>

View file

@ -0,0 +1,57 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type='text/javascript' src='../src/_loader.js?debug'></script>
<script type='text/javascript' src='../src/gcal/_loader.js'></script>
<script type='text/javascript'>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,basicWeek,agendaDay,basicDay'
},
editable: true,
events: $.fullCalendar.gcalFeed('http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic')
});
});
function doit() {
var calendar = $('#calendar');
calendar.fullCalendar('removeEvents');
calendar.fullCalendar('refetchEvents');
calendar.fullCalendar('refetchEvents');
calendar.fullCalendar('refetchEvents');
calendar.fullCalendar('refetchEvents');
}
</script>
<style type='text/css'>
body {
margin-top: 40px;
text-align: center;
font-size: 13px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
#calendar {
width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<button onclick='doit()'>do it</button>
<div id='calendar'></div>
</body>
</html>

56
tests/issue_616.html Normal file
View file

@ -0,0 +1,56 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type='text/javascript' src='../src/_loader.js?debug'></script>
<script type='text/javascript' src='../src/gcal/_loader.js'></script>
<script type='text/javascript'>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,basicWeek,agendaDay,basicDay'
},
editable: true
});
});
function doit() {
var calendar = $('#calendar');
var gcal = $.fullCalendar.gcalFeed('http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic');
calendar.fullCalendar('addEventSource', gcal);
calendar.fullCalendar('refetchEvents');
}
</script>
<style type='text/css'>
body {
margin-top: 40px;
text-align: center;
font-size: 13px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
#calendar {
width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<button onclick='doit()'>do it</button>
<div id='calendar'></div>
</body>
</html>