cssClass, beefed up events option

This commit is contained in:
Adam Shaw 2009-05-17 17:41:48 +00:00
parent b5e2a24619
commit a0c0f30a65
3 changed files with 97 additions and 35 deletions

View file

@ -1,4 +1,9 @@
version 1.2
- cssClass attribute for CalEvents
- multiple event sources (using an array for the 'events' option)
- the 'events' option for fullCalendar() and gcalFullCalendar() is now optional
version 1.1 (5/10/09) version 1.1 (5/10/09)
- Added the following options: - Added the following options:
- weekStart - weekStart

View file

@ -47,13 +47,32 @@
var tdTopBug, trTopBug, tbodyTopBug, sniffBugs = true; var tdTopBug, trTopBug, tbodyTopBug, sniffBugs = true;
var eventSources;
var eo = options.events;
if (eo) {
if (typeof eo == 'string' || $.isFunction(eo)) {
eventSources = [eo];
}else{
var item = eo[0];
if (item) {
if (typeof item == 'string' || $.isFunction(item))
eventSources = eo;
else {
eventSources = [eo];
}
}
}
}
else eventSources = [];
this.each(function() { this.each(function() {
var date = options.year ? new Date(options.year, options.month || 0, 1) : new Date(); var date = options.year ? new Date(options.year, options.month || 0, 1) : new Date();
var start, end, today, numWeeks; var start, end, today, numWeeks;
var events = typeof options.events != 'string' && !$.isFunction(options.events) ?
cleanEvents(options.events) : null;
var ignoreResizes = false; var ignoreResizes = false;
var events;
function updateMonth() { function updateMonth() {
clearEvents(); clearEvents();
@ -80,12 +99,41 @@
updateMonth(); updateMonth();
} }
/*function updateEvent(event) {
}
function removeEvent(event) {
var eventId = typeof event == 'object' ? event.id : event;
var newEvents = [];
for (var i=0; i<events.length; i++) {
if (events[i]) {
newEvents.push(events[i]);
}
}
events = newEvents;
renderEvents();
}
function removeEventsNoId() {
var newEvents = [];
for (var i=0; i<events.length; i++) {
if (events[i].id || typeof events[i].id == 'number') {
newEvents.push(events[i]);
}
}
events = newEvents;
renderEvents();
}*/
$.data(this, 'fullCalendar', { $.data(this, 'fullCalendar', {
today: today, today: today,
prevMonth: prevMonth, prevMonth: prevMonth,
nextMonth: nextMonth, nextMonth: nextMonth,
gotoMonth: gotoMonth, gotoMonth: gotoMonth,
refresh: updateMonth refresh: updateMonth
//updateEvent: updateEvent,
//removeEvent: removeEvent,
//removeUnsavedEvents: removeUnsavedEvents
}); });
@ -270,28 +318,36 @@
sniffBugs = false; sniffBugs = false;
} }
if (typeof options.events == 'string') {
if (options.loading) options.loading(true); events = [];
var jsonOptions = {}; var completed = eventSources.length;
jsonOptions[options.startParam || 'start'] = Math.round(start.getTime() / 1000); var reportEvents = function(a) {
jsonOptions[options.endParam || 'end'] = Math.round(end.getTime() / 1000); events = events.concat(cleanEvents(a));
jsonOptions[options.cacheParam || '_'] = (new Date()).getTime(); if (--completed == 0) {
$.getJSON(options.events, jsonOptions, function(data) {
events = cleanEvents(data);
renderEvents(events);
if (options.loading) options.loading(false); if (options.loading) options.loading(false);
});
}
else if ($.isFunction(options.events)) {
if (options.loading) options.loading(true);
options.events(start, end,
function(data) {
events = cleanEvents(data);
renderEvents(events); renderEvents(events);
if (options.loading) options.loading(false);
});
} }
else if (events) renderEvents(events); };
if (options.loading) options.loading(true);
for (var i=0; i<eventSources.length; i++) {
var src = eventSources[i];
if (typeof src == 'string') {
var params = {};
params[options.startParam || 'start'] = Math.round(start.getTime() / 1000);
params[options.endParam || 'end'] = Math.round(end.getTime() / 1000);
params[options.cacheParam || '_'] = (new Date()).getTime();
$.getJSON(src, params, reportEvents);
}
else if ($.isFunction(src)) {
src(start, end, reportEvents);
}
else if (src) {
reportEvents(src);
}
}
ignoreResizes = false; ignoreResizes = false;
@ -339,9 +395,7 @@
}); });
} }
}); });
segs.sort(function(a, b) { segs.sort(segSort);
return (b.msLength - a.msLength) * 100 + (a.event.start - b.event.start);
});
var levels = []; var levels = [];
$.each(segs, function(j, seg) { $.each(segs, function(j, seg) {
var l = 0; // level index var l = 0; // level index
@ -431,6 +485,7 @@
"<td class='s'/>" + "<td class='s'/>" +
(roundE ? "<td class='se'/>" : '') + "</tr>"); (roundE ? "<td class='se'/>" : '') + "</tr>");
buildEventText(event, element.find('td.c')); buildEventText(event, element.find('td.c'));
if (event.cssClass) element.addClass(event.cssClass);
if (options.eventRender) { if (options.eventRender) {
var res = options.eventRender(event, element); var res = options.eventRender(event, element);
if (typeof res != 'undefined') { if (typeof res != 'undefined') {
@ -746,8 +801,7 @@
// string utilities // string utilities
function zeroPad(n) { function zeroPad(n) {
if (n < 10) return '0' + n; return (n < 10 ? '0' : '') + n;
return n;
} }
@ -764,6 +818,10 @@
return events; return events;
} }
function segSort(a, b) {
return (b.msLength - a.msLength) * 100 + (a.event.start - b.event.start);
}
// date utils // date utils
@ -832,13 +890,12 @@
$.ISO8601String = function(date) { $.ISO8601String = function(date) {
// derived from http://delete.me.uk/2005/03/iso8601.html // derived from http://delete.me.uk/2005/03/iso8601.html
var zeropad = function (num) { return ((num < 10) ? '0' : '') + num; }
return date.getUTCFullYear() + return date.getUTCFullYear() +
"-" + zeropad(date.getUTCMonth() + 1) + "-" + zeroPad(date.getUTCMonth() + 1) +
"-" + zeropad(date.getUTCDate()) + "-" + zeroPad(date.getUTCDate()) +
"T" + zeropad(date.getUTCHours()) + "T" + zeroPad(date.getUTCHours()) +
":" + zeropad(date.getUTCMinutes()) + ":" + zeroPad(date.getUTCMinutes()) +
":" + zeropad(date.getUTCSeconds()) + ":" + zeroPad(date.getUTCSeconds()) +
"Z"; "Z";
}; };

View file

@ -27,7 +27,7 @@
if (options && typeof options.events == 'string') { if (options && typeof options.events == 'string') {
feedURL = options.events; feedURL = options.events;
} }
else return this; else return this.fullCalendar(options);
feedURL = feedURL.replace(/\/basic$/, '/full'); feedURL = feedURL.replace(/\/basic$/, '/full');