diff options
Diffstat (limited to 'public/js/fullcalendar/packages/google-calendar')
| -rw-r--r-- | public/js/fullcalendar/packages/google-calendar/index.global.js | 150 | ||||
| -rw-r--r-- | public/js/fullcalendar/packages/google-calendar/index.global.min.js | 6 |
2 files changed, 156 insertions, 0 deletions
diff --git a/public/js/fullcalendar/packages/google-calendar/index.global.js b/public/js/fullcalendar/packages/google-calendar/index.global.js new file mode 100644 index 0000000..7c933c3 --- /dev/null +++ b/public/js/fullcalendar/packages/google-calendar/index.global.js | |||
| @@ -0,0 +1,150 @@ | |||
| 1 | /*! | ||
| 2 | FullCalendar Google Calendar Plugin v6.1.17 | ||
| 3 | Docs & License: https://fullcalendar.io/docs/google-calendar | ||
| 4 | (c) 2024 Adam Shaw | ||
| 5 | */ | ||
| 6 | FullCalendar.GoogleCalendar = (function (exports, core, internal) { | ||
| 7 | 'use strict'; | ||
| 8 | |||
| 9 | // TODO: expose somehow | ||
| 10 | const API_BASE = 'https://www.googleapis.com/calendar/v3/calendars'; | ||
| 11 | const eventSourceDef = { | ||
| 12 | parseMeta(refined) { | ||
| 13 | let { googleCalendarId } = refined; | ||
| 14 | if (!googleCalendarId && refined.url) { | ||
| 15 | googleCalendarId = parseGoogleCalendarId(refined.url); | ||
| 16 | } | ||
| 17 | if (googleCalendarId) { | ||
| 18 | return { | ||
| 19 | googleCalendarId, | ||
| 20 | googleCalendarApiKey: refined.googleCalendarApiKey, | ||
| 21 | googleCalendarApiBase: refined.googleCalendarApiBase, | ||
| 22 | extraParams: refined.extraParams, | ||
| 23 | }; | ||
| 24 | } | ||
| 25 | return null; | ||
| 26 | }, | ||
| 27 | fetch(arg, successCallback, errorCallback) { | ||
| 28 | let { dateEnv, options } = arg.context; | ||
| 29 | let meta = arg.eventSource.meta; | ||
| 30 | let apiKey = meta.googleCalendarApiKey || options.googleCalendarApiKey; | ||
| 31 | if (!apiKey) { | ||
| 32 | errorCallback(new Error('Specify a googleCalendarApiKey. See https://fullcalendar.io/docs/google-calendar')); | ||
| 33 | } | ||
| 34 | else { | ||
| 35 | let url = buildUrl(meta); | ||
| 36 | // TODO: make DRY with json-feed-event-source | ||
| 37 | let { extraParams } = meta; | ||
| 38 | let extraParamsObj = typeof extraParams === 'function' ? extraParams() : extraParams; | ||
| 39 | let requestParams = buildRequestParams(arg.range, apiKey, extraParamsObj, dateEnv); | ||
| 40 | return internal.requestJson('GET', url, requestParams).then(([body, response]) => { | ||
| 41 | if (body.error) { | ||
| 42 | errorCallback(new core.JsonRequestError('Google Calendar API: ' + body.error.message, response)); | ||
| 43 | } | ||
| 44 | else { | ||
| 45 | successCallback({ | ||
| 46 | rawEvents: gcalItemsToRawEventDefs(body.items, requestParams.timeZone), | ||
| 47 | response, | ||
| 48 | }); | ||
| 49 | } | ||
| 50 | }, errorCallback); | ||
| 51 | } | ||
| 52 | }, | ||
| 53 | }; | ||
| 54 | function parseGoogleCalendarId(url) { | ||
| 55 | let match; | ||
| 56 | // detect if the ID was specified as a single string. | ||
| 57 | // will match calendars like "asdf1234@calendar.google.com" in addition to person email calendars. | ||
| 58 | if (/^[^/]+@([^/.]+\.)*(google|googlemail|gmail)\.com$/.test(url)) { | ||
| 59 | return url; | ||
| 60 | } | ||
| 61 | if ((match = /^https:\/\/www.googleapis.com\/calendar\/v3\/calendars\/([^/]*)/.exec(url)) || | ||
| 62 | (match = /^https?:\/\/www.google.com\/calendar\/feeds\/([^/]*)/.exec(url))) { | ||
| 63 | return decodeURIComponent(match[1]); | ||
| 64 | } | ||
| 65 | return null; | ||
| 66 | } | ||
| 67 | function buildUrl(meta) { | ||
| 68 | let apiBase = meta.googleCalendarApiBase; | ||
| 69 | if (!apiBase) { | ||
| 70 | apiBase = API_BASE; | ||
| 71 | } | ||
| 72 | return apiBase + '/' + encodeURIComponent(meta.googleCalendarId) + '/events'; | ||
| 73 | } | ||
| 74 | function buildRequestParams(range, apiKey, extraParams, dateEnv) { | ||
| 75 | let params; | ||
| 76 | let startStr; | ||
| 77 | let endStr; | ||
| 78 | if (dateEnv.canComputeOffset) { | ||
| 79 | // strings will naturally have offsets, which GCal needs | ||
| 80 | startStr = dateEnv.formatIso(range.start); | ||
| 81 | endStr = dateEnv.formatIso(range.end); | ||
| 82 | } | ||
| 83 | else { | ||
| 84 | // when timezone isn't known, we don't know what the UTC offset should be, so ask for +/- 1 day | ||
| 85 | // from the UTC day-start to guarantee we're getting all the events | ||
| 86 | // (start/end will be UTC-coerced dates, so toISOString is okay) | ||
| 87 | startStr = internal.addDays(range.start, -1).toISOString(); | ||
| 88 | endStr = internal.addDays(range.end, 1).toISOString(); | ||
| 89 | } | ||
| 90 | params = Object.assign(Object.assign({}, (extraParams || {})), { key: apiKey, timeMin: startStr, timeMax: endStr, singleEvents: true, maxResults: 9999 }); | ||
| 91 | if (dateEnv.timeZone !== 'local') { | ||
| 92 | params.timeZone = dateEnv.timeZone; | ||
| 93 | } | ||
| 94 | return params; | ||
| 95 | } | ||
| 96 | function gcalItemsToRawEventDefs(items, gcalTimezone) { | ||
| 97 | return items.map((item) => gcalItemToRawEventDef(item, gcalTimezone)); | ||
| 98 | } | ||
| 99 | function gcalItemToRawEventDef(item, gcalTimezone) { | ||
| 100 | let url = item.htmlLink || null; | ||
| 101 | // make the URLs for each event show times in the correct timezone | ||
| 102 | if (url && gcalTimezone) { | ||
| 103 | url = injectQsComponent(url, 'ctz=' + gcalTimezone); | ||
| 104 | } | ||
| 105 | return { | ||
| 106 | id: item.id, | ||
| 107 | title: item.summary, | ||
| 108 | start: item.start.dateTime || item.start.date, | ||
| 109 | end: item.end.dateTime || item.end.date, | ||
| 110 | url, | ||
| 111 | location: item.location, | ||
| 112 | description: item.description, | ||
| 113 | attachments: item.attachments || [], | ||
| 114 | extendedProps: (item.extendedProperties || {}).shared || {}, | ||
| 115 | }; | ||
| 116 | } | ||
| 117 | // Injects a string like "arg=value" into the querystring of a URL | ||
| 118 | // TODO: move to a general util file? | ||
| 119 | function injectQsComponent(url, component) { | ||
| 120 | // inject it after the querystring but before the fragment | ||
| 121 | return url.replace(/(\?.*?)?(#|$)/, (whole, qs, hash) => (qs ? qs + '&' : '?') + component + hash); | ||
| 122 | } | ||
| 123 | |||
| 124 | const OPTION_REFINERS = { | ||
| 125 | googleCalendarApiKey: String, | ||
| 126 | }; | ||
| 127 | |||
| 128 | const EVENT_SOURCE_REFINERS = { | ||
| 129 | googleCalendarApiKey: String, | ||
| 130 | googleCalendarId: String, | ||
| 131 | googleCalendarApiBase: String, | ||
| 132 | extraParams: internal.identity, | ||
| 133 | }; | ||
| 134 | |||
| 135 | var plugin = core.createPlugin({ | ||
| 136 | name: '@fullcalendar/google-calendar', | ||
| 137 | eventSourceDefs: [eventSourceDef], | ||
| 138 | optionRefiners: OPTION_REFINERS, | ||
| 139 | eventSourceRefiners: EVENT_SOURCE_REFINERS, | ||
| 140 | }); | ||
| 141 | |||
| 142 | core.globalPlugins.push(plugin); | ||
| 143 | |||
| 144 | exports["default"] = plugin; | ||
| 145 | |||
| 146 | Object.defineProperty(exports, '__esModule', { value: true }); | ||
| 147 | |||
| 148 | return exports; | ||
| 149 | |||
| 150 | })({}, FullCalendar, FullCalendar.Internal); | ||
diff --git a/public/js/fullcalendar/packages/google-calendar/index.global.min.js b/public/js/fullcalendar/packages/google-calendar/index.global.min.js new file mode 100644 index 0000000..e3f365b --- /dev/null +++ b/public/js/fullcalendar/packages/google-calendar/index.global.min.js | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | /*! | ||
| 2 | FullCalendar Google Calendar Plugin v6.1.17 | ||
| 3 | Docs & License: https://fullcalendar.io/docs/google-calendar | ||
| 4 | (c) 2024 Adam Shaw | ||
| 5 | */ | ||
| 6 | FullCalendar.GoogleCalendar=function(e,a,t){"use strict";const n={parseMeta(e){let{googleCalendarId:a}=e;return!a&&e.url&&(a=function(e){let a;if(/^[^/]+@([^/.]+\.)*(google|googlemail|gmail)\.com$/.test(e))return e;if((a=/^https:\/\/www.googleapis.com\/calendar\/v3\/calendars\/([^/]*)/.exec(e))||(a=/^https?:\/\/www.google.com\/calendar\/feeds\/([^/]*)/.exec(e)))return decodeURIComponent(a[1]);return null}(e.url)),a?{googleCalendarId:a,googleCalendarApiKey:e.googleCalendarApiKey,googleCalendarApiBase:e.googleCalendarApiBase,extraParams:e.extraParams}:null},fetch(e,n,r){let{dateEnv:o,options:l}=e.context,s=e.eventSource.meta,i=s.googleCalendarApiKey||l.googleCalendarApiKey;if(i){let l=function(e){let a=e.googleCalendarApiBase;a||(a="https://www.googleapis.com/calendar/v3/calendars");return a+"/"+encodeURIComponent(e.googleCalendarId)+"/events"}(s),{extraParams:d}=s,g="function"==typeof d?d():d,c=function(e,a,n,r){let o,l,s;r.canComputeOffset?(l=r.formatIso(e.start),s=r.formatIso(e.end)):(l=t.addDays(e.start,-1).toISOString(),s=t.addDays(e.end,1).toISOString());o=Object.assign(Object.assign({},n||{}),{key:a,timeMin:l,timeMax:s,singleEvents:!0,maxResults:9999}),"local"!==r.timeZone&&(o.timeZone=r.timeZone);return o}(e.range,i,g,o);return t.requestJson("GET",l,c).then(([e,t])=>{var o,l;e.error?r(new a.JsonRequestError("Google Calendar API: "+e.error.message,t)):n({rawEvents:(o=e.items,l=c.timeZone,o.map(e=>function(e,a){let t=e.htmlLink||null;t&&a&&(t=function(e,a){return e.replace(/(\?.*?)?(#|$)/,(e,t,n)=>(t?t+"&":"?")+a+n)}(t,"ctz="+a));return{id:e.id,title:e.summary,start:e.start.dateTime||e.start.date,end:e.end.dateTime||e.end.date,url:t,location:e.location,description:e.description,attachments:e.attachments||[],extendedProps:(e.extendedProperties||{}).shared||{}}}(e,l))),response:t})},r)}r(new Error("Specify a googleCalendarApiKey. See https://fullcalendar.io/docs/google-calendar"))}};const r={googleCalendarApiKey:String},o={googleCalendarApiKey:String,googleCalendarId:String,googleCalendarApiBase:String,extraParams:t.identity};var l=a.createPlugin({name:"@fullcalendar/google-calendar",eventSourceDefs:[n],optionRefiners:r,eventSourceRefiners:o});return a.globalPlugins.push(l),e.default=l,Object.defineProperty(e,"__esModule",{value:!0}),e}({},FullCalendar,FullCalendar.Internal); \ No newline at end of file | ||
