/** * Event handler for smartGtag() to proxy gtag events from the iframe to gtag on the parent page */ window.addEventListener('message', function(event) { // Handle events not coming from smartGtag() if ( typeof event.data !== "object" || typeof event.data.type !== "string" || event.data.type !== "gtagEvent" || typeof event.data.gtagEventType !== "string" ) { return; } // Handle missing payload if (typeof event.data.payload !== "object") { console.error("Missing payload for smartGtag() function"); return; } // Handle Google Analytics not installed on the Customers Website // Its possible that in this case, we could potentially look up the supplier using the // alias in the domain, get their Google Analytics settings then initialise gtag here as a fallback // But for now, lets keep it simple and hope we don't get too many complaints. If we do, then // we can go down that path if (typeof window.gtag !== "function") { console.info("Google Analytics snippet not installed on parent page, so not using Google Analytics"); return; } // Guard clauses caught nothing so were all good, call gtag() const { gtagEventType, payload } = event.data; window.gtag('event', gtagEventType, payload); }); window.rzdApp = window.rzdApp || {}; rzdApp.FeatureDetector = function() {}; rzdApp.FeatureDetector.isSafari = (window.navigator.userAgent.indexOf('Safari') !== -1 && window.navigator.userAgent.indexOf('Chrome') === -1 && window.navigator.userAgent.indexOf('Firefox') === -1); rzdApp.FeatureDetector.supportedFeatures = ['iframe-resize', 'embedded-cart', 'unified-modal']; rzdApp.FeatureDetector.detectFeature = function _detectFeature(feature) { var existingScript = null; var script = null; var scriptId = 'rzd-'+ feature; script = document.createElement('script'); script.id = scriptId; script.defer = true; existingScript = document.querySelector('#' + scriptId); if (existingScript) { return true; } var rzdIframes = [].filter.call(document.querySelectorAll('iframe'), function(iframe) { return iframe.className.indexOf('rezdy') !== -1 || iframe.src.indexOf('rezdy.com') !== -1; }); /* Check for features to activate */ switch(feature) { case 'iframe-resize': script.innerText = " var rzdResizeIframe = function _rzdResizeIframe(iframe) {"+ " var rzdFindPos = function _findPos(obj) {"+ " var curleft = 0;"+ " var curtop = 0;"+ " if (obj.offsetParent) {"+ " do {"+ " curleft += obj.offsetLeft;"+ " curtop += obj.offsetTop;"+ " } while (obj = obj.offsetParent);"+ " }"+ " return {x: curleft, y: curtop};"+ " };"+ ""+ " try {"+ " iFrameResize({"+ " checkOrigin: false,"+ " log: false,"+ " enablePublicMethods: false,"+ " heightCalculationMethod: 'lowestElement',"+ " messageCallback: function(data) {"+ " if (data.message.type === 'scrollToTop') {"+ ""+ " /*See https://github.com/jquery/jquery/blob/master/src/offset.js#L74*/"+ " var getOffset = function _offset(elem) {"+ " if ( !elem.getClientRects().length ) {"+ " return { top: 0, left: 0 };"+ " }"+ ""+ " var rect = elem.getBoundingClientRect();"+ " var win = elem.ownerDocument.defaultView;"+ " return {"+ " top: rect.top + win.pageYOffset,"+ " left: rect.left + win.pageXOffset"+ " };"+ " };"+ " window.scrollTo(0, getOffset(data.iframe).top);"+ " }"+ " },"+ " resizedCallback: function(messageData){ /* Callback fn when resize is received*/"+ " var iframePosition = rzdFindPos(document.getElementById(messageData.id));"+ ""+ " if (typeof iframePosition !== 'undefined') {"+ " var iframeBottomPosition = iframePosition.y + parseFloat(messageData.height);"+ ""+ " if(window.pageYOffset > iframeBottomPosition) {"+ " window.scrollTo(0, iframePosition.y);"+ " }"+ " }"+ " },"+ " }, iframe);"+ " } catch (error) {"+ " /** iFrameResize throwing an error might be because existing outdated resizer is on the page */"+ " rzdApp.hasError = true;"+ " console.error(error);"+ " }"+ " };"+ ""+ " /**"+ " * use event delegation to resize async loaded iframes"+ " */"+ " var iframeResizeHandler = function _iframeResizeHandler(event) {"+ " if (event.target && event.target.matches('iframe.rezdy') || event.target.src.indexOf('rezdy.com') !== -1) {"+ " rzdResizeIframe(event.target);"+ " }"+ " };"+ " document.removeEventListener('load', iframeResizeHandler);"+ " document.addEventListener('load', iframeResizeHandler);"+ ""+ " if (!document.querySelector('#rzd-iframe-resizer')) {"+ ""+ " var rzdIframeResizer = document.createElement('script');"+ " rzdIframeResizer.id = 'rzd-iframe-resizer';"+ " rzdIframeResizer.defer = true;"+ " rzdIframeResizer.addEventListener('load',function() {"+ " rzdApp.iFrameResize = function(){};"+ " rzdApp.iFrameResize.prototype = window.iFrameResize.prototype;"+ " /*Resize any existing Iframes*/"+ " [].forEach.call(document.querySelectorAll('iframe'), function(iframe) {"+ " if (iframe.src.indexOf('rezdy.com') !== -1 || iframe.className.indexOf('rezdy') !== -1) {"+ " rzdResizeIframe(iframe);"+ " iframe.addEventListener('load', function(event) {"+ " /*If the error has been triggered before iframe is done loading... don't send health check*/"+ " if (!rzdApp.hasError) {"+ " event.target.contentWindow.postMessage('rzd_plugin_js_loaded', '*');"+ " }"+ " event.target.contentWindow.postMessage('CUSTOMER_URL=' + window.location.href, '*');"+ " });"+ " }"+ " });"+ " });"+ " rzdIframeResizer.src = 'https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/3.6.2/iframeResizer.min.js';"+ ""+ " document.body.append(rzdIframeResizer);"+ " }"+ ""; break; case 'embedded-cart': if (document.querySelector('#rezdy-embedded-cart')) { script.innerText = " window.rzdApp = window.rzdApp || {};"+ " rzdApp.embeddedCart = rzdApp.embeddedCart || {};"+ ""+ " rzdApp.embeddedCart.open = function _openCart(event) {"+ " window.postMessage({url: window.rezdyCartLink + '?iframe=1', data: '', type: 'rezdy_open_in_modal'}, '*');"+ " };"+ ""+ " rzdApp.embeddedCart.update = function _updateCartQty() {"+ " var ajaxUrl = 'https://tanganyikacoastalcampsite95.rezdy.com/ajax';"+ " var cart = document.querySelector('#rezdy-embedded-cart');"+ " var cartCount = cart.querySelector('.rezdy-cart-count');"+ " var cartLabel= cart.querySelector('.rezdy-cart');"+ " var cartLoading = cart.querySelector('.rezdy-cart-loading');"+ " var cartEmpty = cart.querySelector('.rezdy-cart-empty');"+ ""+ " var numberOfItems = 0;"+ ""+ " fetchJsonp(ajaxUrl + '?method=cartsize&callback=callback')"+ " .then(function(json) { return json.json(); })"+ " .then(function (response) {"+ " if (response.length) {"+ " numberOfItems = parseInt(response[0], 10);"+ " }"+ ""+ " if(numberOfItems >= 1) {"+ ""+ " cartCount.innerText = numberOfItems;"+ " if (cartCount.classList.contains('hidden')) {"+ " cartCount.classList.remove('hidden');"+ " }"+ ""+ " if(cartLabel.classList.contains('hidden')) {"+ " cartLabel.classList.remove('hidden');"+ " }"+ ""+ " if (!cartLoading.classList.contains('hidden')) {"+ " cartLoading.classList.add('hidden');"+ " }"+ ""+ " if (!cartEmpty.classList.contains('hidden')) {"+ " cartEmpty.classList.add('hidden');"+ " }"+ ""+ " } else {"+ " if (!cartCount.classList.contains('hidden')) {"+ " cartCount.classList.add('hidden');"+ " }"+ ""+ " if(!cartLabel.classList.contains('hidden')) {"+ " cartLabel.classList.add('hidden');"+ " }"+ ""+ " if (!cartLoading.classList.contains('hidden')) {"+ " cartLoading.classList.add('hidden');"+ " }"+ ""+ " if (cartEmpty.classList.contains('hidden')) {"+ " cartEmpty.classList.remove('hidden');"+ " }"+ " }"+ " })"+ " .catch(function(){"+ " if (!cartCount.classList.contains('hidden')) {"+ " cartCount.classList.add('hidden');"+ " }"+ ""+ " if(!cartLabel.classList.contains('hidden')) {"+ " cartLabel.classList.add('hidden');"+ " }"+ ""+ " if (cartLoading.classList.contains('hidden')) {"+ " cartLoading.classList.remove('hidden');"+ " }"+ ""+ " if (!cartEmpty.classList.contains('hidden')) {"+ " cartEmpty.classList.add('hidden');"+ " }"+ " });"+ " };"+ ""+ " rzdApp.embeddedCart.init = function _embeddedCart() {"+ " var cart = document.querySelector('#rezdy-embedded-cart');"+ ""+ " if (!cart) { return; }"+ " cart.removeEventListener('click', rzdApp.embeddedCart.open);"+ " cart.addEventListener('click', rzdApp.embeddedCart.open);"+ ""+ " rzdApp.embeddedCart.update();"+ " [].forEach.call(document.querySelectorAll('iframe.rezdy'), function (iframe) {"+ " iframe.addEventListener('load', rzdApp.embeddedCart.update);"+ " });"+ " };"+ ""+ " rzdApp.embeddedCart.shutdown = function _shutdown() {"+ " document.removeEventListener('click', rzdApp.embeddedCart.open);"+ ""+ " [].forEach.call(document.querySelectorAll('iframe'), function (iframe) {"+ ""+ " if (iframe.src.indexOf('rezdy.com') !== -1 || iframe.className.indexOf('rezdy') !== -1) {"+ " iframe.removeEventListener('load', rzdApp.embeddedCart.update);"+ " }"+ " });"+ ""+ " document.querySelector('#rezdy-embedded-cart').onclick = function() {"+ " window.location.href = window.rezdyCartLink;"+ " };"+ " };"+ ""+ " if(!document.querySelector('#rzd-fetch-jsonp')) {"+ " var script = document.createElement('script');"+ " script.id = 'rzd-fetch-jsonp';"+ " script.defer = true;"+ " script.addEventListener('load', rzdApp.embeddedCart.init);"+ ""+ " script.src = 'https://cdnjs.cloudflare.com/ajax/libs/fetch-jsonp/1.1.3/fetch-jsonp.min.js';"+ ""+ " document.body.append(script);"+ " } else {"+ " rzdApp.embeddedCart.init();"+ " }"; } break; case 'unified-modal': if (!document.querySelector('#rzd-modal-css')) { var rzdModalCss = document.createElement('link'); rzdModalCss.id = 'rzd-modal-css'; rzdModalCss.rel ='stylesheet'; rzdModalCss.type = 'text/css'; rzdModalCss.href = 'data:text/css;base64,LnJ6ZC1tb2RhbHsKICAgIHBvc2l0aW9uOmZpeGVkOwogICAgdG9wOjA7CiAgICByaWdodDowOwogICAgYm90dG9tOjA7CiAgICBsZWZ0OjA7CiAgICB0ZXh0LWFsaWduOmxlZnQ7CiAgICBiYWNrZ3JvdW5kOnJnYmEoMCwwLDAsLjgpOwogICAgdHJhbnNpdGlvbjpvcGFjaXR5IC4yNXMgZWFzZTsKICAgIG92ZXJmbG93LXk6YXV0bwp9Ci5yemQtbW9kYWxfX2JnewogICAgcG9zaXRpb246YWJzb2x1dGU7CiAgICB0b3A6MDsKICAgIHJpZ2h0OjA7CiAgICBib3R0b206MDsKICAgIGxlZnQ6MDsKICAgIGN1cnNvcjpwb2ludGVyCn0KLnJ6ZC1tb2RhbHsKICAgIHotaW5kZXg6OTk5OTk5OTk5OTsKICAgIG9wYWNpdHk6MTsKICAgIHZpc2liaWxpdHk6dmlzaWJsZQp9Ci5yemQtbW9kYWxfX2lubmVyewogICAgdHJhbnNpdGlvbjp0b3AgLjI1cyBlYXNlOwogICAgcG9zaXRpb246YWJzb2x1dGU7CiAgICB0b3A6NDBweDsKICAgIHJpZ2h0OjA7CiAgICBsZWZ0OjA7CiAgICBtYXJnaW46YXV0bzsKICAgIGJhY2tncm91bmQtY29sb3I6I2ZmZjsKICAgIGJvcmRlci1yYWRpdXM6NXB4OwogICAgbWF4LXdpZHRoOjEwMjBweDsKICAgIHdpZHRoOjEwMCU7CiAgICBoZWlnaHQ6Y2FsYygxMDB2aCAtIDEwMHB4KTsKfQoucnpkLW1vZGFsX19jbG9zZXsKICAgIHBvc2l0aW9uOmFic29sdXRlOwogICAgdG9wOjA7CiAgICByaWdodDowOwogICAgZGlzcGxheTpibG9jazsKICAgICBoZWlnaHQ6MjRweDsKICAgIHdpZHRoOjQwcHg7CiAgICBsaW5lLWhlaWdodDoyNHB4OwogICAgdGV4dC1hbGlnbjpjZW50ZXI7CiAgICBmb250LXNpemU6MjBweDsKICAgIG1hcmdpbjowOwogICAgYmFja2dyb3VuZDpyZ2JhKDAsMCwwLC43NSk7CiAgICBjb2xvcjojZmZmIWltcG9ydGFudDsKICAgIHBhZGRpbmc6MDsKICAgIGJvcmRlci1yYWRpdXM6MCAwIDAgM3B4OwogICAgYm9yZGVyOm5vbmU7CiAgICBjdXJzb3I6cG9pbnRlcjsKICAgIHotaW5kZXg6MTA2MAp9Ci5yemQtbW9kYWxfX2Nsb3NlIHNwYW57CiAgICBjb2xvcjojZmZmIWltcG9ydGFudAp9Ci5yemQtbW9kYWxfX2xvYWRlcnsKICAgIGRpc3BsYXk6aW5saW5lLWJsb2NrOwogICAgcG9zaXRpb246cmVsYXRpdmU7CiAgICB0b3A6NTAlOwogICAgbGVmdDo1MCU7CiAgICB3aWR0aDo2NHB4OwogICAgaGVpZ2h0OjY0cHgKfQoucnpkLW1vZGFsX19sb2FkZXIgZGl2ewogICAgYm94LXNpemluZzpib3JkZXItYm94OwogICAgZGlzcGxheTpibG9jazsKICAgIHBvc2l0aW9uOmFic29sdXRlOwogICAgd2lkdGg6NTFweDsKICAgIGhlaWdodDo1MXB4OwogICAgbWFyZ2luOjZweDsKICAgIGJvcmRlcjo2cHggc29saWQgI2ZmZjsKICAgIGJvcmRlci1yYWRpdXM6NTAlOwogICAgYW5pbWF0aW9uOnJ6ZC1sb2FkZXIgMS4ycyBjdWJpYy1iZXppZXIoLjUsMCwuNSwxKSBpbmZpbml0ZTsKICAgIGJvcmRlci1jb2xvcjojZmZmIHRyYW5zcGFyZW50IHRyYW5zcGFyZW50Cn0KLnJ6ZC1tb2RhbF9fbG9hZGVyIGRpdjpudGgtY2hpbGQoMSl7CiAgICBhbmltYXRpb24tZGVsYXk6LS40NXMKfQoucnpkLW1vZGFsX19sb2FkZXIgZGl2Om50aC1jaGlsZCgyKXsKICAgIGFuaW1hdGlvbi1kZWxheTotLjNzCn0KLnJ6ZC1tb2RhbF9fbG9hZGVyIGRpdjpudGgtY2hpbGQoMyl7CiAgICBhbmltYXRpb24tZGVsYXk6LS4xNXMKfQpAa2V5ZnJhbWVzIHJ6ZC1sb2FkZXJ7CiAgICAwJXsKICAgICAgICB0cmFuc2Zvcm06cm90YXRlKDApCiAgICB9CiAgICAxMDAlewogICAgICAgIHRyYW5zZm9ybTpyb3RhdGUoMzYwZGVnKQogICAgfQp9CkBtZWRpYSBzY3JlZW4gYW5kIChtYXgtd2lkdGg6NzY4cHgpewogICAgLnJ6ZC1tb2RhbF9faW5uZXJ7CiAgICAgICAgd2lkdGg6OTAlOwogICAgICAgIGhlaWdodDo5MCU7CiAgICAgICAgYm94LXNpemluZzpib3JkZXItYm94OwogICAgfQp9'; document.head.append(rzdModalCss); } script.innerText = " window.rzdApp = window.rzdApp || {};"+ " rzdApp.unifiedModal = rzdApp.unifiedModal || {};"+ " rzdApp.unifiedModal.currentBodyStyle = document.body.style;"+ " rzdApp.unifiedModal.currentHtmlStyle = document.documentElement.style;"+ ""+ " rzdApp.unifiedModal.init = function _init() {"+ ""+ " window.removeEventListener('message', rzdApp.unifiedModal.slickCloseHandler);"+ " window.addEventListener('message', rzdApp.unifiedModal.slickCloseHandler);"+ ""+ " window.removeEventListener('keydown', rzdApp.unifiedModal.escapeHandler);"+ " window.addEventListener('keydown', rzdApp.unifiedModal.escapeHandler);"+ ""+ " document.removeEventListener('click', rzdApp.unifiedModal.simpleModalHandler);"+ " document.addEventListener('click', rzdApp.unifiedModal.simpleModalHandler);"+ ""+ " var mobileRegEx = new RegExp('mobi', 'i');"+ " var userAgent = window.navigator.userAgent;"+ " if (mobileRegEx.test(userAgent) || rzdApp.FeatureDetector.isSafari) {"+ " document.removeEventListener('click', rzdApp.unifiedModal.simpleModalHandler);"+ " }"+ ""+ " /*ensure the previous message handler is replaced*/"+ " window.removeEventListener('message', rzdApp.unifiedModal.openOnMessage);"+ " window.addEventListener('message', rzdApp.unifiedModal.openOnMessage);"+ " if (window.top !== window) {"+ " rzdApp.hasError = true;"+ " throw new Error('This script should not be embedded inside an iframe.');"+ " }"+ " };"+ ""+ " rzdApp.unifiedModal.releaseTheLock = function _releaseTheLock() {"+ " var iframes = [].filter.call(document.querySelectorAll('iframe'), function(iframe) {"+ " return iframe.className.indexOf('rezdy') !== -1 || iframe.src.indexOf('rezdy.com');"+ " });"+ " if (iframes.length) {"+ " [].forEach.call(iframes, function(iframe){"+ " iframe.contentWindow.postMessage('rezdy_release_the_lock', '*');"+ " });"+ " }"+ " };"+ ""+ " rzdApp.unifiedModal.cleanupHandler = function cleanupHandler(event) {"+ " if (typeof event !== 'undefined') {"+ " event.stopPropagation();"+ " event.preventDefault();"+ " }"+ ""+ " var existingModal = document.querySelector('#rzd-modal');"+ " if (existingModal && existingModal.parentNode) {"+ " var existingIFrame = existingModal.querySelector('iframe');"+ " if (existingIFrame && existingIFrame.iFrameResizer) {"+ " existingIFrame.iFrameResizer.close();"+ " }"+ " existingModal.remove();"+ " }"+ ""+ " document.body.style = rzdApp.unifiedModal.currentBodyStyle;"+ " document.documentElement.style = rzdApp.unifiedModal.currentHtmlStyle;"+ ""+ " /** Ugly workaround for IE11 … Couldn't find a better way*/"+ " try {"+ " if (document.body.style instanceof MSStyleCSSProperties) {"+ " document.body.setAttribute('style', document.body.getAttribute('style').replace('-ms-overflow-y: hidden;'));"+ " document.documentElement.setAttribute('style', document.documentElement.getAttribute('style').replace('-ms-overflow-y: hidden;'));"+ " }"+ " } catch (e) { /* Not IE */ }"+ ""+ " rzdApp.unifiedModal.releaseTheLock();"+ " };"+ ""+ " rzdApp.unifiedModal._generateModal = function _generateModal() {"+ " if (window.top !== window){"+ " rzdApp.hasError = true;"+ " throw new Error('This script should not be embedded inside an iframe.');"+ " }"+ ""+ " var modalContainer = document.createElement('div');"+ " modalContainer.className = 'rzd-modal';"+ " modalContainer.id = 'rzd-modal';"+ ""+ " var modalBackground = document.createElement('label');"+ " modalBackground.className = 'rzd-modal__bg';"+ ""+ " var loader = document.createElement('div');"+ " loader.className = 'rzd-modal__loader';"+ " loader.innerHTML = '
';"+ " modalBackground.append(loader);"+ ""+ " var modalInnerWrapper = document.createElement('div');"+ " modalInnerWrapper.className = 'rzd-modal__inner';"+ " modalInnerWrapper.style.visibility = 'hidden';"+ ""+ " var modalClose = document.createElement('label');"+ " modalClose.className = 'rzd-modal__close';"+ " modalClose.onclick = function(event) {"+ " event.preventDefault();"+ " rzdApp.unifiedModal.cleanupHandler(event);"+ " };"+ " modalClose.innerText = 'x';"+ ""+ " var modalContentWrapper = document.createElement('div');"+ " modalContentWrapper.className = 'rzd-modal__content';"+ ""+ " modalInnerWrapper.append(modalClose);"+ " modalInnerWrapper.append(modalContentWrapper);"+ " modalContainer.append(modalBackground);"+ " modalContainer.append(modalInnerWrapper);"+ ""+ " document.body.append(modalContainer);"+ ""+ " document.body.style.overflowY = 'hidden';"+ " document.documentElement.style.overflowY = 'hidden';"+ " };"+ ""+ " rzdApp.unifiedModal.openOnMessage = function _modalHandler(event) {"+ " /*Empty data object*/"+ " var data = {type: '', data: ''};"+ ""+ " /*window emitting the message*/"+ " var iframeWindow = null;"+ ""+ " /*If current event is holding data*/"+ " if (event.data) {"+ " data = event.data;"+ " }"+ ""+ " /*Or if the original one is holding data*/"+ " if (event.originalEvent && event.originalEvent.data) {"+ " data = event.originalEvent.data;"+ " }"+ ""+ " /*Only listen to message emitted by the click on _booking_booknow*/"+ " if (typeof data === 'undefined' || typeof data.type === 'undefined') {"+ " return;"+ " }"+ ""+ " if (['rezdy_open_in_modal', 'rezdy_loading', 'RezdyScrollToTop', 'rezdy_cleanup_modal'].indexOf(data.type) === -1) {"+ " return;"+ " }"+ ""+ " if (data.type === 'rezdy_cleanup_modal') {"+ " rzdApp.unifiedModal.cleanupHandler();"+ " }"+ ""+ ""+ " if (data.type === 'rezdy_loading'|| data.type === 'rezdy_open_in_modal') {"+ " if (!document.querySelector('#rzd-modal')) {"+ " rzdApp.unifiedModal._generateModal();"+ " }"+ " }"+ ""+ " if (data && typeof data.data !== 'undefined' && ((typeof data.data === 'string' && data.data.length) || (typeof data.data === 'object' && Object.keys(data.data).length) || data.url.length)) {"+ " /*Load the iframe on the checkout page.*/"+ " var iframe = document.createElement('iframe');"+ " iframe.className = 'external_rezdy rezdy';"+ " /*Resize the iframe once loaded*/"+ " iframe.onload = function () {"+ " /*trigger scrolling to top whenever the iframe inside the modal is loaded*/"+ " document.querySelector('.rzd-modal').scrollTop = 0;"+ " try {"+ " iFrameResize("+ " {"+ " checkOrigin: false,"+ " log: false,"+ " enablePublicMethods: false,"+ " resizedCallback: function(iframe) {"+ " var modalLoader = document.querySelector('.rzd-modal__loader');"+ " if (modalLoader) {"+ " modalLoader.remove();"+ " }"+ " iframe.iframe.contentWindow.postMessage('MODAL_OPENED', '*');"+ " }"+ " },"+ " iframe"+ " );"+ " } catch (e) {"+ " /** iFrameResize throwing an error might be because existing outdated resizer is on the page */"+ " rzdApp.shutdown();"+ " window.location.href = data.url;"+ " }"+ " document.querySelector('.rzd-modal__inner').style.visibility = 'visible';"+ " };"+ ""+ " iframe.style.width = '100%';"+ " iframe.style.border = 'none';"+ " iframe.style.height = document.body.getBoundingClientRect().height / 1.7 + 'px';"+ ""+ " var modalContent = document.querySelector('.rzd-modal__content');"+ " modalContent.append(iframe);"+ " iframe.src = data.url;"+ ""+ " /*Release the lock when the content is shown to the user.*/"+ " rzdApp.unifiedModal.releaseTheLock();"+ " }"+ " };"+ ""+ " rzdApp.unifiedModal.simpleModalHandler = function _simpleModalHandler(event) {"+ " if (event.target && event.target.matches('.rezdy-modal')) {"+ " var url = event.target.href;"+ " url += url.indexOf('?') !== -1 ? '&iframe=true' : '?iframe=true';"+ ""+ " event.preventDefault();"+ " event.stopPropagation();"+ " event.data = {url: url, data: '', type: 'rezdy_open_in_modal'};"+ " rzdApp.unifiedModal.openOnMessage(event);"+ " }"+ " };"+ ""+ " rzdApp.unifiedModal.escapeHandler = function _escapeHandler (event) {"+ " if (event.defaultPrevented) {"+ " return;"+ " }"+ ""+ " var handled = false;"+ " if (event.key !== undefined) {"+ " if (event.key === 'Escape') {"+ " rzdApp.unifiedModal.cleanupHandler();"+ " handled = true;"+ " }"+ ""+ " } else if (event.keyCode !== undefined) {"+ " if (event.keyCode === 27) {"+ " rzdApp.unifiedModal.cleanupHandler();"+ " handled = true;"+ " }"+ " }"+ ""+ " if (handled) {"+ " event.preventDefault();"+ " }"+ " };"+ ""+ " rzdApp.unifiedModal.slickCloseHandler = function _slickCloseHandler(event) {"+ " var closeButtonSelector = '.rzd-modal__close';"+ " if (typeof event.data === 'string' && event.data === 'SHOW_MODAL_CLOSE') {"+ " /*need to show for those who arent using the new rezdy header*/"+ " if (document.querySelector(closeButtonSelector)) {"+ " document.querySelector(closeButtonSelector).style.display = 'block';"+ " }"+ " } else if (typeof event.data === 'string' && event.data === 'HIDE_MODAL_CLOSE') {"+ " /*need to hide for those who arent using the new rezdy header and are having"+ " the slick box modal close button overlapping issue*/"+ " if (document.querySelector(closeButtonSelector)) {"+ " document.querySelector(closeButtonSelector).style.display = 'none';"+ " }"+ " }"+ " };"+ ""+ " rzdApp.unifiedModal.shutdown = function _shutdown() {"+ " rzdApp.unifiedModal.cleanupHandler();"+ " rzdApp.unifiedModal.releaseTheLock();"+ " window.removeEventListener('message', rzdApp.unifiedModal.slickCloseHandler);"+ " window.removeEventListener('keydown', rzdApp.unifiedModal.escapeHandler);"+ " document.removeEventListener('click', rzdApp.unifiedModal.simpleModalHandler);"+ " window.removeEventListener('message', rzdApp.unifiedModal.openOnMessage);"+ " };"+ ""+ " rzdApp.unifiedModal.init();"; break; } if (script.innerText.length) { document.body.append(script); return true; } return false; }; rzdApp.FeatureDetector.init = function _init() { rzdApp.FeatureDetector.supportedFeatures.filter(function(feature) { return rzdApp.FeatureDetector.detectFeature(feature); }); }; //Dedicated endpoint to deal with async loaded booking button (monthly calendar) rzdApp.healthCheck = function _healthCheck(event) { if (event.data && event.data === 'rzd_health_check' && !document.querySelector('.rzd-modal') && window.location.protocol === 'https:' && !rzdApp.hasError) { rzdApp.notifyIframes('rzd_plugin_js_loaded'); } }; rzdApp.initPluginJS = function _initPluginJs() { if (document.querySelector('#rzd-polyfill')) { return; } var polyfillScript = document.createElement('script'); polyfillScript.id = 'rzd-polyfill'; polyfillScript.defer = true; polyfillScript.addEventListener('load', function(){ rzdApp.FeatureDetector.init(); }); polyfillScript.src = 'https://cdn.polyfill.io/v2/polyfill.min.js'; //BAD DOM if (document.readyState === 'complete' && !document.body) { var body = document.createElement("body"); document.documentElement.appendChild(body); } document.body.appendChild(polyfillScript); window.addEventListener('message', rzdApp.healthCheck); window.addEventListener('message', function(event) { if (event && event.data && event.data === 'rzd_app_shutdown') { rzdApp.hasError = true; } }); window.iFrameResize = rzdApp.iFrameResize; window.addEventListener('error', function() { rzdApp.hasError = true; }); //hasError is reactive, it will trigger the shutdown has soon has it's set to true. var internalValue = false; Object.defineProperty(rzdApp, 'hasError', { configurable: true, enumerable: true, writeable: true, get: function() { return internalValue; }, set: function (value) { internalValue = value; if (value) { rzdApp.shutdown(); } } }); rzdApp.hasError = false; //Disable the modal for safari (until we find a reliable way to check 3rd party cookies being allowed). if ( rzdApp.FeatureDetector.isSafari) { // Google Analytics 4 has built in functionality that will decorate any new link that is "clicked" // Its not loaded immediately even when GA itself is loaded and there is no event that // tells us that it is loaded. This interval checks for it every 100ms until it finds it const gaCheck = setInterval(function() { // Create a fake link which GA will decorate with a linker param for us // Then save the URL const rezdyIframe = document.querySelector('iframe.rezdy'); const rezdyIframeSrc = rezdyIframe.getAttribute('src'); const tempAnchorEl = document.createElement("a"); tempAnchorEl.setAttribute("type", "hidden"); tempAnchorEl.setAttribute("href", rezdyIframeSrc); tempAnchorEl.setAttribute("onclick", "event.preventDefault(); return false"); document.body.appendChild(tempAnchorEl); tempAnchorEl.dispatchEvent(new MouseEvent("mousedown", { bubbles: true })); const urlWithLinker = tempAnchorEl.href; tempAnchorEl.remove(); window.gaDecoratedWidgetUrl = urlWithLinker; const testUrl = new URL(urlWithLinker); if(testUrl.searchParams.has('_gl')) { // The link is decorated, now stop the interval clearInterval(gaCheck); }; }, 100); // checking every 100 milliseconds rzdApp.hasError = true; } }; rzdApp.notifyIframes = function _notifyIframes(message) { var rzdIframes = document.querySelectorAll('iframe.rezdy, iframe[src*="rezdy.com"]'); if (!rzdIframes.length) { return; } [].forEach.call(rzdIframes, function(iframe) { iframe.contentWindow.postMessage(message, '*'); }); }; //If something goes wrong, try to provide the feature //Without using modal rzdApp.shutdown = function _gracefullyFail(event) { rzdApp.notifyIframes({type: 'rzd_js_errors'}); if (typeof rzdApp.healthCheck === 'function') { window.removeEventListener('message', rzdApp.healthCheck); } if (typeof rzdApp.unifiedModal !== 'undefined') { rzdApp.unifiedModal.shutdown(); } if (typeof rzdApp.embeddedCart !== 'undefined') { rzdApp.embeddedCart.shutdown(); } }; if (!document.querySelector('#rzd-polyfill')) { if (document.readyState === 'loading') { document.removeEventListener('DOMContentLoaded', rzdApp.initPluginJS); document.addEventListener('DOMContentLoaded', rzdApp.initPluginJS); } else { rzdApp.initPluginJS(); } } window.addEventListener('message', function(event) { // Handle other events if ( typeof event.data !== "object" || typeof event.data.type !== "string" || event.data.type !== "navigateParent" ) { return; } // Naviage to the decorated link for the widget that we saved previously window.location = window.gaDecoratedWidgetUrl; });