-
-
Save daftspunk/2be1a45f04013bd5f765043267b29f9f to your computer and use it in GitHub Desktop.
Full calendar Hot Control
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
oc.registerControl('full-calendar', class extends oc.ControlBase { | |
connect() { | |
this.calendar = new FullCalendar.Calendar(this.element, { | |
headerToolbar: { | |
left: 'prev,next today', | |
center: 'title', | |
right: null, | |
}, | |
initialView: window.innerWidth < 1000 ? 'listWeek' : 'dayGridMonth', | |
locale: '<?= $locale ?>', | |
contentHeight: 'calc(100vh - 200px)', | |
weekNumbers: true, | |
loading: function (isLoading) { | |
if (isLoading) { | |
document.getElementById('r-calendar').style.display = 'none'; | |
oc.progressBar.show() | |
} else { | |
oc.progressBar.hide() | |
document.getElementById('r-calendar').style.display = 'block'; | |
} | |
}, | |
events: function (eventInfo, successCallback) { | |
oc.request(this.element, 'onLoadHolidays', { | |
data: { | |
start: eventInfo.start.toDateString(), | |
end: eventInfo.end.toDateString() | |
}, | |
success: function (events) { | |
successCallback(events); | |
} | |
}); | |
}, | |
windowResize: function (arg) { | |
if (window.innerWidth < 1000) { | |
this.changeView('listWeek'); | |
} else { | |
this.changeView('dayGridMonth'); | |
} | |
} | |
}); | |
this.calendar.render(); | |
} | |
disconnect() { | |
this.calendar.destroy(); | |
this.calendar = null; | |
} | |
}); | |
addEventListener('render', function () { | |
document.querySelectorAll('#r-calendar:not([data-control~="full-calendar"]').forEach((element) => { | |
if (element.dataset.control) { | |
element.dataset.control = element.dataset.control + ' full-calendar'; | |
} | |
else { | |
element.dataset.control = 'full-calendar'; | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment