Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mjradwin
Last active September 26, 2023 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjradwin/aa0ed1ee6d42d4ea09856f029bbbb0f9 to your computer and use it in GitHub Desktop.
Save mjradwin/aa0ed1ee6d42d4ea09856f029bbbb0f9 to your computer and use it in GitHub Desktop.
Hebcal + FullCalendar with a function to modify JSON event feed
<!DOCTYPE html>
<html lang="en">
<head>
<title>Jewish Calendar</title>
<style>
html, body {
font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;
font-size: 14px;
}
</style>
</head>
<body>
<div id="calendar"></div>
<script src="https://cdn.jsdelivr.net/npm/fullcalendar@6.1.9/index.global.min.js" integrity="sha384-wv6yRjQC0TqzEnAjFQVXM2V0JrF6Nk0dh6QAGf1RwzTqPArdwU3luBZjVCi2YSVH" crossorigin="anonymous"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
headerToolbar: {
left: 'title',
right: 'prev,next today',
},
timeZone: 'local',
eventDisplay: 'block',
events: function(info, successCallback, failureCallback) {
var url = new URL('https://www.hebcal.com/hebcal');
var sp = url.searchParams;
sp.set('v', '1'); // Required, version 1
sp.set('cfg', 'fc'); // Required, mode = FullCalendar
sp.set('start', info.startStr.substring(0, 10));
sp.set('end', info.endStr.substring(0, 10));
sp.set('i', 'off'); // Israel or Diaspora holiday schedule
sp.set('maj', 'on'); // Major holidays
sp.set('min', 'on'); // Minor holidays
sp.set('nx', 'on'); // Rosh Chodesh
sp.set('mf', 'on'); // Minor fasts
sp.set('ss', 'on'); // Special Shabbatot
sp.set('mod', 'on'); // Modern holidays
sp.set('s', 'on'); // Weekly Torah portion on Saturdays
sp.set('o', 'off'); // Days of the Omer
sp.set('D', 'off'); // Show Hebrew date for dates with some event
sp.set('lg', 's'); // Sephardic transliterations
// sp.set('geonameid', 3448439); // Candle-lighting, Havdalah, and Fast times
var fetchOptions = {
method: 'GET',
credentials: 'omit',
mode: 'cors',
};
fetch(url.href, fetchOptions).then(function(fetchRes) {
if (fetchRes.ok) {
fetchRes.json().then(function(parsedResponse) {
var events = parsedResponse.map(function(ev) {
// Modify ev as desired
if (ev.emoji) {
ev.title += '\u00a0' + ev.emoji;
}
return ev;
});
successCallback(events);
}, function(err) {
failureCallback(err);
});
} else {
failureCallback('Request failed');
}
}).catch(function(err) {
failureCallback(err);
});
}
});
calendar.render();
// optional: bind keyboard left/right arrow keys to move calendar forward/backward by a month
document.addEventListener('keydown', function(e) {
if (e.key === 'ArrowLeft' && !e.metaKey) {
calendar.prev();
} else if (e.key === 'ArrowRight' && !e.metaKey) {
calendar.next();
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment