Skip to content

Commit

Permalink
Display Hebrew month range below Gregorian month name in FullCalendar
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Jul 9, 2024
1 parent 55da23b commit e70de4d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions views/partials/script-fullcalendar.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@
<script><%- await include('hdate.bundle.min.js') %></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
function getHebMonthName(dt) {
const abs = hdate.greg2abs(dt);
const hdt = hdate.abs2hebrew(abs);
const str = hdate.getMonthName(hdt.mm, hdt.yy);
hdt.monthName = str.replace(/'/g, '');
return hdt;
}
function makeHebMonthRangeStr(startDt, endDt) {
const start = getHebMonthName(startDt);
const end = getHebMonthName(endDt);
let str = start.monthName;
if (end.yy !== start.yy) {
str += ' ' + start.yy;
}
if (end.mm !== start.mm) {
str += '' + end.monthName;
}
str += ' ' + end.yy;
return str;
}
let hebmonthEl = null;
function monthSubtitle(view) {
const end = new Date(view.currentEnd.getTime());
end.setDate(end.getDate() - 1);
const s = makeHebMonthRangeStr(view.currentStart, end);
if (hebmonthEl) {
hebmonthEl.innerText = s;
}
}
let calendar = null;
const calendarEl = document.getElementById('calendar');
calendarEl.style.display = 'none';
Expand All @@ -14,6 +43,14 @@ document.addEventListener('DOMContentLoaded', function() {
if (fc) {
makeFullCalendar();
calendar.render();
const toolbarEl = document.querySelector('.fc-header-toolbar .fc-toolbar-chunk:nth-child(2)');
if (toolbarEl && !hebmonthEl) {
hebmonthEl = document.createElement('h5');
hebmonthEl.id = 'hebmonth';
hebmonthEl.className = 'text-burgundy ms-0 mt-1';
toolbarEl.appendChild(hebmonthEl);
monthSubtitle(calendar.view);
}
}
toggleMonth.blur();
});
Expand Down Expand Up @@ -93,6 +130,9 @@ document.addEventListener('DOMContentLoaded', function() {
},
};
calendar = new FullCalendar.Calendar(calendarEl, opts);
calendar.on('datesSet', function(dateInfo) {
monthSubtitle(dateInfo.view);
});
document.addEventListener('keydown', function(e) {
if (e.key === 'ArrowLeft' && !e.metaKey) {
calendar.prev();
Expand Down

0 comments on commit e70de4d

Please sign in to comment.