var ga = window.ga || false function embedIframe(){ var tag = 'phx-ui-be-5-1'; var el = document.getElementById( 'phx-ui-be-5-1' ); // Create Iframe if (el instanceof HTMLElement === true) { var iframe = document.createElement( 'iframe' ); iframe.id = 'phx-ui-be'; iframe.src = 'https://bridgemill-athletic-club.book-v2.teeitup.golf' iframe.style.width = '100%'; iframe.style.height = '100%'; iframe.scrolling = 'yes'; // pass along query string atts try { var beUrlObj = new URL(iframe.src); var elementAtts = el.attributes; var searchQParams = new URLSearchParams(window.location.search); var beUrlParams = ['beUsername', 'beGolfIdToken', 'beStateKey']; if (beUrlParams.every(function (p) { return searchQParams.has(p); })) { beUrlObj.pathname = '/login-with-golfid'; beUrlParams.forEach(function (p) { beUrlObj.searchParams.append(p, searchQParams.get(p)); searchQParams.delete(p); }); var newQSearchStr = searchQParams.toString() ? '?' + searchQParams.toString() : ''; history.replaceState(null, '', window.location.href.replace(window.location.search, newQSearchStr)); } var linkerParam = getLinkerParam('UA-103204346-1'); if (linkerParam !== undefined) { linkerParam = linkerParam.split('=', 2); beUrlObj.searchParams.append(linkerParam[0], linkerParam[1]); } if (el.hasAttributes() && typeof elementAtts === 'object') { var dataRegExp = new RegExp('^data-'); for ( var i = 0; i < elementAtts.length; ++i) { if (dataRegExp.test( elementAtts[i].name ) === true) { beUrlObj.searchParams.append(elementAtts[i].name.replace(dataRegExp, ''), elementAtts[i].value); } } } var newBeSrc = beUrlObj.toString(); if (iframe.src !== newBeSrc) { iframe.src = newBeSrc; } } catch (error) { console.log(error); } window.addEventListener( 'message', function (message) { var data = message.data || {}; if (data.action === 'updateHeight') { iframe.style.height = data.height + 'px'; el.style.height = data.height + 'px'; } else if (data.action === 'scrollToTop') { var rectA = document.getElementById( 'phx-ui-be' ).getBoundingClientRect(); var rectB = document.body.getBoundingClientRect(); // the offset accounts for the nav bar on the site used for testing - you may need to change this var offset = ( rectA.top - rectB.top ); window.scrollTo( 0, offset - 32 ); } else if (data.action === 'redirect' && data.location) { window.location = data.location; } else { console.log( 'PHX-UI-BE :: unknown action: ', event.data.action ); } }); iframe.addEventListener( 'load', function () { iframe.contentWindow.postMessage( { action: 'iframeSaysHi', location: window.location.href }, '*' ); }); el.appendChild( iframe ); } else { console.error( tag + ': could not find the required container element with id "phx-ui-be-5-1"' ); } } /* google analytics cross-domain stuff */ function getLinkerParam(c){ if( ga && ga.getAll){ for(var b = ga.getAll(), a = 0; a < b.length; a++){ if(b[a].get('trackingId') === c){ return b[a].get('linkerParam'); } } } return undefined; }; embedIframe();