1/*! 2 * FullCalendar v1.6.7 Google Calendar Plugin 3 * Docs & License: http://arshaw.com/fullcalendar/ 4 * (c) 2013 Adam Shaw 5 */ 6 7(function($) { 8 9 10var API_BASE = 'https://www.googleapis.com/calendar/v3/calendars'; 11var fc = $.fullCalendar; 12var formatDate = fc.formatDate; 13var parseISO8601 = fc.parseISO8601; 14var cloneDate = fc.cloneDate; 15var addDays = fc.addDays; 16var applyAll = fc.applyAll; 17 18 19fc.sourceNormalizers.push(function(sourceOptions) { 20 var googleCalendarId = sourceOptions.googleCalendarId; 21 var url = sourceOptions.url; 22 var match; 23 24 // if the Google Calendar ID hasn't been explicitly defined 25 if (!googleCalendarId && url) { 26 27 // detect if the ID was specified as a single string 28 if ((match = /^[^\/]+@([^\/]+\.)?calendar\.google\.com$/.test(url))) { 29 googleCalendarId = url; 30 } 31 // try to scrape it out of a V1 or V3 API feed URL 32 else if ( 33 (match = /^https:\/\/www.googleapis.com\/calendar\/v3\/calendars\/([^\/]*)/.exec(url)) || 34 (match = /^https?:\/\/www.google.com\/calendar\/feeds\/([^\/]*)/.exec(url)) 35 ) { 36 googleCalendarId = decodeURIComponent(match[1]); 37 } 38 39 if (googleCalendarId) { 40 sourceOptions.googleCalendarId = googleCalendarId; 41 } 42 } 43 44 45 if (googleCalendarId) { // is this a Google Calendar? 46 47 // make each Google Calendar source uneditable by default 48 if (sourceOptions.editable == null) { 49 sourceOptions.editable = false; 50 } 51 52 // We want removeEventSource to work, but it won't know about the googleCalendarId primitive. 53 // Shoehorn it into the url, which will function as the unique primitive. Won't cause side effects. 54 // This hack is obsolete since 1.6.7, but keep it so this plugin file is compatible with old versions. 55 sourceOptions.url = googleCalendarId; 56 } 57}); 58 59 60fc.sourceFetchers.push(function(sourceOptions, start, end) { 61 if (sourceOptions.googleCalendarId) { 62 return transformOptions(sourceOptions, start, end); 63 } 64}); 65 66 67function transformOptions(sourceOptions, start, end) { 68 var url = API_BASE + '/' + encodeURIComponent(sourceOptions.googleCalendarId) + '/events?callback=?'; // jsonp 69 var apiKey = sourceOptions.googleCalendarApiKey; 70 var ctz = sourceOptions.currentTimezone; 71 var success = sourceOptions.success; 72 var data; 73 74 function reportError(message, apiErrorObjs) { 75 var errorObjs = apiErrorObjs || [ { message: message } ]; // to be passed into error handlers 76 var consoleObj = window.console; 77 var consoleWarnFunc = consoleObj ? (consoleObj.warn || consoleObj.log) : null; 78 79 // call error handlers 80 (sourceOptions.googleCalendarError || $.noop).apply(null, errorObjs); 81 82 // print error to debug console 83 if (consoleWarnFunc) { 84 consoleWarnFunc.apply(consoleObj, [ message ].concat(apiErrorObjs || [])); 85 } 86 } 87 88 // The API expects an ISO8601 datetime with a time and timezone part. 89 // Since the calendar's timezone offset isn't always known, request the date in UTC and pad it by a day on each 90 // side, guaranteeing we will receive all events in the desired range, albeit a superset. 91 start = addDays(cloneDate(start), -1); 92 end = addDays(cloneDate(end), 1); 93 94 if (!apiKey) { 95 reportError("Specify a googleCalendarApiKey. See http://fullcalendar.io/docs1/google_calendar/"); 96 return {}; // an empty source to use instead. won't fetch anything. 97 } 98 99 data = $.extend({}, sourceOptions.data || {}, { 100 key: apiKey, 101 timeMin: formatDate(start, 'u'), 102 timeMax: formatDate(end, 'u'), 103 singleEvents: true, 104 maxResults: 9999 105 }); 106 107 if (ctz) { 108 data.timeZone = ctz = ctz.replace(' ', '_'); 109 } 110 111 return $.extend({}, sourceOptions, { 112 googleCalendarId: null, // prevents source-normalizing from happening again 113 url: url, 114 data: data, 115 startParam: false, // `false` omits this parameter. we already included it above 116 endParam: false, // same 117 success: function(data) { 118 var events = []; 119 var successArgs; 120 var successRes; 121 122 if (data.error) { 123 reportError('Google Calendar API: ' + data.error.message, data.error.errors); 124 } 125 else if (data.items) { 126 $.each(data.items, function(i, entry) { 127 var allDay = !entry.start.dateTime && !entry.end.dateTime; 128 var start = parseISO8601(entry.start.dateTime || entry.start.date, true); 129 var end = parseISO8601(entry.end.dateTime || entry.end.date, true); 130 var url = entry.htmlLink; 131 132 if (allDay) { 133 addDays(end, -1); // make inclusive 134 } 135 136 if (ctz) { 137 url += (url.indexOf('?') == -1 ? '?' : '&') + 'ctz=' + ctz; 138 } 139 140 events.push({ 141 id: entry.id, 142 title: entry.summary, 143 allDay: allDay, 144 start: start, 145 end: end, 146 url: url, 147 location: entry.location, 148 description: entry.description 149 }); 150 }); 151 152 // call the success handler(s) and allow it to return a new events array 153 successArgs = [ events ].concat(Array.prototype.slice.call(arguments, 1)); // forward other jq args 154 successRes = applyAll(success, this, successArgs); 155 if ($.isArray(successRes)) { 156 return successRes; 157 } 158 } 159 160 return events; 161 } 162 }); 163 164} 165 166 167// legacy 168fc.gcalFeed = function(url, sourceOptions) { 169 return $.extend({}, sourceOptions, { url: url }); 170}; 171 172 173})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.