131 lines
3.5 KiB
JavaScript
131 lines
3.5 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
var modalEl = null;
|
|
var iframeEl = null;
|
|
var titleEl = null;
|
|
var modalReady = false;
|
|
|
|
function ensureModal() {
|
|
if (modalEl) {
|
|
return;
|
|
}
|
|
|
|
modalEl = document.createElement('div');
|
|
modalEl.className = 'modal fade eventup-registration-modal';
|
|
modalEl.id = 'eventupRegistrationModal';
|
|
modalEl.setAttribute('tabindex', '-1');
|
|
modalEl.setAttribute('role', 'dialog');
|
|
modalEl.setAttribute('aria-labelledby', 'eventupRegistrationModalTitle');
|
|
modalEl.setAttribute('aria-hidden', 'true');
|
|
modalEl.innerHTML =
|
|
'<div class="modal-dialog modal-dialog-centered modal-lg" role="document">' +
|
|
'<div class="modal-content">' +
|
|
'<div class="modal-header">' +
|
|
'<h5 class="modal-title" id="eventupRegistrationModalTitle">Register</h5>' +
|
|
'<button type="button" class="close" data-dismiss="modal" aria-label="Close">' +
|
|
'<span aria-hidden="true">×</span>' +
|
|
'</button>' +
|
|
'</div>' +
|
|
'<div class="modal-body eventup-registration-modal__body">' +
|
|
'<iframe class="eventup-registration-modal__frame" title="Event registration form" src="about:blank"></iframe>' +
|
|
'</div>' +
|
|
'</div>' +
|
|
'</div>';
|
|
|
|
document.body.appendChild(modalEl);
|
|
iframeEl = modalEl.querySelector('.eventup-registration-modal__frame');
|
|
titleEl = modalEl.querySelector('#eventupRegistrationModalTitle');
|
|
|
|
if (window.jQuery) {
|
|
window.jQuery(modalEl).on('hidden.bs.modal', function () {
|
|
if (iframeEl) {
|
|
iframeEl.src = 'about:blank';
|
|
}
|
|
});
|
|
}
|
|
|
|
modalReady = true;
|
|
}
|
|
|
|
function buildEmbedUrl(url) {
|
|
if (!url) {
|
|
return '';
|
|
}
|
|
|
|
try {
|
|
var parsed = new URL(url, window.location.href);
|
|
parsed.searchParams.set('embed', '1');
|
|
return parsed.toString();
|
|
} catch (error) {
|
|
var joiner = url.indexOf('?') >= 0 ? '&' : '?';
|
|
return url + joiner + 'embed=1';
|
|
}
|
|
}
|
|
|
|
function resolveRegistrationUrl(cta, config) {
|
|
if (cta && cta.url) {
|
|
return cta.url;
|
|
}
|
|
|
|
var meta = (config && config.meta) || {};
|
|
var eventId = meta.eventId;
|
|
var webBase = meta.webBaseUrl;
|
|
|
|
if (eventId && webBase) {
|
|
return String(webBase).replace(/\/$/, '') + '/event/' + eventId + '/register';
|
|
}
|
|
|
|
return '';
|
|
}
|
|
|
|
function openModal(url, title) {
|
|
ensureModal();
|
|
|
|
if (!url) {
|
|
console.warn('[registration-modal] No registration URL configured.');
|
|
return;
|
|
}
|
|
|
|
if (titleEl) {
|
|
titleEl.textContent = title || 'Register';
|
|
}
|
|
|
|
if (iframeEl) {
|
|
iframeEl.src = buildEmbedUrl(url);
|
|
}
|
|
|
|
if (window.jQuery) {
|
|
window.jQuery(modalEl).modal('show');
|
|
} else {
|
|
modalEl.classList.add('show');
|
|
modalEl.style.display = 'block';
|
|
modalEl.removeAttribute('aria-hidden');
|
|
}
|
|
}
|
|
|
|
function bindLink(link, cta, config) {
|
|
if (!link || link.getAttribute('data-registration-modal-bound') === 'true') {
|
|
return;
|
|
}
|
|
|
|
link.setAttribute('data-registration-modal-bound', 'true');
|
|
link.setAttribute('data-cta-target', 'modal');
|
|
link.href = '#';
|
|
|
|
link.addEventListener('click', function (event) {
|
|
event.preventDefault();
|
|
openModal(resolveRegistrationUrl(cta, config), cta && cta.text ? cta.text : 'Register');
|
|
});
|
|
}
|
|
|
|
window.EventUpRegistrationModal = {
|
|
bindLink: bindLink,
|
|
open: openModal,
|
|
resolveUrl: resolveRegistrationUrl,
|
|
isReady: function () {
|
|
return modalReady;
|
|
},
|
|
};
|
|
})();
|