gcal.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*!
  2. * FullCalendar v3.9.0
  3. * Docs & License: https://fullcalendar.io/
  4. * (c) 2018 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 = 266);
  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. /***/ 266:
  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__(267);
  109. exportHooks.EventSourceParser.registerClass(GcalEventSource_1.default);
  110. exportHooks.GcalEventSource = GcalEventSource_1.default;
  111. /***/ }),
  112. /***/ 267:
  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') {
  126. rawProps = rawInput;
  127. }
  128. else if (typeof rawInput === 'string') {
  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) {
  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. return {
  189. id: item.id,
  190. title: item.summary,
  191. start: item.start.dateTime || item.start.date,
  192. end: item.end.dateTime || item.end.date,
  193. url: url,
  194. location: item.location,
  195. description: item.description
  196. };
  197. };
  198. GcalEventSource.prototype.buildUrl = function () {
  199. return GcalEventSource.API_BASE + '/' +
  200. encodeURIComponent(this.googleCalendarId) +
  201. '/events?callback=?'; // jsonp
  202. };
  203. GcalEventSource.prototype.buildRequestParams = function (start, end, timezone) {
  204. var apiKey = this.googleCalendarApiKey || this.calendar.opt('googleCalendarApiKey');
  205. var params;
  206. if (!apiKey) {
  207. this.reportError('Specify a googleCalendarApiKey. See http://fullcalendar.io/docs/google_calendar/');
  208. return null;
  209. }
  210. // The API expects an ISO8601 datetime with a time and timezone part.
  211. // Since the calendar's timezone offset isn't always known, request the date in UTC and pad it by a day on each
  212. // side, guaranteeing we will receive all events in the desired range, albeit a superset.
  213. // .utc() will set a zone and give it a 00:00:00 time.
  214. if (!start.hasZone()) {
  215. start = start.clone().utc().add(-1, 'day');
  216. }
  217. if (!end.hasZone()) {
  218. end = end.clone().utc().add(1, 'day');
  219. }
  220. params = $.extend(this.ajaxSettings.data || {}, {
  221. key: apiKey,
  222. timeMin: start.format(),
  223. timeMax: end.format(),
  224. singleEvents: true,
  225. maxResults: 9999
  226. });
  227. if (timezone && timezone !== 'local') {
  228. // when sending timezone names to Google, only accepts underscores, not spaces
  229. params.timeZone = timezone.replace(' ', '_');
  230. }
  231. return params;
  232. };
  233. GcalEventSource.prototype.reportError = function (message, apiErrorObjs) {
  234. var calendar = this.calendar;
  235. var calendarOnError = calendar.opt('googleCalendarError');
  236. var errorObjs = apiErrorObjs || [{ message: message }]; // to be passed into error handlers
  237. if (this.googleCalendarError) {
  238. this.googleCalendarError.apply(calendar, errorObjs);
  239. }
  240. if (calendarOnError) {
  241. calendarOnError.apply(calendar, errorObjs);
  242. }
  243. // print error to debug console
  244. fullcalendar_1.warn.apply(null, [message].concat(apiErrorObjs || []));
  245. };
  246. GcalEventSource.prototype.getPrimitive = function () {
  247. return this.googleCalendarId;
  248. };
  249. GcalEventSource.prototype.applyManualStandardProps = function (rawProps) {
  250. var superSuccess = fullcalendar_1.EventSource.prototype.applyManualStandardProps.apply(this, arguments);
  251. var googleCalendarId = rawProps.googleCalendarId;
  252. if (googleCalendarId == null && rawProps.url) {
  253. googleCalendarId = parseGoogleCalendarId(rawProps.url);
  254. }
  255. if (googleCalendarId != null) {
  256. this.googleCalendarId = googleCalendarId;
  257. return superSuccess;
  258. }
  259. return false;
  260. };
  261. GcalEventSource.prototype.applyMiscProps = function (rawProps) {
  262. if (!this.ajaxSettings) {
  263. this.ajaxSettings = {};
  264. }
  265. $.extend(this.ajaxSettings, rawProps);
  266. };
  267. GcalEventSource.API_BASE = 'https://www.googleapis.com/calendar/v3/calendars';
  268. return GcalEventSource;
  269. }(fullcalendar_1.EventSource));
  270. exports.default = GcalEventSource;
  271. GcalEventSource.defineStandardProps({
  272. // manually process...
  273. url: false,
  274. googleCalendarId: false,
  275. // automatically transfer...
  276. googleCalendarApiKey: true,
  277. googleCalendarError: true
  278. });
  279. function parseGoogleCalendarId(url) {
  280. var match;
  281. // detect if the ID was specified as a single string.
  282. // will match calendars like "asdf1234@calendar.google.com" in addition to person email calendars.
  283. if (/^[^\/]+@([^\/\.]+\.)*(google|googlemail|gmail)\.com$/.test(url)) {
  284. return url;
  285. }
  286. else if ((match = /^https:\/\/www.googleapis.com\/calendar\/v3\/calendars\/([^\/]*)/.exec(url)) ||
  287. (match = /^https?:\/\/www.google.com\/calendar\/feeds\/([^\/]*)/.exec(url))) {
  288. return decodeURIComponent(match[1]);
  289. }
  290. }
  291. // Injects a string like "arg=value" into the querystring of a URL
  292. function injectQsComponent(url, component) {
  293. // inject it after the querystring but before the fragment
  294. return url.replace(/(\?.*?)?(#|$)/, function (whole, qs, hash) {
  295. return (qs ? qs + '&' : '?') + component + hash;
  296. });
  297. }
  298. /***/ }),
  299. /***/ 3:
  300. /***/ (function(module, exports) {
  301. module.exports = __WEBPACK_EXTERNAL_MODULE_3__;
  302. /***/ })
  303. /******/ });
  304. });