gcal.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*!
  2. * FullCalendar v3.10.2
  3. * Docs & License: https://fullcalendar.io/
  4. * (c) 2019 Adam Shaw
  5. */
  6. (function webpackUniversalModuleDefinition(root, factory) {
  7. if(typeof exports === 'object' && typeof module === 'object')
  8. module.exports = factory(require("fullcalendar"), require("jquery"));
  9. else if(typeof define === 'function' && define.amd)
  10. define(["fullcalendar", "jquery"], factory);
  11. else if(typeof exports === 'object')
  12. factory(require("fullcalendar"), require("jquery"));
  13. else
  14. factory(root["FullCalendar"], root["jQuery"]);
  15. })(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_3__) {
  16. return /******/ (function(modules) { // webpackBootstrap
  17. /******/ // The module cache
  18. /******/ var installedModules = {};
  19. /******/
  20. /******/ // The require function
  21. /******/ function __webpack_require__(moduleId) {
  22. /******/
  23. /******/ // Check if module is in cache
  24. /******/ if(installedModules[moduleId]) {
  25. /******/ return installedModules[moduleId].exports;
  26. /******/ }
  27. /******/ // Create a new module (and put it into the cache)
  28. /******/ var module = installedModules[moduleId] = {
  29. /******/ i: moduleId,
  30. /******/ l: false,
  31. /******/ exports: {}
  32. /******/ };
  33. /******/
  34. /******/ // Execute the module function
  35. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  36. /******/
  37. /******/ // Flag the module as loaded
  38. /******/ module.l = true;
  39. /******/
  40. /******/ // Return the exports of the module
  41. /******/ return module.exports;
  42. /******/ }
  43. /******/
  44. /******/
  45. /******/ // expose the modules object (__webpack_modules__)
  46. /******/ __webpack_require__.m = modules;
  47. /******/
  48. /******/ // expose the module cache
  49. /******/ __webpack_require__.c = installedModules;
  50. /******/
  51. /******/ // define getter function for harmony exports
  52. /******/ __webpack_require__.d = function(exports, name, getter) {
  53. /******/ if(!__webpack_require__.o(exports, name)) {
  54. /******/ Object.defineProperty(exports, name, {
  55. /******/ configurable: false,
  56. /******/ enumerable: true,
  57. /******/ get: getter
  58. /******/ });
  59. /******/ }
  60. /******/ };
  61. /******/
  62. /******/ // getDefaultExport function for compatibility with non-harmony modules
  63. /******/ __webpack_require__.n = function(module) {
  64. /******/ var getter = module && module.__esModule ?
  65. /******/ function getDefault() { return module['default']; } :
  66. /******/ function getModuleExports() { return module; };
  67. /******/ __webpack_require__.d(getter, 'a', getter);
  68. /******/ return getter;
  69. /******/ };
  70. /******/
  71. /******/ // Object.prototype.hasOwnProperty.call
  72. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  73. /******/
  74. /******/ // __webpack_public_path__
  75. /******/ __webpack_require__.p = "";
  76. /******/
  77. /******/ // Load entry module and return exports
  78. /******/ return __webpack_require__(__webpack_require__.s = 270);
  79. /******/ })
  80. /************************************************************************/
  81. /******/ ({
  82. /***/ 1:
  83. /***/ (function(module, exports) {
  84. module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
  85. /***/ }),
  86. /***/ 2:
  87. /***/ (function(module, exports) {
  88. /*
  89. derived from:
  90. https://github.com/Microsoft/tslib/blob/v1.6.0/tslib.js
  91. only include the helpers we need, to keep down filesize
  92. */
  93. var extendStatics = Object.setPrototypeOf ||
  94. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  95. function (d, b) { for (var p in b)
  96. if (b.hasOwnProperty(p))
  97. d[p] = b[p]; };
  98. exports.__extends = function (d, b) {
  99. extendStatics(d, b);
  100. function __() { this.constructor = d; }
  101. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  102. };
  103. /***/ }),
  104. /***/ 270:
  105. /***/ (function(module, exports, __webpack_require__) {
  106. Object.defineProperty(exports, "__esModule", { value: true });
  107. var exportHooks = __webpack_require__(1);
  108. var GcalEventSource_1 = __webpack_require__(271);
  109. exportHooks.EventSourceParser.registerClass(GcalEventSource_1.default);
  110. exportHooks.GcalEventSource = GcalEventSource_1.default;
  111. /***/ }),
  112. /***/ 271:
  113. /***/ (function(module, exports, __webpack_require__) {
  114. Object.defineProperty(exports, "__esModule", { value: true });
  115. var tslib_1 = __webpack_require__(2);
  116. var $ = __webpack_require__(3);
  117. var fullcalendar_1 = __webpack_require__(1);
  118. var GcalEventSource = /** @class */ (function (_super) {
  119. tslib_1.__extends(GcalEventSource, _super);
  120. function GcalEventSource() {
  121. return _super !== null && _super.apply(this, arguments) || this;
  122. }
  123. GcalEventSource.parse = function (rawInput, calendar) {
  124. var rawProps;
  125. if (typeof rawInput === 'object') { // long form. might fail in applyManualStandardProps
  126. rawProps = rawInput;
  127. }
  128. else if (typeof rawInput === 'string') { // short form
  129. rawProps = { url: rawInput }; // url will be parsed with parseGoogleCalendarId
  130. }
  131. if (rawProps) {
  132. return fullcalendar_1.EventSource.parse.call(this, rawProps, calendar);
  133. }
  134. return false;
  135. };
  136. GcalEventSource.prototype.fetch = function (start, end, timezone) {
  137. var _this = this;
  138. var url = this.buildUrl();
  139. var requestParams = this.buildRequestParams(start, end, timezone);
  140. var ajaxSettings = this.ajaxSettings || {};
  141. var onSuccess = ajaxSettings.success;
  142. if (!requestParams) { // could have failed
  143. return fullcalendar_1.Promise.reject();
  144. }
  145. this.calendar.pushLoading();
  146. return fullcalendar_1.Promise.construct(function (onResolve, onReject) {
  147. $.ajax($.extend({}, // destination
  148. fullcalendar_1.JsonFeedEventSource.AJAX_DEFAULTS, ajaxSettings, {
  149. url: url,
  150. data: requestParams,
  151. success: function (responseData, status, xhr) {
  152. var rawEventDefs;
  153. var successRes;
  154. _this.calendar.popLoading();
  155. if (responseData.error) {
  156. _this.reportError('Google Calendar API: ' + responseData.error.message, responseData.error.errors);
  157. onReject();
  158. }
  159. else if (responseData.items) {
  160. rawEventDefs = _this.gcalItemsToRawEventDefs(responseData.items, requestParams.timeZone);
  161. successRes = fullcalendar_1.applyAll(onSuccess, _this, [responseData, status, xhr]); // passthru
  162. if ($.isArray(successRes)) {
  163. rawEventDefs = successRes;
  164. }
  165. onResolve(_this.parseEventDefs(rawEventDefs));
  166. }
  167. },
  168. error: function (xhr, statusText, errorThrown) {
  169. _this.reportError('Google Calendar network failure: ' + statusText, [xhr, errorThrown]);
  170. _this.calendar.popLoading();
  171. onReject();
  172. }
  173. }));
  174. });
  175. };
  176. GcalEventSource.prototype.gcalItemsToRawEventDefs = function (items, gcalTimezone) {
  177. var _this = this;
  178. return items.map(function (item) {
  179. return _this.gcalItemToRawEventDef(item, gcalTimezone);
  180. });
  181. };
  182. GcalEventSource.prototype.gcalItemToRawEventDef = function (item, gcalTimezone) {
  183. var url = item.htmlLink || null;
  184. // make the URLs for each event show times in the correct timezone
  185. if (url && gcalTimezone) {
  186. url = injectQsComponent(url, 'ctz=' + gcalTimezone);
  187. }
  188. var extendedProperties = {};
  189. if (typeof item.extendedProperties === 'object' &&
  190. typeof item.extendedProperties.shared === 'object') {
  191. extendedProperties = item.extendedProperties.shared;
  192. }
  193. return {
  194. id: item.id,
  195. title: item.summary,
  196. start: item.start.dateTime || item.start.date,
  197. end: item.end.dateTime || item.end.date,
  198. url: url,
  199. location: item.location,
  200. description: item.description,
  201. extendedProperties: extendedProperties
  202. };
  203. };
  204. GcalEventSource.prototype.buildUrl = function () {
  205. return GcalEventSource.API_BASE + '/' +
  206. encodeURIComponent(this.googleCalendarId) +
  207. '/events?callback=?'; // jsonp
  208. };
  209. GcalEventSource.prototype.buildRequestParams = function (start, end, timezone) {
  210. var apiKey = this.googleCalendarApiKey || this.calendar.opt('googleCalendarApiKey');
  211. var params;
  212. if (!apiKey) {
  213. this.reportError('Specify a googleCalendarApiKey. See http://fullcalendar.io/docs/google_calendar/');
  214. return null;
  215. }
  216. // The API expects an ISO8601 datetime with a time and timezone part.
  217. // Since the calendar's timezone offset isn't always known, request the date in UTC and pad it by a day on each
  218. // side, guaranteeing we will receive all events in the desired range, albeit a superset.
  219. // .utc() will set a zone and give it a 00:00:00 time.
  220. if (!start.hasZone()) {
  221. start = start.clone().utc().add(-1, 'day');
  222. }
  223. if (!end.hasZone()) {
  224. end = end.clone().utc().add(1, 'day');
  225. }
  226. params = $.extend(this.ajaxSettings.data || {}, {
  227. key: apiKey,
  228. timeMin: start.format(),
  229. timeMax: end.format(),
  230. singleEvents: true,
  231. maxResults: 9999
  232. });
  233. if (timezone && timezone !== 'local') {
  234. // when sending timezone names to Google, only accepts underscores, not spaces
  235. params.timeZone = timezone.replace(' ', '_');
  236. }
  237. return params;
  238. };
  239. GcalEventSource.prototype.reportError = function (message, apiErrorObjs) {
  240. var calendar = this.calendar;
  241. var calendarOnError = calendar.opt('googleCalendarError');
  242. var errorObjs = apiErrorObjs || [{ message: message }]; // to be passed into error handlers
  243. if (this.googleCalendarError) {
  244. this.googleCalendarError.apply(calendar, errorObjs);
  245. }
  246. if (calendarOnError) {
  247. calendarOnError.apply(calendar, errorObjs);
  248. }
  249. // print error to debug console
  250. fullcalendar_1.warn.apply(null, [message].concat(apiErrorObjs || []));
  251. };
  252. GcalEventSource.prototype.getPrimitive = function () {
  253. return this.googleCalendarId;
  254. };
  255. GcalEventSource.prototype.applyManualStandardProps = function (rawProps) {
  256. var superSuccess = fullcalendar_1.EventSource.prototype.applyManualStandardProps.apply(this, arguments);
  257. var googleCalendarId = rawProps.googleCalendarId;
  258. if (googleCalendarId == null && rawProps.url) {
  259. googleCalendarId = parseGoogleCalendarId(rawProps.url);
  260. }
  261. if (googleCalendarId != null) {
  262. this.googleCalendarId = googleCalendarId;
  263. return superSuccess;
  264. }
  265. return false;
  266. };
  267. GcalEventSource.prototype.applyMiscProps = function (rawProps) {
  268. if (!this.ajaxSettings) {
  269. this.ajaxSettings = {};
  270. }
  271. $.extend(this.ajaxSettings, rawProps);
  272. };
  273. GcalEventSource.API_BASE = 'https://www.googleapis.com/calendar/v3/calendars';
  274. return GcalEventSource;
  275. }(fullcalendar_1.EventSource));
  276. exports.default = GcalEventSource;
  277. GcalEventSource.defineStandardProps({
  278. // manually process...
  279. url: false,
  280. googleCalendarId: false,
  281. // automatically transfer...
  282. googleCalendarApiKey: true,
  283. googleCalendarError: true
  284. });
  285. function parseGoogleCalendarId(url) {
  286. var match;
  287. // detect if the ID was specified as a single string.
  288. // will match calendars like "asdf1234@calendar.google.com" in addition to person email calendars.
  289. if (/^[^\/]+@([^\/\.]+\.)*(google|googlemail|gmail)\.com$/.test(url)) {
  290. return url;
  291. }
  292. else if ((match = /^https:\/\/www.googleapis.com\/calendar\/v3\/calendars\/([^\/]*)/.exec(url)) ||
  293. (match = /^https?:\/\/www.google.com\/calendar\/feeds\/([^\/]*)/.exec(url))) {
  294. return decodeURIComponent(match[1]);
  295. }
  296. }
  297. // Injects a string like "arg=value" into the querystring of a URL
  298. function injectQsComponent(url, component) {
  299. // inject it after the querystring but before the fragment
  300. return url.replace(/(\?.*?)?(#|$)/, function (whole, qs, hash) {
  301. return (qs ? qs + '&' : '?') + component + hash;
  302. });
  303. }
  304. /***/ }),
  305. /***/ 3:
  306. /***/ (function(module, exports) {
  307. module.exports = __WEBPACK_EXTERNAL_MODULE_3__;
  308. /***/ })
  309. /******/ });
  310. });