Initial commit
This commit is contained in:
commit
29f9d7c880
25 changed files with 985 additions and 0 deletions
26
js/vanilla.dbkcalendar.js
Normal file
26
js/vanilla.dbkcalendar.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
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("<div data-date='" + date + "'><span>" + day.toLocaleDateString(true, {weekday:'short', day:'numeric', month:'long', year: 'numeric'}) + "</span></div>");
|
||||
Object.keys(data[date]).forEach(function (uid) {
|
||||
var event = data[date][uid];
|
||||
if(event.location) event.location = event.location.replace(/\n/g,"<br>").replace(uri_regex, "<a href='$1' target='_blank'>$1</a>");
|
||||
if(event.description) event.description = event.description.replace(/\n/g,"<br>").replace(uri_regex, (url) => {event.summary = `<a href='${url}' target='_blank'>${event.summary}</a>`; return "";});
|
||||
if(event.categories) event.categories = "<i>" + event.categories.replace(",", "</i> <i>") + "</i>";
|
||||
items.push("<div data-uid='" + uid + "'><span>" + event.datestr + "</span><span><b>" + event.summary + "</b> | " + ((event.location)?event.location:'') + "<br/>" + ((event.description)?event.description:'') + ((event.categories)?event.categories:'') + "</span></div>");
|
||||
});
|
||||
});
|
||||
document.querySelector('#dbkcalendar').innerHTML = items.join( "" );
|
||||
});
|
||||
}
|
||||
|
Reference in a new issue