In case people need a handy script to load their Google Calendar data
onto their site using AJAX:
var GCalendar = new Class({
Implements: [Options, Events],
options: {
uri: "",
orderby: "starttime",
singleEvents: true,
futureEvents: true,
sortOrder: "ascending",
maxResults: 5
/*onSuccess: $empty*/
},
entries: {},
initialize: function(options) {
this.setOptions(options);
options = this.options;
window.activeCalendar = this;
var script = new Asset.javascript(
"http://www.google.com/calendar/feeds/" +
options.uri +
"/public/full-noattendees?orderby=" +
options.orderby +
"&alt=json-in-
script&callback=window.activeCalendar.parseFeed&" +
"&max-results=" + options.maxResults +
"&singleevents=" + options.singleEvents +
"&sortorder=" + options.sortOrder +
"&futureevents=" + options.futureEvents
);
return this;
},
parseFeed: function(json){
var cal = this;
$A(json.feed.entry).each(function(e, i){
cal.entries[i] = (function(entry){
return $H({
title: entry.title.$t,
content: entry.content.$t,
startDate: cal.rfc3339toDate(entry.gd
$when[0].startTime),
endDate: cal.rfc3339toDate(entry.gd
$when[0].endTime),
location: entry.gd$where[0].valueString
});
})(e)
});
this.fireEvent('success');
},
rfc3339toDate: function(t){
t = t.substr(0,19).replace(/-/g,"/").replace("T"," ");
var dt = new Date();
dt.setTime(Date.parse(t));
return dt;
}
});
When you instantiate the class, pass an onSuccess function that
references "this.entries" and uses those Hashes to generate whatever
HTML they may need.