Fix missing functions — add escapeHtml, loadDates, renderDates to complete JS
This commit is contained in:
+102
@@ -855,3 +855,105 @@ function getTopicColor(topic) {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// ========================================
|
||||
// COOKIES
|
||||
// ========================================
|
||||
function getCookie(name) {
|
||||
const localVal = localStorage.getItem('paraguay_' + name);
|
||||
if (localVal) return localVal;
|
||||
|
||||
const value = '; ' + document.cookie;
|
||||
const parts = value.split('; ' + name + '=');
|
||||
if (parts.length === 2) {
|
||||
return parts.pop().split(';').shift().replace(/^"|"$/g, '');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
// ========================================
|
||||
// ESCAPE HTML — utility function
|
||||
// ========================================
|
||||
function escapeHtml(text) {
|
||||
if (!text) return '';
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// DATES / EVENTS
|
||||
// ========================================
|
||||
async function loadDates() {
|
||||
try {
|
||||
const response = await fetch(SCHEDULE_URL);
|
||||
if (!response.ok) throw new Error('Failed to fetch');
|
||||
const result = await response.json();
|
||||
|
||||
if (result.data && Array.isArray(result.data) && result.data.length > 0) {
|
||||
renderDates(result.data);
|
||||
} else {
|
||||
document.getElementById('dates-list').innerHTML =
|
||||
'<p class="no-events">' + (isDE() ? 'Keine Termine geplant' : 'No events scheduled') + '</p>';
|
||||
}
|
||||
} catch (error) {
|
||||
document.getElementById('dates-list').innerHTML =
|
||||
'<p class="no-events">' + (isDE() ? 'Fehler beim Laden' : 'Error loading events') + '</p>';
|
||||
}
|
||||
}
|
||||
|
||||
function renderDates(events) {
|
||||
const container = document.getElementById('dates-list');
|
||||
container.innerHTML = '';
|
||||
|
||||
// Sort events by date
|
||||
const sorted = events.sort((a, b) => new Date(a.start) - new Date(b.start));
|
||||
|
||||
sorted.forEach((event, idx) => {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'date-card stagger-' + (idx % 4 + 1);
|
||||
|
||||
// Parse date/time from ISO string
|
||||
const startDate = new Date(event.start);
|
||||
const endDate = new Date(event.end);
|
||||
|
||||
// Format date: yyyy.mm.dd
|
||||
const day = String(startDate.getDate()).padStart(2, '0');
|
||||
const month = String(startDate.getMonth() + 1).padStart(2, '0');
|
||||
const year = startDate.getFullYear();
|
||||
const dateStr = year + '.' + month + '.' + day;
|
||||
|
||||
// Format time: HH:MM (local time)
|
||||
const startHour = String(startDate.getHours()).padStart(2, '0');
|
||||
const startMinute = String(startDate.getMinutes()).padStart(2, '0');
|
||||
const endHour = String(endDate.getHours()).padStart(2, '0');
|
||||
const endMinute = String(endDate.getMinutes()).padStart(2, '0');
|
||||
const startStr = startHour + ':' + startMinute;
|
||||
const endStr = endHour + ':' + endMinute;
|
||||
|
||||
card.innerHTML = '<div class="date-header">' +
|
||||
'<div class="date-icon">📅</div>' +
|
||||
'<h3 class="date-headline">' + escapeHtml(event.headline || 'Event') + '</h3>' +
|
||||
'</div><div class="date-info">' +
|
||||
'<div class="date-row">' +
|
||||
'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="4" width="18" height="18" rx="2" ry="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg>' +
|
||||
'<span>' + dateStr + '</span>' +
|
||||
'</div><div class="date-row">' +
|
||||
'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>' +
|
||||
'<span>' + (isDE() ? 'Start' : 'Start') + ' ' + startStr + '</span>' +
|
||||
'</div><div class="date-row">' +
|
||||
'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>' +
|
||||
'<span>' + (isDE() ? 'Ende' : 'End') + ' ' + endStr + '</span>' +
|
||||
'</div></div>';
|
||||
|
||||
container.appendChild(card);
|
||||
});
|
||||
}
|
||||
|
||||
function setCookie(name, value, days) {
|
||||
const expires = new Date();
|
||||
expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000);
|
||||
document.cookie = name + '=' + encodeURIComponent(value) + ';expires=' + expires.toUTCString() + ';path=/';
|
||||
localStorage.setItem('paraguay_' + name, value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user