window.addEventListener("message", (event) => {
if (typeof dataLayer === "undefined") {
const dataLayer = [];
dataLayer.push(JSON.parse(event.data));
} else {
dataLayer.push(JSON.parse(event.data));
}
});
const frameId = "going-modal-frame";
const eventLocation = "https://goingapp.pl";
const modalStyleElement = document.createElement("link");
const modalElement = document.createElement("div");
const frameElement = document.createElement("div");
const closeElement = document.createElement("i");
const closeModal = () => (modalElement.style.display = "none");
const openModal = () => (modalElement.style.display = "flex");
modalStyleElement.href =
"https://embed-config-meqesdpgvc.s3-eu-west-1.amazonaws.com/going-modal-embed/going-modal.css";
modalStyleElement.type = "text/css";
modalStyleElement.rel = "stylesheet";
modalElement.id = "going-modal";
frameElement.id = frameId;
closeElement.id = "going-close";
closeElement.innerText = "✖︎";
closeElement.onclick = closeModal;
modalElement.onclick = closeModal;
document.head.appendChild(modalStyleElement);
modalElement.appendChild(frameElement);
modalElement.appendChild(closeElement);
document.body.appendChild(modalElement);
function checkGoingLink(link) {
if (link.href.includes(`${eventLocation}/buying/`)) {
return true;
}
if (link.href.includes(`${eventLocation}/wydarzenie/`)) {
return true;
}
return link.href.includes(`${eventLocation}/kup-bilety/`);
}
function reloadIframe(src) {
GoingService.iframe.src = src;
setTimeout(function () {
window.goingQ = [
{
type: "SET_PARENT",
payload: frameId,
},
{
type: "SET_APP_URL",
payload: src,
},
{
type: "SET_CURRENT_URL",
payload: window.location.href,
},
];
GoingService.newReloadIframe();
[
{
type: "SET_PARENT",
payload: frameId,
},
{
type: "SET_APP_URL",
payload: src,
},
{
type: "SET_CURRENT_URL",
payload: window.location.href,
},
].forEach((action) => GoingService.sendMessageToChild(action));
openModal();
}, 400);
}
function checkParams() {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const error = urlParams.has("error");
const success = urlParams.has("transactionId");
if (error || success) {
openModal();
}
}
window.onload = () => {
const linksArray = Array.prototype.slice.call(document.links);
(function (G, o, i, n, g) {
G.going =
G.going ||
function () {
[].push.apply((G.goingQ = G.goingQ || []), arguments);
};
G.goingSettings = { gv: 1, gid: 1 };
n = o.getElementsByTagName("head")[0];
g = o.createElement("script");
g.async = true;
g.src = i + "?gid=" + G.goingSettings.gid + "&gv=" + G.goingSettings.gv;
n.appendChild(g);
})(window, document, "https://goingapp.pl/static_legacy/going/script.js");
going(
{
type: "SET_PARENT",
payload: frameId,
},
{
type: "SET_APP_URL",
payload: linksArray.find((link) => checkGoingLink(link)).href,
},
{
type: "SET_CURRENT_URL",
payload: window.location.href,
},
{
type: "GET_TRANSACTION_FROM_URL",
payload: "transactionId",
},
{
type: "GET_ERROR_FROM_URL",
payload: "error",
}
);
linksArray.forEach(function (link, index) {
if (checkGoingLink(link)) {
const linkMap = link.href.split("/");
document.links.item(index).addEventListener("click", function (event) {
event.preventDefault();
reloadIframe(`${eventLocation}/buying/${linkMap[4]}/${linkMap[5]}`);
});
}
});
checkParams();
};