/*
Include calendar | Chaostreff Backnang | @paddy
*/
document.addEventListener("DOMContentLoaded", hackcal);
function hackcal(p=1) {
var cal_uri = "/hackcal/?period="+p;
var uri_regex = /(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/\-_\.\:]*(\?\S+)?)?)?)/ig
fetch(cal_uri).then(res => res.json()).then(data => {
var items = [];
Object.keys(data).forEach(function (date) {
var day = new Date(date);
items.push("
" + day.toLocaleDateString(true, {weekday:'short', day:'numeric', month:'long', year: 'numeric'}) + "
");
Object.keys(data[date]).forEach(function (uid) {
var event = data[date][uid];
if(event.location) event.location = event.location.replace(/\n/g,"
").replace(uri_regex, "$1");
if(event.description) event.description = event.description.replace(/\n/g,"
").replace(uri_regex, (url) => {event.summary = `${event.summary}`; return "";});
if(event.categories) event.categories = "" + event.categories.replace(",", " ") + "";
items.push("" + event.datestr + "" + event.summary + " | " + ((event.location)?event.location:'') + "
" + ((event.description)?event.description:'') + ((event.categories)?event.categories:'') + "
");
});
});
document.querySelector('#dbkcalendar').innerHTML = items.join( "" );
});
}