]> git.mxchange.org Git - friendica.git/blob - library/fullcalendar/gcal.js
Fix generated po headers
[friendica.git] / library / fullcalendar / gcal.js
1 /*!
2  * FullCalendar v1.6.4 Google Calendar Plugin
3  * Docs & License: http://arshaw.com/fullcalendar/
4  * (c) 2013 Adam Shaw
5  */
6  
7 (function($) {
8
9
10 var fc = $.fullCalendar;
11 var formatDate = fc.formatDate;
12 var parseISO8601 = fc.parseISO8601;
13 var addDays = fc.addDays;
14 var applyAll = fc.applyAll;
15
16
17 fc.sourceNormalizers.push(function(sourceOptions) {
18         if (sourceOptions.dataType == 'gcal' ||
19                 sourceOptions.dataType === undefined &&
20                 (sourceOptions.url || '').match(/^(http|https):\/\/www.google.com\/calendar\/feeds\//)) {
21                         sourceOptions.dataType = 'gcal';
22                         if (sourceOptions.editable === undefined) {
23                                 sourceOptions.editable = false;
24                         }
25                 }
26 });
27
28
29 fc.sourceFetchers.push(function(sourceOptions, start, end) {
30         if (sourceOptions.dataType == 'gcal') {
31                 return transformOptions(sourceOptions, start, end);
32         }
33 });
34
35
36 function transformOptions(sourceOptions, start, end) {
37
38         var success = sourceOptions.success;
39         var data = $.extend({}, sourceOptions.data || {}, {
40                 'start-min': formatDate(start, 'u'),
41                 'start-max': formatDate(end, 'u'),
42                 'singleevents': true,
43                 'max-results': 9999
44         });
45         
46         var ctz = sourceOptions.currentTimezone;
47         if (ctz) {
48                 data.ctz = ctz = ctz.replace(' ', '_');
49         }
50
51         return $.extend({}, sourceOptions, {
52                 url: sourceOptions.url.replace(/\/basic$/, '/full') + '?alt=json-in-script&callback=?',
53                 dataType: 'jsonp',
54                 data: data,
55                 startParam: false,
56                 endParam: false,
57                 success: function(data) {
58                         var events = [];
59                         if (data.feed.entry) {
60                                 $.each(data.feed.entry, function(i, entry) {
61                                         var startStr = entry['gd$when'][0]['startTime'];
62                                         var start = parseISO8601(startStr, true);
63                                         var end = parseISO8601(entry['gd$when'][0]['endTime'], true);
64                                         var allDay = startStr.indexOf('T') == -1;
65                                         var url;
66                                         $.each(entry.link, function(i, link) {
67                                                 if (link.type == 'text/html') {
68                                                         url = link.href;
69                                                         if (ctz) {
70                                                                 url += (url.indexOf('?') == -1 ? '?' : '&') + 'ctz=' + ctz;
71                                                         }
72                                                 }
73                                         });
74                                         if (allDay) {
75                                                 addDays(end, -1); // make inclusive
76                                         }
77                                         events.push({
78                                                 id: entry['gCal$uid']['value'],
79                                                 title: entry['title']['$t'],
80                                                 url: url,
81                                                 start: start,
82                                                 end: end,
83                                                 allDay: allDay,
84                                                 location: entry['gd$where'][0]['valueString'],
85                                                 description: entry['content']['$t']
86                                         });
87                                 });
88                         }
89                         var args = [events].concat(Array.prototype.slice.call(arguments, 1));
90                         var res = applyAll(success, this, args);
91                         if ($.isArray(res)) {
92                                 return res;
93                         }
94                         return events;
95                 }
96         });
97         
98 }
99
100
101 // legacy
102 fc.gcalFeed = function(url, sourceOptions) {
103         return $.extend({}, sourceOptions, { url: url, dataType: 'gcal' });
104 };
105
106
107 })(jQuery);