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-slim-0.0.1 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.84.96 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.84.95 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.83.95 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.83.94 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.83.93 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.82.93 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.81.93 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.81.92 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.80.92 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.79.92 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.79.91 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.79.90 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.78.90 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.78.89 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.78.88 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.78.87 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.78.86 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.77.86 assets/js/theme/src/ytEmbed.js
kcc-gem-theme-1.77.85 assets/js/theme/src/ytEmbed.js