PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 3.6.8
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v3.6.8
4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / ThirdParty / Googlecalendar / assets / js / main.js
embedpress / EmbedPress / ThirdParty / Googlecalendar / assets / js Last commit date
main.js 4 years ago
main.js
490 lines
1 (function(win) {
2 jQuery(document).ready(function () {
3
4 window.fullCalendars = [];
5
6 var int_reg = /^\d+$/;
7
8 function underscoreToUpper(s) {
9 // event_limit ==> eventLimit
10 return s.replace(/_([a-z])/g, function (g) { return g[1].toUpperCase(); });
11 }
12
13 // Because attributes are always strings, we need to cast them to appropriate types.
14 function castAttrValue(value, defaultValue) {
15 if (value === 'true') return true;
16 if (value === 'false') return false;
17 if (int_reg.test(value)) {
18 return parseInt(value, 10);
19 }
20 if (!value && typeof defaultValue !== "undefined") {
21 return defaultValue;
22 }
23 return value;
24 }
25
26 function getConfigBackgroundColor(config) {
27 if ("eventBackgroundColor" in config) {
28 return config.eventBackgroundColor;
29 }
30 if ("eventColor" in config) {
31 return config.eventColor;
32 }
33 return false;
34 }
35
36 function padDatePart(d) {
37 if (d < 10) return "0" + d.toString();
38 return d;
39 }
40
41 function dateFormat(date) {
42 return date.getFullYear() + "-" + padDatePart(date.getMonth() + 1) + "-" + padDatePart(date.getDate());
43 }
44
45 function castObjectAttributes(obj) {
46 Object.keys(obj).forEach(function(key) {
47 if (obj[key]) {
48 switch (typeof obj[key]) {
49 case 'string':
50 obj[key] = castAttrValue(obj[key]);
51 break;
52 case 'object':
53 if (obj[key].constructor === Object) {
54 castObjectAttributes(obj[key]);
55 }
56 break;
57 }
58 }
59 });
60 }
61
62
63 Array.prototype.forEach.call(document.querySelectorAll(".epgc-calendar-wrapper"), function(calendarWrapper, calendarCounter) {
64
65 var errorEl = window.document.createElement("div");
66 errorEl.className = "epgc-error-el";
67 var loadingEl = window.document.createElement("div");
68 loadingEl.className = "epgc-loading-el";
69
70 var currentAllEvents = null;
71 var fullCalendar = null;
72 var $calendar = calendarWrapper.querySelector('.epgc-calendar');
73 var $calendarFilter = calendarWrapper.querySelector('.epgc-calendar-filter');
74 var errorAndLoadingParent = null; // will be set by FullCalendar, so is not available now.
75
76 var selectedCalIds = null;
77 var allCalendars = null;
78
79 // Always present, gets set in PHP file.
80 // Note: make sure you use the same defaults as get set in the PHP file!
81 var isPublic = castAttrValue($calendar.getAttribute('data-public'), false);
82 var filter = castAttrValue($calendar.getAttribute('data-filter'));
83 var showEventPopup = castAttrValue($calendar.getAttribute('data-eventpopup'), true);
84 var showEventLink = castAttrValue($calendar.getAttribute('data-eventlink'), false);
85 var hidePassed = castAttrValue($calendar.getAttribute('data-hidepassed'), false);
86 var hideFuture = castAttrValue($calendar.getAttribute('data-hidefuture'), false);
87 var showEventDescription = castAttrValue($calendar.getAttribute('data-eventdescription'), false);
88 var showEventLocation = castAttrValue($calendar.getAttribute('data-eventlocation'), false);
89 var showEventAttendees = castAttrValue($calendar.getAttribute('data-eventattendees'), false);
90 var showEventAttachments = castAttrValue($calendar.getAttribute('data-eventattachments'), false);
91 var showEventCreator = castAttrValue($calendar.getAttribute('data-eventcreator'), false);
92 var showEventCalendarname = castAttrValue($calendar.getAttribute('data-eventcalendarname'), false);
93
94 var uncheckedCalendarIds = $calendarFilter && $calendarFilter.getAttribute("data-uncheckedcalendarids") ? JSON.parse($calendarFilter.getAttribute("data-uncheckedcalendarids")) : [];
95
96 // fullCalendar locales are like this: nl-be OR es
97 // The locale we get from WP are en_US OR en.
98 var locale = 'en-us';
99 // This one (data-locale) is set by WP and NOT by the user. User can set it in the fullCalendar config.
100 if ($calendar.getAttribute('data-locale')) {
101 locale = $calendar.getAttribute('data-locale').toLowerCase().replace("_", "-"); // en-us or en
102 }
103
104 // This can be overridden by shortcode attributes.
105 var defaultConfig = {
106 height: "auto",
107 locale: locale,
108 eventLimit: true
109 };
110 var dataConfig = $calendar.getAttribute("data-config") ? JSON.parse($calendar.getAttribute("data-config")) : {};
111
112 // Cast booleans and int (we also get these as strings)
113 castObjectAttributes(dataConfig);
114
115 var config = Object.assign({}, defaultConfig);
116 Object.keys(dataConfig).forEach(function(key) {
117 var value = castAttrValue(dataConfig[key]);
118 config[underscoreToUpper(key)] = value;
119 });
120
121 // New option for firstDay: +0, +1, +2, etc. instead of 0, 1, 2, etc. ==> FullCalendar expects day number (Sunday = 0), so translate it
122 if (("firstDay" in config) && !int_reg.test(config.firstDay)) {
123 config.firstDay = parseInt(moment().add(config.firstDay, 'd').format('d'), 10);
124 }
125
126 locale = config.locale;
127
128 moment.locale(locale);
129
130 // Users can set specific set of calendars
131 // Only in widget set (data-calendarids)
132 var thisCalendarids = $calendar.getAttribute('data-calendarids') ? JSON.parse($calendar.getAttribute('data-calendarids')) : [];
133 // Only in shortcode
134 // TODO: with new release this can be deleted I think.
135 if ("calendarids" in config) {
136 thisCalendarids = config.calendarids.split(",").map(function(item) {
137 return item.replace(" ", "");
138 });
139 }
140
141 if (isPublic && thisCalendarids.length === 0) {
142 console.error("If you set the 'public' property, you have to specify at least 1 calendar ID in the 'calendarids' property.");
143 }
144
145 function makeSureErrorAndLoadingParentExists() {
146 if (!errorAndLoadingParent) {
147 errorAndLoadingParent = $calendar.querySelector(".fc-view-container");
148 }
149 return !!errorAndLoadingParent;
150 }
151
152 function clearError() {
153 if (errorEl.parentNode) {
154 errorEl.parentNode.removeChild(errorEl);
155 }
156 }
157
158 function clearLoading() {
159 if (loadingEl.parentNode) {
160 loadingEl.parentNode.removeChild(loadingEl);
161 }
162 }
163
164 function setError(msg) {
165 clearLoading();
166 if (makeSureErrorAndLoadingParentExists()) {
167 errorEl.innerText = msg;
168 errorAndLoadingParent.appendChild(errorEl);
169 }
170 }
171
172 function setLoading(msg) {
173 clearError();
174 if (makeSureErrorAndLoadingParentExists()) {
175 loadingEl.innerText = msg;
176 errorAndLoadingParent.appendChild(loadingEl);
177 }
178 }
179
180 function handleCalendarFilter(calendars) {
181
182 allCalendars = calendars;
183
184 // Make sure below happens once.
185 if (selectedCalIds !== null) {
186 return;
187 }
188
189 selectedCalIds = Object.keys(calendars); // default all calendars selected
190 if (uncheckedCalendarIds.length) {
191 var tmp = [];
192 selectedCalIds.forEach(function(key) {
193 if (uncheckedCalendarIds.indexOf(key) === -1) {
194 tmp.push(key);
195 }
196 });
197 selectedCalIds = tmp;
198 }
199
200 if (!filter) return;
201
202 var selectBoxes = [];
203 Object.keys(calendars).forEach(function(key, index) {
204 if (thisCalendarids.length && thisCalendarids.indexOf(key) === -1) {
205 return;
206 }
207 selectBoxes.push('<input id="id_' + calendarCounter + '_' + index + '" type="checkbox" ' + (uncheckedCalendarIds.indexOf(key) === -1 ? "checked" : "") + ' value="' + key + '" />'
208 + '<label for="id_' + calendarCounter + '_' + index + '">'
209 + '<span class="epgc-calendar-color" style="background-color:' + (getConfigBackgroundColor(config) || calendars[key].backgroundColor) + '"></span> ' + (calendars[key].summary || key)
210 + '</label>');
211 });
212 $calendarFilter.innerHTML = '<div class="epgc-calendar-filter-wrapper">' + selectBoxes.join("\n") + '</div>';
213 }
214
215 function getFilteredEvents() {
216 var newEvents = [];
217 currentAllEvents.forEach(function(item) {
218 if (selectedCalIds.indexOf(item.calId) > -1) {
219 newEvents.push(item);
220 }
221 });
222 return newEvents;
223 }
224
225 function setEvents() {
226 var newEvents = getFilteredEvents();
227 var calendarEvents = fullCalendar.getEvents();
228 fullCalendar.batchRendering(function() {
229 calendarEvents.forEach(function(e) {
230 e.remove();
231 });
232 });
233 fullCalendar.batchRendering(function() {
234 newEvents.forEach(function(e) {
235 fullCalendar.addEvent(e);
236 });
237 });
238 }
239
240 if ($calendarFilter) {
241 $calendarFilter.addEventListener("change", function(e) {
242 selectedCalIds = Array.prototype.map.call(calendarWrapper.querySelectorAll(".epgc-calendar-filter-wrapper input[type='checkbox']:checked"), function(item) {
243 return item.value;
244 });
245 setEvents();
246 });
247 }
248
249 var loadingTimer = null;
250
251 // Add things no one can override.
252 config = Object.assign(config, {
253 loading: function(isLoading, view) {
254 if (isLoading) {
255 loadingTimer = setTimeout(function() {
256 setLoading(epgc_object.trans.loading);
257 }, 300);
258 } else {
259 if (loadingTimer) {
260 clearTimeout(loadingTimer);
261 loadingTimer = null;
262 }
263 clearLoading();
264 }
265 },
266 eventRender: function(info) {
267
268 if (showEventPopup) {
269 var texts = ['<span class="epgc-popup-draghandle dashicons dashicons-screenoptions"></span><div class="epgc-popup-row epgc-event-title"><div class="epgc-popup-row-icon"><span></span></div><div class="epgc-popup-row-value">' + info.event.title + '</div></div>'];
270
271 var date = config.timeZone ? moment.tz(info.event.start, config.timeZone).format("L") : info.event.start.toLocaleDateString();
272
273 texts.push('<div class="epgc-popup-row epgc-event-time"><div class="epgc-popup-row-icon"><span class="dashicons dashicons-clock"></span></div><div class="epgc-popup-row-value">' + date + '<br>');
274 if (info.event.allDay) {
275 texts.push(epgc_object.trans.all_day + "</div></div>");
276 } else {
277 if (config.timeZone) {
278 // info.event.end can be null, for example when someone uses the same start and end time!
279 texts.push(moment.tz(info.event.start, config.timeZone).format("LT")
280 + " - "
281 + moment.tz((info.event.end || info.event.start), config.timeZone).format("LT") + "</div></div>");
282 } else {
283 // info.event.end can be null, for example when someone uses the same start and end time!
284 texts.push(info.event.start.toLocaleTimeString(locale, {
285 timeStyle: "short"
286 }) + " - " + (info.event.end || info.event.start).toLocaleTimeString(locale, {
287 timeStyle: "short"
288 }) + "</div></div>");
289 }
290 }
291 if (showEventDescription && info.event.extendedProps.description) {
292 texts.push('<div class="epgc-popup-row epgc-event-description"><div class="epgc-popup-row-icon"><span class="dashicons dashicons-editor-alignleft"></span></div><div class="epgc-popup-row-value">' + info.event.extendedProps.description + '</div></div>');
293 }
294 if (showEventLocation && info.event.extendedProps.location) {
295 texts.push('<div class="epgc-popup-row epgc-event-location"><div class="epgc-popup-row-icon"><span class="dashicons dashicons-location"></span></div><div class="epgc-popup-row-value">' + info.event.extendedProps.location + '</div></div>');
296 }
297 if (showEventAttendees && info.event.extendedProps.attendees && info.event.extendedProps.attendees.length) {
298 texts.push('<div class="epgc-popup-row epgc-event-attendees"><div class="epgc-popup-row-icon"><span class="dashicons dashicons-groups"></span></div><div class="epgc-popup-row-value"><ul>' + info.event.extendedProps.attendees.map(function(attendee) {
299 return '<li>' + attendee.email + '</li>';
300 }).join('') + '</ul></div></div>');
301 }
302 if (showEventAttachments && info.event.extendedProps.attachments && info.event.extendedProps.attachments.length) {
303 texts.push('<div class="epgc-popup-row epgc-event-attachments"><div class="epgc-popup-row-icon"><span class="dashicons dashicons-paperclip"></span></div><div class="epgc-popup-row-value"><ul>' + info.event.extendedProps.attachments.map(function(attachment) {
304 return '<li><a rel="noopener noreferrer" target="_blank" href="' + attachment.fileUrl + '">' + attachment.title + '</a></li>';
305 }).join('<br>') + '</ul></div></div>');
306 }
307 var hasCreator = showEventCreator && info.event.extendedProps.creator && (info.event.extendedProps.creator.email || info.event.extendedProps.creator.displayName);
308 if (showEventCalendarname || hasCreator) {
309 texts.push('<div class="epgc-popup-row epgc-event-calendarname-creator"><div class="epgc-popup-row-icon"><span class="dashicons dashicons-calendar-alt"></span></div><div class="epgc-popup-row-value">');
310 if (showEventCalendarname) {
311 texts.push(allCalendars[info.event.extendedProps.calId].summary || info.event.extendedProps.calId);
312 if (hasCreator) {
313 texts.push('<br>');
314 }
315 }
316 if (hasCreator) {
317 texts.push(epgc_object.trans.created_by + ': ' + (info.event.extendedProps.creator.displayName || info.event.extendedProps.creator.email));
318 }
319 texts.push('</div></div>');
320 }
321 if (showEventLink) {
322 texts.push('<div class="epgc-popup-row epgc-event-link"><div class="epgc-popup-row-icon"><span class="dashicons dashicons-external"></span></div><div class="epgc-popup-row-value"><a rel="noopener noreferrer" target="_blank" href="' + info.event.extendedProps.htmlLink + '">' + epgc_object.trans.go_to_event + '</a></div></div>');
323 }
324 info.el.setAttribute("data-tippy-content", texts.join("\n"));
325 info.el.setAttribute("data-calendarid", info.event.extendedProps.calId);
326 }
327 },
328 events: function(arg, successCcallback, failureCallback) {
329 var start = arg.start;
330 var end = arg.end;
331 //var fStart = dateFormat(start);
332 var fStart = arg.startStr;
333 //var fEnd = dateFormat(end);
334 var fEnd = arg.endStr;
335
336 var xhr = new XMLHttpRequest();
337 var formData = new FormData();
338 formData.append("_ajax_nonce", epgc_object.nonce);
339 formData.append("action", "epgc_ajax_get_calendar");
340 formData.append("start", fStart);
341 formData.append("end", fEnd);
342 if ("timeZone" in arg && arg.timeZone) {
343 formData.append("timeZone", arg.timeZone);
344 }
345 formData.append("thisCalendarids", thisCalendarids.join(","));
346 if (isPublic) {
347 formData.append("isPublic", 1);
348 }
349 xhr.onload = function(eLoad) {
350 try {
351 var response = JSON.parse(this.response);
352 if ("error" in response) {
353 throw response;
354 }
355 var items = [];
356 if ("items" in response) {
357 // Merge calendar backgroundcolor and items
358 var calendars = response.calendars;
359 response.items.forEach(function(item) {
360 // Check if we have this calendar - if we get cached items, but someone unselected
361 // a calendar in the admin, we can get items for unselected calendars.
362 if (!(item.calId in calendars)) return;
363 if (item.bColor) {
364 item.backgroundColor = item.bColor;
365 item.textColor = item.fColor;
366 } else if (!getConfigBackgroundColor(config)) {
367 item.backgroundColor = calendars[item.calId].backgroundColor;
368 }
369 items.push(item);
370 });
371 currentAllEvents = items;
372 handleCalendarFilter(response.calendars);
373 }
374 successCcallback([]);
375 setEvents();
376 } catch (ex) {
377 setError(ex.errorDescription || ex.error || epgc_object.trans.unknown_error);
378 console.error(ex);
379 successCcallback([]);
380 } finally {
381 xhr = null;
382 }
383 };
384 xhr.onerror = function(eError) {
385 setError(eError.error || epgc_object.trans.request_error);
386 console.error(eError);
387 successCcallback([]);
388 };
389 xhr.open("POST", epgc_object.ajax_url);
390 xhr.send(formData);
391 }
392 });
393
394 // Can be true, false, or numeric, even 0 meaning the same as true.
395 if (hidePassed || hideFuture || hidePassed === 0 || hideFuture === 0) {
396 config.validRange = {};
397 }
398
399 if (hidePassed === true || hidePassed === 0) {
400 config.validRange.start = new Date();
401 } else if (hidePassed) {
402 config.validRange.start = moment().subtract(hidePassed, 'days').toDate();
403 }
404 if (hideFuture === true || hideFuture === 0) {
405 config.validRange.end = new Date();
406 } else if (hideFuture) {
407 config.validRange.end = moment().add(hideFuture, 'days').toDate();
408 }
409
410 fullCalendar = new FullCalendar.Calendar($calendar, Object.assign({
411 plugins: ['moment', 'momentTimezone', 'dayGrid', 'list', 'timeGrid'],
412 defaultView: 'dayGridMonth',
413 nowIndicator: true,
414 columnHeader: true,
415 columnHeaderFormat: {
416 weekday: 'short'
417 }
418 }, config));
419 fullCalendar.render();
420 // For debugging, so we have access to it from within the console.
421 window.fullCalendars.push(fullCalendar);
422 });
423
424 var tippyArg = {
425 target: "*[data-tippy-content]",
426 allowHTML: true,
427 theme: "epgc",
428 interactive: true,
429 appendTo: document.body,
430 theme: 'light-border',
431 onMount: function(instance) {
432 Array.prototype.forEach.call(instance.popper.querySelectorAll("a"), function(a) {
433 if (!a.getAttribute("target")) {
434 a.setAttribute("target", "_blank");
435 a.setAttribute("rel", "noopener noreferrer");
436 }
437 });
438 }
439 };
440
441 if (!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
442 tippyArg.trigger = "click";
443 }
444
445 tippy.delegate("body", tippyArg);
446
447 var startClientX = 0;
448 var startClientY = 0;
449 var popupElement = null;
450 var popupElementStartX = 0;
451 var popupElementStartY = 0;
452
453 function onBodyMouseDown(e) {
454
455 var el = e.target || e.srcElement;
456
457 if (!el.classList.contains('epgc-popup-draghandle')) return;
458
459 while (el) {
460 if (el.getAttribute && el.hasAttribute("data-tippy-root")) {
461 popupElement = el;
462 break;
463 }
464 el = el.parentNode;
465 }
466
467 if (!popupElement) return;
468 var transform = popupElement.style.transform.replace("translate(", "").replace(")", "").split(",");
469 popupElementStartX = parseInt(transform[0].replace(" ", ""), 10);
470 popupElementStartY = parseInt(transform[1].replace(" ", ""), 10);
471 startClientX = e.clientX;
472 startClientY = e.clientY;
473 document.body.addEventListener("mousemove", onBodyMouseMove);
474 document.body.addEventListener("mouseup", onBodyMouseUp);
475 }
476
477 function onBodyMouseMove(e) {
478 popupElement.style.transform = "translate(" + (popupElementStartX + (e.clientX - startClientX)) + "px, " + (popupElementStartY + (e.clientY - startClientY)) + "px)";
479 }
480
481 function onBodyMouseUp() {
482 document.body.removeEventListener("mousemove", onBodyMouseMove);
483 document.body.removeEventListener("mouseup", onBodyMouseUp);
484 }
485
486 document.body.addEventListener("mousedown", onBodyMouseDown);
487 });
488
489 }(this));
490