1(function () { 2 "use strict"; 3 4 var container = document.getElementById("dreamax-video-testimonial"); 5 6 if (!container) { 7 return; 8 } 9 10 var youtubeId = getYouTubeId(container.getAttribute("data-youtube-id")); 11 var isVisible = false; 12 var hasLoaded = false; 13 var embedUrl = ""; 14 15 function getYouTubeId(value) { 16 var match = null; 17 var parsedUrl = null; 18 var videoId = ""; 19 20 if (!value || value === "VIDEO_ID_HERE") { 21 return ""; 22 } 23 24 if (/^[A-Za-z0-9_-]{11}$/.test(value)) { 25 return value; 26 } 27 28 try { 29 parsedUrl = new URL(value); 30 videoId = parsedUrl.searchParams.get("v") || ""; 31 32 if (!videoId && parsedUrl.hostname.indexOf("youtu.be") !== -1) { 33 videoId = parsedUrl.pathname.replace("/", ""); 34 } 35 36 if (!videoId) { 37 match = parsedUrl.pathname.match(/\/(?:embed|shorts)\/([A-Za-z0-9_-]+)/); 38 videoId = match && match[1] ? match[1] : ""; 39 } 40 41 return /^[A-Za-z0-9_-]{11}$/.test(videoId) ? videoId : ""; 42 } catch (error) { 43 return ""; 44 } 45 } 46 47 if (!youtubeId) { 48 container.classList.add("video-testimonial-player--missing"); 49 return; 50 } 51 52 if (window.console && typeof window.console.info === "function") { 53 window.console.info("Dreamax testimonial YouTube ID:", youtubeId); 54 } 55 56 function playWhenVisible() { 57 if (!isVisible) { 58 return; 59 } 60 61 loadVideo(true); 62 } 63 64 function pauseVideo() { 65 unloadVideo(); 66 } 67 68 function loadVideo(autoplay) { 69 var iframe = null; 70 71 if (hasLoaded) { 72 return; 73 } 74 75 iframe = document.createElement("iframe"); 76 iframe.src = embedUrl + (autoplay ? "&autoplay=1" : ""); 77 iframe.title = container.getAttribute("aria-label") || "Video testimonial"; 78 iframe.allow = "autoplay; encrypted-media; picture-in-picture"; 79 iframe.allowFullscreen = true; 80 81 container.innerHTML = ""; 82 container.appendChild(iframe); 83 hasLoaded = true; 84 } 85 86 function unloadVideo() { 87 if (!hasLoaded) { 88 return; 89 } 90 91 container.innerHTML = '<div class="video-testimonial-placeholder"><i class="fa-brands fa-youtube"></i><span>Video testimonial</span></div>'; 92 hasLoaded = false; 93 } 94 95 function setupObserver() { 96 if (!("IntersectionObserver" in window)) { 97 isVisible = true; 98 playWhenVisible(); 99 return; 100 } 101 102 var observer = new IntersectionObserver(function (entries) { 103 entries.forEach(function (entry) { 104 isVisible = entry.isIntersecting && entry.intersectionRatio >= 0.45; 105 106 if (isVisible) { 107 playWhenVisible(); 108 } else { 109 pauseVideo(); 110 } 111 }); 112 }, { 113 threshold: [0, 0.45, 0.75] 114 }); 115 116 observer.observe(container); 117 } 118 119 embedUrl = "https://www.youtube.com/embed/" + youtubeId + "?mute=1&playsinline=1&rel=0&modestbranding=1&controls=1"; 120 setupObserver(); 121})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.