forked from fullcalendar/fullcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
68 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/*! | ||
* FullCalendar v2.2.2 Google Calendar Plugin | ||
* FullCalendar v2.2.3 Google Calendar Plugin | ||
* Docs & License: http://arshaw.com/fullcalendar/ | ||
* (c) 2013 Adam Shaw | ||
*/ | ||
|
@@ -27,8 +27,9 @@ fc.sourceNormalizers.push(function(sourceOptions) { | |
// if the Google Calendar ID hasn't been explicitly defined | ||
if (!googleCalendarId && url) { | ||
|
||
// detect if the ID was specified as a single string | ||
if ((match = /^[^\/]+@([^\/]+\.)?calendar\.google\.com$/.test(url))) { | ||
// detect if the ID was specified as a single string. | ||
// will match calendars like "[email protected]" in addition to person email calendars. | ||
if ((match = /^[^\/]+@([^\/\.]+\.)*(google|googlemail|gmail)\.com$/.test(url))) { | ||
googleCalendarId = url; | ||
} | ||
// try to scrape it out of a V1 or V3 API feed URL | ||
|
@@ -54,6 +55,7 @@ fc.sourceNormalizers.push(function(sourceOptions) { | |
|
||
// We want removeEventSource to work, but it won't know about the googleCalendarId primitive. | ||
// Shoehorn it into the url, which will function as the unique primitive. Won't cause side effects. | ||
// This hack is obsolete since 2.2.3, but keep it so this plugin file is compatible with old versions. | ||
sourceOptions.url = googleCalendarId; | ||
} | ||
}); | ||
|
@@ -71,6 +73,7 @@ function transformOptions(sourceOptions, start, end, timezone, calendar) { | |
var apiKey = sourceOptions.googleCalendarApiKey || calendar.options.googleCalendarApiKey; | ||
var success = sourceOptions.success; | ||
var data; | ||
var timezoneArg; // populated when a specific timezone. escaped to Google's liking | ||
|
||
function reportError(message, apiErrorObjs) { | ||
var errorObjs = apiErrorObjs || [ { message: message } ]; // to be passed into error handlers | ||
|
@@ -103,10 +106,16 @@ function transformOptions(sourceOptions, start, end, timezone, calendar) { | |
end = end.clone().utc().add(1, 'day'); | ||
} | ||
|
||
// when sending timezone names to Google, only accepts underscores, not spaces | ||
if (timezone && timezone != 'local') { | ||
timezoneArg = timezone.replace(' ', '_'); | ||
} | ||
|
||
data = $.extend({}, sourceOptions.data || {}, { | ||
key: apiKey, | ||
timeMin: start.format(), | ||
timeMax: end.format(), | ||
timeZone: timezoneArg, | ||
singleEvents: true, | ||
maxResults: 9999 | ||
}); | ||
|
@@ -115,9 +124,9 @@ function transformOptions(sourceOptions, start, end, timezone, calendar) { | |
googleCalendarId: null, // prevents source-normalizing from happening again | ||
url: url, | ||
data: data, | ||
timezoneParam: 'timeZone', | ||
startParam: false, // `false` omits this parameter. we already included it above | ||
endParam: false, // same | ||
timezoneParam: false, // same | ||
success: function(data) { | ||
var events = []; | ||
var successArgs; | ||
|
@@ -128,12 +137,19 @@ function transformOptions(sourceOptions, start, end, timezone, calendar) { | |
} | ||
else if (data.items) { | ||
$.each(data.items, function(i, entry) { | ||
var url = entry.htmlLink; | ||
|
||
// make the URLs for each event show times in the correct timezone | ||
if (timezoneArg) { | ||
url = injectQsComponent(url, 'ctz=' + timezoneArg); | ||
} | ||
|
||
events.push({ | ||
id: entry.id, | ||
title: entry.summary, | ||
start: entry.start.dateTime || entry.start.date, // try timed. will fall back to all-day | ||
end: entry.end.dateTime || entry.end.date, // same | ||
url: entry.htmlLink, | ||
url: url, | ||
location: entry.location, | ||
description: entry.description | ||
}); | ||
|
@@ -153,4 +169,13 @@ function transformOptions(sourceOptions, start, end, timezone, calendar) { | |
} | ||
|
||
|
||
// Injects a string like "arg=value" into the querystring of a URL | ||
function injectQsComponent(url, component) { | ||
// inject it after the querystring but before the fragment | ||
return url.replace(/(\?.*?)?(#|$)/, function(whole, qs, hash) { | ||
return (qs ? qs + '&' : '?') + component + hash; | ||
}); | ||
} | ||
|
||
|
||
}); |
Oops, something went wrong.