EventBuzz_Backend/microsite-v2-templates/event-up_ol/assets/js/eventup-ssr-bridge.js

139 lines
4.4 KiB
JavaScript

(function () {
'use strict';
/** Minimal runtime bridge for SSR-published EventUp pages (no site-config.js DOM hydration). */
function readEmbeddedConfig() {
var el = document.getElementById('eventup-microsite-config');
if (!el || !el.textContent) return null;
try {
return JSON.parse(el.textContent);
} catch (e) {
return null;
}
}
function applyTheme(theme) {
if (!theme) return;
var root = document.documentElement;
if (theme.accent) {
root.style.setProperty('--eventup-accent', theme.accent);
root.style.setProperty('--eventup-accent-start', theme.accent);
}
var headingColor = (theme.heading && theme.heading.color) || theme.headingColor;
if (headingColor) {
root.style.setProperty('--eventup-heading-color', headingColor);
}
}
function initCountdown(hero) {
if (!hero || !hero.countdown || hero.countdown.show === false) {
var countSection = document.querySelector('[data-site-component="countdown"]');
if (countSection) countSection.style.display = 'none';
return;
}
if (!window.jQuery || !window.jQuery.fn.countdown) return;
var date = hero.countdown.date;
var time = hero.countdown.time || '12:00';
if (!date) return;
var target = new Date(date + 'T' + time + ':00');
window.jQuery('#clock').countdown(target, function (event) {
window.jQuery(this).html(event.strftime('%D days %H:%M:%S'));
});
}
function applyLinkTarget(linkEl, item) {
if (!linkEl || !item || !item.url) return;
linkEl.href = item.url;
if (item.target === '_blank') {
linkEl.target = '_blank';
linkEl.rel = 'noopener noreferrer';
return;
}
linkEl.removeAttribute('target');
if (item.target === '_self' || !item.target) {
linkEl.removeAttribute('rel');
}
}
function bindCtaLinks(config) {
var components = config.components || config.sections || {};
var heroCta = components.hero && components.hero.cta;
var heroLinks = document.querySelectorAll('[data-hero-cta-link], [data-nav-cta-link]');
if (heroCta && heroCta.url) {
if (heroCta.target === 'modal' && window.EventUpRegistrationModal && window.EventUpRegistrationModal.bindLink) {
heroLinks.forEach(function (a) {
window.EventUpRegistrationModal.bindLink(a, heroCta, config);
});
} else {
heroLinks.forEach(function (a) {
applyLinkTarget(a, heroCta);
});
}
}
var footer = components.footer;
if (!footer || !footer.links || !footer.links.length) return;
var footerLinkEls = document.querySelectorAll('[data-footer-link]');
footer.links.forEach(function (item, index) {
var linkEl = footerLinkEls[index];
if (!linkEl || !item.url) return;
if (item.target === 'modal' && window.EventUpRegistrationModal && window.EventUpRegistrationModal.bindLink) {
window.EventUpRegistrationModal.bindLink(linkEl, item, config);
return;
}
applyLinkTarget(linkEl, item);
});
}
function boot(config) {
if (!config) return;
applyTheme(config.theme || {});
initCountdown((config.components || config.sections || {}).hero);
bindCtaLinks(config);
var components = config.components || config.sections || {};
if (window.EventUpContactForm && components.contact) {
window.EventUpContactForm.init(components.contact, config);
}
if (window.EventUpFeedbackFab && components.feedback) {
window.EventUpFeedbackFab.init(components.feedback, config);
}
if (window.EventUpMarketingPopup && components.marketing_popup) {
window.EventUpMarketingPopup.init(components.marketing_popup, config);
}
document.documentElement.classList.add('site-config-loaded');
document.dispatchEvent(new CustomEvent('site-config-loaded'));
if (typeof window.updateNavbarSpacer === 'function') {
window.updateNavbarSpacer();
}
}
function init() {
var config = readEmbeddedConfig();
if (config) {
boot(config);
return;
}
fetch('config.json', { cache: 'no-store' })
.then(function (r) { return r.ok ? r.json() : null; })
.then(function (json) {
if (json) {
if (!json.components && json.sections) json.components = json.sections;
boot(json);
}
})
.catch(function () {});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();