function create(type){
return document.createElement(type);
}
function getTags(){
const params = query();
return params.get('tags');
}
async function handleData(response){
if (response.ok){
var json = await response.json();
var tags = getTags();
if (!tags) showcase(json);
var list = tag('eventlist');
for (var event of json){
var div = create('div');
div.innerHTML = event.description;
div.setAttribute('class','event');
if (event.attachments){
for (var attachment of event.attachments){
if (attachment.mime.startsWith('image')){
var img = create('img');
img.src = attachment.url;
div.prepend(img);
break;
}
}
}
if (event.start){
var span = create('span');
span.setAttribute('class','start');
var loc = event.location;
var pos = loc.indexOf(',');
if (pos>0) loc = loc.substring(0,pos);
span.innerHTML = event.start + ' @ '+ loc + '
';
div.prepend(span);
}
var h4 = create('h4');
h4.innerHTML = event.url ? `${event.title}` : event.title;
div.prepend(h4);
eventlist.appendChild(div);
}
}
}
function hide(id){
console.log({hide:id});
var elem = tag(id);
if (elem) elem.style.display = 'none';
}
function load(){
var hash = window.location.hash;
if (hash) {
if (hash.startsWith('#')) hash = hash.substring(1);
hide('showcase');
hide('eventlist');
show(hash);
}
var tags = getTags();
if (!tags) {
tags = 'schwarzesjena';
} else {
hide('showcase');
tag('eventlist').innerHTML = `