1/* Keep autoplay; defer lower homepage videos until close to the viewport. */ 2(function () { 3 'use strict'; 4 function init() { 5 var videos = Array.prototype.slice.call(document.querySelectorAll('video[data-hog-deferred-video]')); 6 if (!videos.length) return; 7 function play(video) { 8 var promise = video.play(); 9 if (promise && promise.catch) promise.catch(function () {}); 10 } 11 function load(video) { 12 if (video.dataset.hogVideoLoaded) return; 13 video.dataset.hogVideoLoaded = '1'; 14 video.src = video.dataset.hogVideoSrc; 15 video.muted = true; 16 video.load(); 17 } 18 function visible(video) { 19 var rect = video.getBoundingClientRect(); 20 return rect.width > 0 && rect.height > 0 && rect.bottom > 0 && rect.top < window.innerHeight; 21 } 22 function sync(video) { 23 if (!video.dataset.hogVideoLoaded) return; 24 if (!document.hidden && visible(video)) play(video); 25 else video.pause(); 26 } 27 if ('IntersectionObserver' in window) { 28 var nearby = new IntersectionObserver(function (entries) { 29 entries.forEach(function (entry) { 30 if (!entry.isIntersecting) return; 31 load(entry.target); 32 sync(entry.target); 33 nearby.unobserve(entry.target); 34 }); 35 }, { rootMargin: '200px 0px' }); 36 var onscreen = new IntersectionObserver(function (entries) { 37 entries.forEach(function (entry) { sync(entry.target); }); 38 }, { threshold: 0.01 }); 39 videos.forEach(function (video) { 40 video.addEventListener('canplay', function () { sync(video); }); 41 nearby.observe(video); 42 onscreen.observe(video); 43 }); 44 } else { 45 videos.forEach(function (video) { load(video); video.autoplay = true; play(video); }); 46 } 47 document.addEventListener('visibilitychange', function () { 48 videos.forEach(sync); 49 }); 50 } 51 if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init); 52 else init(); 53}());
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.