Skip to content

michaeldscherr/js-plugin-youtube-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

js youtube api plugin

take an element and transform into a youtube iframe

installation

add right before closing body tag

<body>
  <script src="/path/to/plugin/youtube-api.min.js"></script>
</body>

usage

plugin will automatically be called on

document.querySelectorAll('[data-yt-client="true"])

each element must also have the [data-yt-videoid] with a valid youtube video id

html

<!-- called automatically -->
<div data-yt-client="true" data-yt-videoid="[VIDEO_ID]"></div>
<!-- have to invoke plugin manually -->
<div class="some-class" data-yt-videoid="[VIDEO_ID]"></div>

javascript

var elems = document.querySelectorAll('.some-class');
window.youtubeClient(elems, {
  onAPIReady: () => {},
  onStateChange: () => {},
  playerVars: {
    autoplay: 0,
    controls: 0,
    loop: 1,
    modestbranding: 1,
    showinfo: 0,
    wmode: 'opaque'
}
});

options

option description default
onAPIReady _called once on youtube api ready () => {}
onStateChange _called on every youtube api state change () => {}
playerVars playerVars to pass into youtube api (see below)

full default options

{
  onAPIReady: () => {},
  onStateChange: () => {},
  playerVars: {
    autoplay: 0,
    controls: 0,
    loop: 1,
    modestbranding: 1,
    showinfo: 0,
    wmode: 'opaque'
  }
}

About

take an element and transform into a youtube iframe

Resources

Stars

Watchers

Forks

Packages

No packages published