ProjectFirewatch/static/js/youtube.js

1 line
909 B
JavaScript

function labnolIframe(e){var t=document.createElement("iframe");t.setAttribute("src","https://www.youtube.com/embed/"+e.dataset.id+"?autoplay=1"),t.setAttribute("frameborder","0"),t.setAttribute("allowfullscreen","1"),t.setAttribute("allow","accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"),e.parentNode.replaceChild(t,e)}function initYouTubeVideos(){for(var e=document.querySelectorAll(".youtube-player"),t=0;t<e.length;t+=1){var a=e[t].dataset.id,r=document.createElement("div");r.setAttribute("data-id",a);var i=document.createElement("img");i.src="https://i.ytimg.com/vi/ID/maxresdefault.jpg".replace("ID",a),r.appendChild(i);i.alt="Youtube Thumbnail";i.loading="eager";var d=document.createElement("div");d.setAttribute("class","play"),r.appendChild(d),r.onclick=function(){labnolIframe(this)},e[t].appendChild(r)}}document.addEventListener("DOMContentLoaded",initYouTubeVideos);