Loading tour...
'; // Set the iframe src to load the content const originalSrc = iframe.getAttribute('src'); iframe.src = originalSrc; // Add autoplay parameter if it's a music tour if (originalSrc.includes('music') || originalSrc.includes('audio')) { iframe.src = originalSrc + (originalSrc.includes('?') ? '&' : '?') + 'autoplay=1'; } // Hide placeholder when iframe loads iframe.onload = function() { placeholder.style.display = 'none'; // Set this as active iframe activeIframe = iframe; // Try to autoplay if it's a music tour if (originalSrc.includes('music') || originalSrc.includes('audio')) { try { const iframeWindow = iframe.contentWindow; if (iframeWindow) { iframeWindow.postMessage('playMedia', '*'); } } catch (e) { console.log('Cannot autoplay iframe content'); } } }; }); // Also allow clicking on the iframe container const container = iframe.parentElement; container.addEventListener('click', function(e) { if (e.target === container) { placeholder.click(); } }); } // Initialize all iframes iframes.forEach((iframe, index) => { // Set up click-to-load functionality setupIframeClickLoad(iframe, iframePlaceholders[index], index); // Handle iframe visibility changes const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (!entry.isIntersecting && activeIframe === iframe) { // If iframe goes out of view, stop the media stopAllIframeMedia(); } }); }, { threshold: 0.1 }); observer.observe(iframe); }); // Stop media when switching slides featuredPrevBtn.addEventListener('click', stopAllIframeMedia); featuredNextBtn.addEventListener('click', stopAllIframeMedia); // Stop media when clicking on dots const featuredDots = document.querySelectorAll('.featured-dot'); featuredDots.forEach(dot => { dot.addEventListener('click', stopAllIframeMedia); }); // Stop media when page loses focus document.addEventListener('visibilitychange', function() { if (document.hidden) { stopAllIframeMedia(); } }); // Stop media when user leaves the page window.addEventListener('beforeunload', stopAllIframeMedia); // Listen for messages from iframes (if they support it) window.addEventListener('message', function(event) { if (event.data === 'iframeUnloaded' || event.data === 'mediaStopped') { activeIframe = null; } }); });