document.addEventListener('DOMContentLoaded', function() { // params from $_GET const node_id = 'hoelper_frame'; const base = 'https://hoelper.anderreihe.de'; const lang = ''; const app = 'index'; const iframeId = '' || randomId(); const hideLogo = ''; // create iframe if (document.getElementById(iframeId)) { console.error('Element with id ' + iframeId + ' already exists'); return; } const iframe = document.createElement('iframe'); iframe.id = iframeId; iframe.src = app === 'index' ? (base) : (base + '/' + app + '.html'); const code = window.location .search .split('?') .pop() .split('&') .map(keyValue => keyValue.split('=')) .map(entry => Object.fromEntries([entry])) .reduce((current, prev) => Object.assign(prev, current), {}) ?.booking_code; const params = {}; if (code) { params.code = code; } if (lang) { params.lang = lang; } if (hideLogo) { params.hide_logo = 'yes'; } const paramsString = Object.entries(params) .map(entry => entry.join('=')) .join('&'); iframe.src += '?' + paramsString; // append iframe const node = document.getElementById(node_id); if (!node) { console.error('Element with id ' + node_id + ' not found'); return; } node.appendChild(iframe); // add page height listener for the appended iframe (function() { const handlers = []; function iframeResize(id) { const iframe = document.getElementById(id); if (!iframe) { return; } handlers.push(function(event) { if (typeof event.data !== 'object') { return; } if (event.source !== iframe.contentWindow) { return; } if (event.data.type === 'Embed.heightChange') { if (event.data.height > 0) { iframe.style.height = (event.data.height) + 'px'; } } }); } window.addEventListener('message', function(event) { handlers.forEach(function(handler) { handler(event); }); }, false); iframeResize(iframeId); })(); // create default iframe styles const style = document.createElement('style'); if (!style) { console.error('unable to create style tag'); return; } style.id = 'styles_' + iframeId; style.innerText += '#' + node_id + ' {position: relative;} '; style.innerText += '#' + iframeId + ' {border: none;} '; document.head.appendChild(style); // helper functions function randomId(min = 1000, max = 10000) { // min and max included const randomInt = Math.floor(Math.random() * (max - min + 1) + min); const randomString = btoa(randomInt.toString()).replace(/=/gi, 'x'); return ['id', randomString].join('_'); } });