Fix flatpickr DOM nodes not removed

pull/1/head
yflory 4 years ago
parent 7f01ab3e1a
commit 5dded12f53

@ -536,6 +536,7 @@ Messages.calendar_tempCalendar = "Temp calendar";
var cal = APP.calendar = new Calendar('#cp-sidebarlayout-rightside', { var cal = APP.calendar = new Calendar('#cp-sidebarlayout-rightside', {
defaultView: 'week', // weekly view option defaultView: 'week', // weekly view option
taskView: false,
useCreationPopup: true, useCreationPopup: true,
useDetailPopup: true, useDetailPopup: true,
usageStatistics: false, usageStatistics: false,
@ -714,6 +715,15 @@ Messages.calendar_tempCalendar = "Temp calendar";
var onCalendarEditPopup = function (el) { var onCalendarEditPopup = function (el) {
// TODO // TODO
}; };
var onPopupRemoved = function () {
var start, end;
if (window.CP_startPickr) { start = window.CP_startPickr.calendarContainer; }
if (window.CP_endPickr) { end = window.CP_endPickr.calendarContainer; }
$('.flatpickr-calendar').each(function (i, el) {
if (el === start || el === end) { return; }
$(el).remove();
});
};
var observer = new MutationObserver(function(mutations) { var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) { mutations.forEach(function(mutation) {
var node; var node;
@ -721,15 +731,23 @@ Messages.calendar_tempCalendar = "Temp calendar";
var node = mutation.addedNodes[i]; var node = mutation.addedNodes[i];
try { try {
if (node.classList && node.classList.contains('tui-full-calendar-popup') if (node.classList && node.classList.contains('tui-full-calendar-popup')
&& node.parentNode.classList.contains('tui-view-26')) { && !node.classList.contains('tui-full-calendar-popup-detail')) {
onCalendarPopup(node); onCalendarPopup(node);
} }
if (node.classList && node.classList.contains('tui-full-calendar-popup') if (node.classList && node.classList.contains('tui-full-calendar-popup')
&& node.parentNode.classList.contains('tui-view-29')) { && node.classList.contains('tui-full-calendar-popup-detail')) {
onCalendarEditPopup(node); onCalendarEditPopup(node);
} }
} catch (e) {} } catch (e) {}
} }
for (var j = 0; j < mutation.removedNodes.length; j++) {
var _node = mutation.addedNodes[j];
try {
if (_node.classList && _node.classList.contains('tui-full-calendar-popup')) {
onPopupRemoved();
}
} catch (e) {}
}
}); });
}); });
observer.observe($('body')[0], { observer.observe($('body')[0], {
@ -741,7 +759,7 @@ Messages.calendar_tempCalendar = "Temp calendar";
onEvent: onEvent onEvent: onEvent
}); });
APP.module.execCommand('SUBSCRIBE', null, function (obj) { APP.module.execCommand('SUBSCRIBE', null, function (obj) {
if (obj.empty && !privateData.calendarHash) { if (obj.empty) {
// No calendar yet, create one // No calendar yet, create one
newCalendar({ newCalendar({
teamId: 1, teamId: 1,

@ -23,6 +23,8 @@ define([
} }
}); });
startPickr.setDate(start.date); startPickr.setDate(start.date);
window.CP_startPickr = startPickr;
window.CP_endPickr = endPickr;
var getStartDate = function () { var getStartDate = function () {
setTimeout(function () { $(startPickr.calendarContainer).remove(); }); setTimeout(function () { $(startPickr.calendarContainer).remove(); });

Loading…
Cancel
Save