diff options
author | friendica <info@friendica.com> | 2012-02-15 14:13:20 -0800 |
---|---|---|
committer | friendica <info@friendica.com> | 2012-02-15 14:13:20 -0800 |
commit | c965074e5343bf97a8d077e1dc00384f36f90acc (patch) | |
tree | c7b9545accad1fd1ee7ea5e98e6bbf6067ff2280 /library/fullcalendar/gcal.js | |
parent | 18b307f9830b99a7f8b44db648740945de9b89af (diff) | |
parent | 16f00cb73b4d9acbe15e636b3ab69f81c793a6c7 (diff) | |
download | volse-hubzilla-c965074e5343bf97a8d077e1dc00384f36f90acc.tar.gz volse-hubzilla-c965074e5343bf97a8d077e1dc00384f36f90acc.tar.bz2 volse-hubzilla-c965074e5343bf97a8d077e1dc00384f36f90acc.zip |
Merge branch 'pull'
Diffstat (limited to 'library/fullcalendar/gcal.js')
-rw-r--r-- | library/fullcalendar/gcal.js | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/library/fullcalendar/gcal.js b/library/fullcalendar/gcal.js new file mode 100644 index 000000000..e9bbe26d8 --- /dev/null +++ b/library/fullcalendar/gcal.js @@ -0,0 +1,112 @@ +/* + * FullCalendar v1.5.3 Google Calendar Plugin + * + * Copyright (c) 2011 Adam Shaw + * Dual licensed under the MIT and GPL licenses, located in + * MIT-LICENSE.txt and GPL-LICENSE.txt respectively. + * + * Date: Mon Feb 6 22:40:40 2012 -0800 + * + */ + +(function($) { + + +var fc = $.fullCalendar; +var formatDate = fc.formatDate; +var parseISO8601 = fc.parseISO8601; +var addDays = fc.addDays; +var applyAll = fc.applyAll; + + +fc.sourceNormalizers.push(function(sourceOptions) { + if (sourceOptions.dataType == 'gcal' || + sourceOptions.dataType === undefined && + (sourceOptions.url || '').match(/^(http|https):\/\/www.google.com\/calendar\/feeds\//)) { + sourceOptions.dataType = 'gcal'; + if (sourceOptions.editable === undefined) { + sourceOptions.editable = false; + } + } +}); + + +fc.sourceFetchers.push(function(sourceOptions, start, end) { + if (sourceOptions.dataType == 'gcal') { + return transformOptions(sourceOptions, start, end); + } +}); + + +function transformOptions(sourceOptions, start, end) { + + var success = sourceOptions.success; + var data = $.extend({}, sourceOptions.data || {}, { + 'start-min': formatDate(start, 'u'), + 'start-max': formatDate(end, 'u'), + 'singleevents': true, + 'max-results': 9999 + }); + + var ctz = sourceOptions.currentTimezone; + if (ctz) { + data.ctz = ctz = ctz.replace(' ', '_'); + } + + return $.extend({}, sourceOptions, { + url: sourceOptions.url.replace(/\/basic$/, '/full') + '?alt=json-in-script&callback=?', + dataType: 'jsonp', + data: data, + startParam: false, + endParam: false, + success: function(data) { + var events = []; + if (data.feed.entry) { + $.each(data.feed.entry, function(i, entry) { + var startStr = entry['gd$when'][0]['startTime']; + var start = parseISO8601(startStr, true); + var end = parseISO8601(entry['gd$when'][0]['endTime'], true); + var allDay = startStr.indexOf('T') == -1; + var url; + $.each(entry.link, function(i, link) { + if (link.type == 'text/html') { + url = link.href; + if (ctz) { + url += (url.indexOf('?') == -1 ? '?' : '&') + 'ctz=' + ctz; + } + } + }); + if (allDay) { + addDays(end, -1); // make inclusive + } + events.push({ + id: entry['gCal$uid']['value'], + title: entry['title']['$t'], + url: url, + start: start, + end: end, + allDay: allDay, + location: entry['gd$where'][0]['valueString'], + description: entry['content']['$t'] + }); + }); + } + var args = [events].concat(Array.prototype.slice.call(arguments, 1)); + var res = applyAll(success, this, args); + if ($.isArray(res)) { + return res; + } + return events; + } + }); + +} + + +// legacy +fc.gcalFeed = function(url, sourceOptions) { + return $.extend({}, sourceOptions, { url: url, dataType: 'gcal' }); +}; + + +})(jQuery); |