(function () {
var appId = document.currentScript.src.split(‚/‘).slice(-1)[0].toUpperCase().split(‚?‘)[0]; //remove ?parameters
var __loadjs = function (a, b) { var c = document.createElement(„script“); c.setAttribute(„src“, a); c.setAttribute(„charset“, „UTF-8“); if (b) c.onload = c.onreadystatechange = function () { if (c.readyState) { if (c.readyState === „complete“ || c.readyState === „loaded“) { c.onload = c.onreadystatechange = null; b() } } else b() }; document.getElementsByTagName(„head“)[0].appendChild(c) };
var getURLParameter = function (name) {
var usp = new URLSearchParams(window.location.search)
for (var key of usp.keys())
if (key.toLowerCase() == name.toLowerCase()) // case-insensitive
return usp.get(key);
}
var setURLState = function (name, value) {
try {
let params = new URLSearchParams(window.location.search);
params.set(name, value);
window.history.pushState({}, „“, decodeURIComponent(`${window.location.pathname}?${params}`));
}
catch { }
}
var openSeres = function (aid) {
if (window.self !== window.top) {
window.top.location.href = ‚https://‘ + aid + ‚.mitdenkt.io‘;
return;
}
fetch(`https://${aid}.mitdenkt.io/api/v1`)
.then(r => {
if (r.status == 204) {
__loadjs(‚https://‘ + aid + ‚.mitdenkt.io/api/v1/static/sdk‘, function () {
seres.init({
server: ‚mitdenkt.io/api/v1‘,
version: ‚v1‘,
modal: true,
embedded: true,
appId: aid
})
})
return
}
if (r.status == 421) {
fetch(`https://whereami.mitdenkt.io?appId=${aid}`)
.then(r => r.json())
.then(j => {
if (j.error || !j.server || !j.apiCompat) throw j.error
__loadjs(`https://${j.server}.mitdenkt.io/sdk/sdk.${j.apiCompat}.min.js`, function () {
seres.init({
server: {
host: `${j.server}.mitdenkt.io`,
api: ‚/api/v2‘,
whereami: ‚whereami.mitdenkt.io‘
},
appId: aid,
version: ‚v2‘,
modal: true,
embedded: true
})
})
})
.catch(e => { alert(e || „Hoppla! Da ist etwas schiefgelaufen“) })
return
}
throw undefined
})
.catch(e => alert(e || „Hoppla! Da ist etwas schiefgelaufen.“))
}
//var openSeres = function (aid) {
// if (window.self !== window.top) {
// window.top.location.href = ‚https://‘ + aid + ‚.mitdenkt.io‘;
// return;
// }
// fetch(`https://whereami.mitdenkt.io?appId=${aid}`)
// .then(r => r.json())
// .then(j => {
// if (j.error) throw j.error;
// __loadjs(`https://${j.server}.mitdenkt.io/sdk/sdk.${j.apiCompat}.min.js`, function () {
// //seres.init({
// // server: j.server + ‚/api/v2‘,
// // modal: true,
// // embedded: true,
// // appId: aid
// //})
// seres.init({
// server: {
// host: `${j.server}.mitdenkt.io`,
// api: ‚/api/v2‘,
// whereami: ‚whereami.mitdenkt.io‘
// },
// appId: aid,
// version: ‚v2‘,
// modal: true,
// embedded: true
// })
// })
// })
// .catch(e => alert(‚Unexpected error: ‚ + e))
//}
if (getURLParameter(‚appId‘))
openSeres(getURLParameter(‚appId‘)); // open immediately
var loadfunc = function () {
if (document.getElementById(„visual_composer_content“) && document.getElementById(„iy“)) {
document.getElementById(„iy“).innerText = „[[[Buchungsformular wird hier angezeigt.]]]“;
return;
}
window.onpopstate = () => window.location.reload();
var legacyDiv = document.getElementById(„iy“);
var styles = “;
var btn = document.getElementById(„sereslauncher“);
if (!btn && document.getElementsByClassName(„seres-launcher“).length)
btn = document.getElementsByClassName(„seres-launcher“)[0];
if (!btn) {
btn = document.createElement(„button“);
btn.innerText = „Jetzt buchen“;
btn.id = „sereslauncher“;
styles += `
#sereslauncher {
color: white;
background: black;
cursor: pointer;
margin: 1em;
font-size: 1.3em;
padding: .3em .6em;
border: solid 1pt black;
outline: none;
border-radius: .5em;
}
#sereslauncher:hover {
box-shadow:0 0 4px 4px silver
}
`;
if (legacyDiv) { /* show button in old #iy div */
legacyDiv.innerText = “;
legacyDiv.appendChild(btn);
styles += `
#iy {
margin: 10px auto;
}`;
}
else {
document.body.appendChild(btn); {
styles += `
#sereslauncher {
position: fixed;
z-index: 2147480000;
bottom: 20px;
right: 20px;
}
`;
}
}
}
btn.onclick = function () {
setURLState(‚appId‘, appId)
openSeres(appId)
};
if (styles) {
let styleSheet = document.createElement(„style“)
styleSheet.type = „text/css“
styleSheet.innerText = styles
document.head.appendChild(styleSheet)