// language=JavaScript (function () { var accountUuid = 'a07ce3f1-1623-42b1-8c55-fe05993cd4d7'; // Optional GA ID anf BU ID var buUuid = ''; var gaId = ''; var vsInjectUrlParams = ''; console.log('IFRAME_PARAMS:', vsInjectUrlParams); if (vsInjectUrlParams.trim() !== '') { vsInjectUrlParams = '&' + vsInjectUrlParams; } if (!accountUuid) { console.error('Manjka ACCOUNT UUID:', accountUuid); } // Get the first GA ID from the window.gaData object var gaKeys = Object.keys(window.gaData || {}); var gaActualId = gaId || (gaKeys.length ? gaKeys[0] : null) || null; console.log('PREBRAN GA ID:', gaActualId); // Get the value of the 'vehicle' query parameter var urlParams = new URLSearchParams(window.location.search); var vehicle = urlParams.get('vehicle'); console.log('IFRAME_PARAMS:', urlParams); // Create a new iframe element var iframe = document.createElement('iframe'); var vsUri = vehicle ? `v2/virtual-salon/vehicles/${vehicle}` : 'v2/virtual-salon/vehicles'; // Set attributes for the iframe // accountUuid/bu/ga are already added explicitly above - if the host page's own // current URL happens to also carry any of them (e.g. a visitor is on // ?vehicle=...&bu=... because they followed a shared/carousel link), leaving them // in urlParams here would duplicate that query key in the iframe src (bu=&bu=...). // vue-router parses a duplicated key into an array, and the SPA's own listing // fetch forwards that array straight through - the backend's // BusinessUnit::where('uuid', $arrayValue)->firstOrFail() then never matches, // producing a 404 the SPA renders as "0 vehicles" the next time it navigates back // to the listing from a vehicle detail page reached via such a link. urlParams.delete('accountUuid'); urlParams.delete('bu'); urlParams.delete('ga'); var allOtherParams = urlParams.toString(); allOtherParams = allOtherParams ? '&' + allOtherParams : ''; iframe.src = `https://api.briefd.io/hr/public/${vsUri}?accountUuid=${accountUuid}&bu=${buUuid}&ga=${gaActualId}${vsInjectUrlParams}${allOtherParams}`; iframe.frameBorder = 'no'; iframe.style.width = '100%'; iframe.scrolling = 'no'; iframe.allowFullscreen = true; iframe.id = 'autobrief-resizer'; // Add the iframe to the container element var targetContainer = document.currentScript.dataset.target || false; if(targetContainer){ var container = document.querySelector(targetContainer); if(!container){ console.error('Manjka VS TARGET CONTAINER:', targetContainer); } container.appendChild(iframe); } else { document.currentScript.parentNode.insertBefore(iframe, document.currentScript); } // Add an event listener for the 'message' event window.addEventListener('message', function (e) { if (e.data.id === 'autobrief.scroll') { var iframe = document.querySelector("#autobrief-resizer"); var iframeToTopOffset = window.pageYOffset + iframe.getBoundingClientRect().top; console.log('scrollTo', e.data, iframeToTopOffset); var scrollData = e.data; window.scrollTo(scrollData.x, iframeToTopOffset + scrollData.y); } else if (e.data.id === 'autobrief.resizer') { var iframe = document.querySelector("#autobrief-resizer"); var message = e.data; iframe.style.height = message.height + 'px'; } else if(e.data.id === 'autobrief.vehicle'){ // Update the 'vehicle' query parameter based on the received message var urlParams = new URLSearchParams(window.location.search); var message = e.data; urlParams.set('vehicle', message.vehicle); var newUrl = window.location.pathname + '?' + urlParams.toString(); window.history.replaceState(null, null, newUrl); } }, false); })();