Make pilot and carousel buttons editable and simplify navigation arrows
This commit is contained in:
+29
-1
@@ -447,19 +447,47 @@ function safeArticleHref(value) {
|
||||
} catch { return ""; }
|
||||
}
|
||||
|
||||
// Only normalized colors and numeric radii can reach the inline style.
|
||||
function buttonColor(value) {
|
||||
if (typeof value !== "string") return null;
|
||||
const hex = value.trim();
|
||||
if (/^#[0-9a-f]{6}$/i.test(hex)) return hex.toLowerCase();
|
||||
if (/^#[0-9a-f]{3}$/i.test(hex)) return "#" + [...hex.slice(1)].map(c => c + c).join("").toLowerCase();
|
||||
return null;
|
||||
}
|
||||
|
||||
function accentButtonStyle(color, radius) {
|
||||
const background = buttonColor(color) || "#146ef5";
|
||||
const linear = background.slice(1).match(/../g).map(channel => {
|
||||
const srgb = parseInt(channel, 16) / 255;
|
||||
return srgb <= 0.04045 ? srgb / 12.92 : ((srgb + 0.055) / 1.055) ** 2.4;
|
||||
});
|
||||
const luminance = 0.2126 * linear[0] + 0.7152 * linear[1] + 0.0722 * linear[2];
|
||||
const foreground = (luminance + 0.05) / 0.05 > 1.05 / (luminance + 0.05) ? "#000000" : "#ffffff";
|
||||
const numeric = typeof radius === "number" || (typeof radius === "string" && radius.trim()) ? Number(radius) : NaN;
|
||||
const pixels = Number.isFinite(numeric) ? Math.max(0, Math.min(64, numeric)) : 8;
|
||||
return `--cta-bg:${background};--cta-ink:${foreground};--cta-radius:${pixels}px`;
|
||||
}
|
||||
|
||||
async function renderBlock(block, renderCounts) {
|
||||
if (block.enabled === false) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const templateName = block.template;
|
||||
if (["theses-request-demo.html", "request-demo-txt-files.html"].includes(templateName)) {
|
||||
const card = block.content?.accessCard;
|
||||
block = { ...block, buttonStyle: accentButtonStyle(card?.buttonColor, card?.buttonRadius) };
|
||||
}
|
||||
// Old CMS blocks can adopt the shared carousel without adding every optional field.
|
||||
if (["project-video-detail.html", "project-composition.html"].includes(templateName)) {
|
||||
block = { ...block, content: { mediaKind: "", note: "", modules: [], openImagesInFullscreen: false, ...block.content } };
|
||||
const button = block.content.detailsButton || {};
|
||||
block.content.sliderItems = (block.content.sliderItems || []).map(item => ({
|
||||
description: "", imageSrc: "", imageAlt: "", videoSrc: "", posterSrc: "", ...item,
|
||||
detailsHref: safeArticleHref(item.detailsHref),
|
||||
detailsLabel: typeof item.detailsLabel === "string" && item.detailsLabel.trim() ? item.detailsLabel.trim() : "Подробнее",
|
||||
detailsLabel: String(item.detailsLabel || "").trim() || String(button.label || "").trim() || "Подробнее",
|
||||
buttonStyle: accentButtonStyle((item.useButtonColor === true && buttonColor(item.buttonColor)) || button.color, button.radius),
|
||||
imageSizes: ["photo-gallery", "scenario-gallery"].includes(block.content.mediaKind) ? "(max-width: 767px) 82vw, 560px" : "(max-width: 767px) 86vw, 1280px",
|
||||
imageLinkEnabled: block.content.openImagesInFullscreen === true,
|
||||
imageLinkDisabled: block.content.openImagesInFullscreen !== true,
|
||||
|
||||
Reference in New Issue
Block a user