Show and edit marker images

This commit is contained in:
rueeggeandre committed 2026-06-01 03:41:30 +02:00
1 parent e4759b8961
commit 806aedb984
3 files changed
+174 -14

No files matched your search

+47 -3
View File
@@ -227,6 +227,20 @@
border-radius: var(--radius-2);
margin: var(--size-2) 0;
}
.chapter-images {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: var(--size-3);
margin: var(--size-3) 0;
}
.chapter-images img {
width: 100%;
aspect-ratio: 4 / 3;
object-fit: cover;
border-radius: var(--radius-2);
box-shadow: var(--shadow-2);
background: var(--surface-2);
}
.chapter-content {
line-height: 1.6;
}
@@ -290,7 +304,7 @@
const title = marker.title || `Chapter ${idx + 1}`;
const date = marker.date ? `<span class="marker-date">${new Date(marker.date).toLocaleDateString()}</span>` : '';
const content = marker.description ? escapeHtml(marker.description).replace(/\n/g, '<br>') : '';
const image = marker.image ? `<img src="${marker.image}" class="chapter-image">` : '';
const images = getMarkerImagesHtml(marker.images || (marker.image ? [marker.image] : []));
const video = marker.videoUrl ? `<iframe src="${marker.videoUrl}" frameborder="0" allowfullscreen></iframe>` : '';
chaptersHtml += `
<div class="chapter" data-marker-id="${marker.id || idx}">
@@ -298,7 +312,7 @@
<h3>${escapeHtml(title)}</h3>
${date}
</div>
${image}
${images}
${video}
<div class="chapter-content">${content}</div>
</div>
@@ -332,6 +346,36 @@
document.getElementById('delete-journey-btn')?.addEventListener('click', deleteJourney);
}
}
function getUploadUrl(path) {
if (!path) return '';
if (path.startsWith('http')) return path;
return API_BASE.replace('/api', path);
}
function getMarkerImagesHtml(images) {
if (!images || !images.length) return '';
const imageHtml = images.map((image) => {
const url = typeof image === 'string' ? image : image.url;
const alt = typeof image === 'string' ? 'Journey image' : image.originalName || 'Journey image';
if (!url) return '';
return `<img src="${escapeAttribute(getUploadUrl(url))}" alt="${escapeAttribute(alt)}">`;
}).join('');
if (!imageHtml) return '';
return `<div class="chapter-images">${imageHtml}</div>`;
}
function escapeAttribute(value) {
return String(value || '').replace(/[&<>"']/g, (char) => ({
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;'
})[char]);
}
async function deleteJourney() {
if (!confirm('Delete this journey permanently? All chapters and comments will be lost.')) return;
@@ -454,4 +498,4 @@
});
</script>
</body>
</html>
</html>