linkify image and title

This commit is contained in:
Stefan Bühler 2025-01-04 00:13:41 +01:00
parent 2ee91c9686
commit 034fd7b4ba

View File

@ -11,15 +11,28 @@ function fa_solid_icon(settings, name) {
const is_mobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); const is_mobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
var AppointmentImage = { const AppointmentLinkify = {
view: function(vnode) { view: function(vnode) {
const {item, settings} = vnode.attrs; const {item} = vnode.attrs;
const image_url = item.base.image?.fileUrl ?? (is_mobile ? default_image_mobile : null) ?? settings.default_image; if (!vnode.children || (vnode.children instanceof Array && vnode.children.length === 0)) {
return m("[");
}
let url = item.base.link; let url = item.base.link;
if (url && !url.startsWith("http")) { if (url && !url.startsWith("http")) {
url = "https://" + url; url = "https://" + url;
} }
if (url) {
return m("a", {href: url}, vnode.children);
} else {
return m("[", vnode.children);
}
}
}
var AppointmentImage = {
view: function(vnode) {
const {item, settings} = vnode.attrs;
const image_url = item.base.image?.fileUrl ?? (is_mobile ? default_image_mobile : null) ?? settings.default_image;
let img = image_url ? m( let img = image_url ? m(
"img", "img",
@ -28,11 +41,8 @@ var AppointmentImage = {
alt: item.base.caption, alt: item.base.caption,
}, },
) : null; ) : null;
if (img && url) {
img = m("a", {href: url}, img);
}
return m(".cte-image", img) return m(".cte-image", m(AppointmentLinkify, {item}, img))
} }
} }
@ -194,10 +204,10 @@ var AppointmentDescription = {
note_parts.push(item.base.address.meetingAt); note_parts.push(item.base.address.meetingAt);
} }
return m(".cte-description", [ return m(".cte-description", [
m("h1", item.base.caption), m("h1", m(AppointmentLinkify, {item, settings}, item.base.caption)),
m("h2", note_parts.join(" | ")), m("h2", note_parts.join(" | ")),
format_information(item), format_information(item),
m(AppointmentLocation,{item, settings}), m(AppointmentLocation, {item, settings}),
m(AppointmentLink, {item, settings}), m(AppointmentLink, {item, settings}),
]); ]);
} }