var scriptCounter = (scriptCounter || 0); (function() { var iFrame = document.createElement('iframe'); var src = null; iFrame.id = "gastronaviReservationWidget-" + scriptCounter; iFrame.src = "https://www.kraenholm.de/reservation/widget/91392/78562/1/templates/newgeneration/css?embed=1&companyRoute=1&fixedButton=0&iframeId=" + iFrame.id + "&referral="; iFrame.width = "100%"; iFrame.height = "400"; iFrame.setAttribute("style", "max-width: 100%; display: block;"); iFrame.frameBorder = "0"; iFrame.allow = "payment"; var scripts = document.getElementsByTagName('script'); for(var i=0; i < scripts.length; i++){ if(scripts[i].src && scripts[i].src.indexOf('/scripts/widget/91392/78562/1/templates/newgeneration/css') != -1){ var scriptExecuted = scripts[i].getAttribute('data-gn-executed'); if(!scriptExecuted) { scripts[i].setAttribute('gn-executed', true); src = scripts[i]; scriptCounter++; break; } } } var wrapper = document.createElement('div'); wrapper.setAttribute("style", "position: relative; width: 100%; margin:auto;"); wrapper.style.width = "100%"; var loadingOverlay = document.createElement('div'); loadingOverlay.setAttribute("style", "z-index: 99; position: absolute; left: 0; top: 0; right: 0; bottom: 0;"); var innerHtml = ''; innerHtml += ''; innerHtml += ''; loadingOverlay.innerHTML = innerHtml; iFrame.style.visibility = "hidden"; wrapper.appendChild(loadingOverlay); wrapper.appendChild(iFrame); var showIframeHandler = function() { if (wrapper.contains(loadingOverlay)) { wrapper.removeChild(loadingOverlay); } iFrame.style.visibility = "visible"; }; var onload = function(e) { window.setTimeout(function() { if (wrapper.contains(loadingOverlay)) { console.warn("loadingOverlay timed out, hide overlay before getting initialized from iframe"); showIframeHandler(); } }, 5000); // fallback ... always remove overlay after load + 5sec }; if (iFrame.addEventListener) { iFrame.addEventListener('load', onload, false); } else { iFrame.attachEvent('onload', onload); } if(src) src.parentNode.insertBefore(wrapper, src); var onmessage = function(e) { var iframeId = e.data[0] var eventName = e.data[1]; var data = e.data[2]; if (iframeId && iframeId != iFrame.id) { return; } switch(eventName) { case 'setHeight': var prevBoundings = iFrame.getBoundingClientRect(); var prevScrollPosition = document.documentElement.scrollTop || document.body.scrollTop; iFrame.height = data; iFrame.style.height = data + (data.toString().match(/(%|px)/) ? "" : "px"); var boundings = iFrame.getBoundingClientRect(); if(prevBoundings.top + prevBoundings.height > 0 && boundings.top < 0) { var scrollDiff = Math.min(prevBoundings.height-boundings.height, boundings.top*-1); if(scrollDiff > 0) document.documentElement.scrollTop = document.body.scrollTop = prevScrollPosition - scrollDiff; } break; case 'initialized': showIframeHandler(); if (window.self != window.top) { e.source.postMessage(['parent', 'isSandboxed', true], '*'); } else { e.source.postMessage(['parent', 'isSandboxed', false], '*'); } break; } }; if (window.addEventListener) { window.addEventListener('message', onmessage, false); } else { window.attachEvent('onmessage', onmessage); } })();