Sha256: 91f2f7e0e53b439515ed843a8fe1bef70e22e1834ef6f3af007e567d3bfc7e05

Contents?: true

Size: 1.14 KB

Versions: 146

Compression:

Stored size: 1.14 KB

Contents

const YT_EMBED_PARENT = document.getElementById('yt-embed');
const YT_EMBED_PARENT_VIDEO_ID = YT_EMBED_PARENT.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', '']);
  YT_EMBED_PARENT.appendChild(iframe);
  setAttributes(iframe, 'src', 'https://www.youtube.com/embed/' + YT_EMBED_PARENT_VIDEO_ID + '?showinfo=0&rel=0');
  iframe.onload = () => {
    YT_EMBED_PARENT.removeChild(YT_EMBED_PARENT.querySelector('.yt-embed'));
  }

}

export default ytEmbed;

Version data entries

146 entries across 146 versions & 3 rubygems

Version Path
kcc-gem-theme-1.96.1 assets/js/src/ytEmbed.js
kcc-gem-theme-1.96.0 assets/js/src/ytEmbed.js
kcc-gem-theme-1.95.0 assets/js/src/ytEmbed.js
kcc-gem-theme-1.94.1 assets/js/src/ytEmbed.js
kcc-gem-theme-1.94.0 assets/js/src/ytEmbed.js
kcc-gem-theme-1.93.0 assets/js/src/ytEmbed.js
kcc-gem-theme-1.92.0 assets/js/src/ytEmbed.js
kcc-gem-theme-1.91.0 assets/js/src/ytEmbed.js
kcc-gem-theme-1.90.0 assets/js/src/ytEmbed.js
kcc-gem-theme-1.89.0 assets/js/src/ytEmbed.js
kcc-gem-theme-1.88.0 assets/js/src/ytEmbed.js
kcc-gem-theme-1.87.0 assets/js/src/ytEmbed.js
kcc-gem-theme-1.86.1 assets/js/src/ytEmbed.js
kcc-gem-theme-1.86.0 assets/js/src/ytEmbed.js
kcc-gem-theme-core-0.0.3 assets/js/src/ytEmbed.js
kcc-gem-theme-core-0.0.2 assets/js/src/ytEmbed.js
kcc-gem-theme-core-0.0.1 assets/js/src/ytEmbed.js
kcc-gem-theme-2.14.1 assets/js/src/ytEmbed.js
kcc-gem-theme-2.14.0 assets/js/src/ytEmbed.js
kcc-gem-theme-2.13.0 assets/js/src/ytEmbed.js