Sha256: c2c4dffe0954449575657074f0566e443a413e25a1ee7b5c83de66b48a083899
Contents?: true
Size: 1.1 KB
Versions: 17
Compression:
Stored size: 1.1 KB
Contents
const ytEmbedParent = document.getElementById('yt-embed'); const videoId = ytEmbedParent.dataset.video; //<iframe width="560" height="315" src="https://www.youtube.com/embed/LUCrx9chw-c" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> function setAttributes(el, arg, argVal) { const argumentIsString = typeof arg == 'string'; if ( argumentIsString ) { el.setAttribute(arg, argVal) } else { for (let i = 0, len = arg.length; i < len; i++) { el.setAttribute(arg[i], argVal[i]) } } return el; } function ytEmbed() { const iframe = document.createElement('iframe'); setAttributes(iframe, ['width', 'height', 'frameborder', 'allow', 'allowfullscreen'], ['560', '315', '0', 'accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture', '']); ytEmbedParent.appendChild(iframe); setAttributes(iframe, 'src', 'https://www.youtube.com/embed/' + videoId + '?showinfo=0&rel=0'); iframe.onload = () => { ytEmbedParent.removeChild(ytEmbedParent.querySelector('.yt-embed')); } } export default ytEmbed;
Version data entries
17 entries across 17 versions & 1 rubygems