fullcalendar/gcal.js

66 lines
2 KiB
JavaScript
Raw Normal View History

2009-04-27 05:46:02 +02:00
/*
* gcalFullCalendar extension for fullCalendar
* http://arshaw.com/fullcalendar/
*
* Same usage/options as fullCalendar.
* However, enter your Google Calendar's public feed URL in the 'events' option.
* Here is how to find it in the Google Calendar interface:
*
* -> click the arrow next to your calendar's name
* -> click "Share this calendar"
* -> check "Make this calendar public" and then Save
* -> click the arrow again, then click "Calendar settings"
* -> in the "Calendar Address" section, click the XML rectangle
* -> the URL is displayed
*
* Copyright (c) 2009 Adam Shaw
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
2009-04-26 06:43:27 +02:00
(function($) {
2009-05-30 07:54:53 +02:00
$.fullCalendar.gcalFeed = function(feedUrl, options) {
2009-04-26 06:43:27 +02:00
2009-05-30 07:54:53 +02:00
feedUrl = feedUrl.replace(/\/basic$/, '/full');
options = options || {};
var draggable = options.draggable || false;
2009-04-26 06:43:27 +02:00
2009-05-30 07:54:53 +02:00
return function(start, end, callback) {
$.getJSON(feedUrl + "?alt=json-in-script&callback=?",
{
'start-min': $.fullCalendar.formatDate(start, 'c'),
'start-max': $.fullCalendar.formatDate(end, 'c'),
'singleevents': true
},
function(data) {
var events = [];
if (data.feed.entry)
$.each(data.feed.entry, function(i, entry) {
var url;
$.each(entry['link'], function(j, link) {
if (link.type == 'text/html') url = link.href;
2009-04-26 06:43:27 +02:00
});
2009-05-30 07:54:53 +02:00
var showTime = entry['gd$when'][0]['startTime'].indexOf('T') != -1;
events.push({
id: entry['gCal$uid']['value'],
url: url,
title: entry['title']['$t'],
start: $.fullCalendar.parseDate(entry['gd$when'][0]['startTime']),
end: $.fullCalendar.parseDate(entry['gd$when'][0]['endTime']),
location: entry['gd$where'][0]['valueString'],
description: entry['content']['$t'],
showTime: showTime,
className: [showTime ? 'nobg' : null, options.className],
draggable: draggable
});
});
callback(events);
});
}
2009-04-26 06:43:27 +02:00
2009-05-30 07:54:53 +02:00
}
2009-04-26 06:43:27 +02:00
})(jQuery);