diff --git a/js/ct-events.js b/js/ct-events.js index ba2ea55..2ab0900 100644 --- a/js/ct-events.js +++ b/js/ct-events.js @@ -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); -var AppointmentImage = { +const AppointmentLinkify = { view: function(vnode) { - const {item, settings} = vnode.attrs; - const image_url = item.base.image?.fileUrl ?? (is_mobile ? default_image_mobile : null) ?? settings.default_image; - + const {item} = vnode.attrs; + if (!vnode.children || (vnode.children instanceof Array && vnode.children.length === 0)) { + return m("["); + } let url = item.base.link; if (url && !url.startsWith("http")) { 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( "img", @@ -28,11 +41,8 @@ var AppointmentImage = { alt: item.base.caption, }, ) : 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); } return m(".cte-description", [ - m("h1", item.base.caption), + m("h1", m(AppointmentLinkify, {item, settings}, item.base.caption)), m("h2", note_parts.join(" | ")), format_information(item), - m(AppointmentLocation,{item, settings}), + m(AppointmentLocation, {item, settings}), m(AppointmentLink, {item, settings}), ]); }