sass/themes/cr/2019/components/copy-video/js/copy-video.js
function onYouTubePlayerAPIReady() {
  // Loop through each iframe video on the page
  jQuery( "iframe.copy-video__video").each(function (index) {

    // Create IDs dynamically
    var iframeID = "js-copy-video-" + index;
    var buttonID = "js-copy-video-" + index + "__button";

    // Set IDs
    jQuery(this).attr('id', iframeID);
    jQuery(this).next('button.copy-video__button').attr('id', buttonID);

    // Associate video player with button via index
    players[buttonID] = { player: null, }

    // Set-up a player object for each video
    players[buttonID].player =  new YT.Player(iframeID, {
      events: { 'onReady': onPlayerReady }
    });
  });
}
function onYouTubePlayerAPIReady() {
  // Loop through each iframe video on the page
  jQuery( "iframe.copy-video__video").each(function (index) {

    // Create IDs dynamically
    var iframeID = "js-copy-video-" + index;
    var buttonID = "js-copy-video-" + index + "__button";

    // Set IDs
    jQuery(this).attr('id', iframeID);
    jQuery(this).next('button.copy-video__button').attr('id', buttonID);

    // Associate video player with button via index
    players[buttonID] = { player: null, }

    // Set-up a player object for each video
    players[buttonID].player =  new YT.Player(iframeID, {
      events: { 'onReady': onPlayerReady }
    });
  });
}
function onYouTubePlayerAPIReady ( ) { // Loop through each iframe video on the page jQuery ( "iframe.copy-video__video" ) . each ( function ( index ) { // Create IDs dynamically var iframeID = "js-copy-video-" + index ; var buttonID = "js-copy-video-" + index + "__button" ; // Set IDs jQuery ( this ) . attr ( 'id' , iframeID ) ; jQuery ( this ) . next ( 'button.copy-video__button' ) . attr ( 'id' , buttonID ) ; // Associate video player with button via index players [ buttonID ] = { player : null , } // Set-up a player object for each video players [ buttonID ] . player = new YT . Player ( iframeID , { events : { 'onReady' : onPlayerReady } } ) ; } ) ; }
Only called on successful YT API load
Only called on successful YT API load