youtubemodal/index.js
function YouTubeModal(config) {
  this.config = config;
  this.parentElement = document.querySelector(this.config.parentSelector);
  this.closeEventListener_ = this.setActive_.bind(this, false);
  this.popstateListener_ = this.onHistoryChange_.bind(this);
  this.el_ = null;
  this.closeEl_ = null;
  this.attributionEl_ = null;
  this.initDom_();
  this.lastActiveVideoId_ = null;
  this.scrollY = 0;

  this.delegatedListener_ = function(targetEl) {
    var data = 'data-' + this.config.className + '-video-id';
    var videoId = targetEl.getAttribute(data);
    var startDataAttribute = 'data-' + this.config.className + '-video-start-seconds';
    var startTime = +targetEl.getAttribute(startDataAttribute);
    var attributionAttribute = 'data-' + this.config.className + '-attribution';
    var attribution = targetEl.getAttribute(attributionAttribute);
    if (videoId) {
      this.play(videoId, true /* opt_updateState */, startTime, attribution);
    }
  }.bind(this);

  // Loads YouTube iframe API.
  events.addDelegatedListener(document, 'click', this.delegatedListener_);

  // Only add the script tag if it doesn't exist
  var scriptTag =
    document.querySelector('script[src="https://www.youtube.com/iframe_api"]');
  if (!scriptTag) {
    var tag = document.createElement('script');
    tag.setAttribute('src', 'https://www.youtube.com/iframe_api');
    this.parentElement.appendChild(tag);
  }
}
function YouTubeModal(config) {
  this.config = config;
  this.parentElement = document.querySelector(this.config.parentSelector);
  this.closeEventListener_ = this.setActive_.bind(this, false);
  this.popstateListener_ = this.onHistoryChange_.bind(this);
  this.el_ = null;
  this.closeEl_ = null;
  this.attributionEl_ = null;
  this.initDom_();
  this.lastActiveVideoId_ = null;
  this.scrollY = 0;

  this.delegatedListener_ = function(targetEl) {
    var data = 'data-' + this.config.className + '-video-id';
    var videoId = targetEl.getAttribute(data);
    var startDataAttribute = 'data-' + this.config.className + '-video-start-seconds';
    var startTime = +targetEl.getAttribute(startDataAttribute);
    var attributionAttribute = 'data-' + this.config.className + '-attribution';
    var attribution = targetEl.getAttribute(attributionAttribute);
    if (videoId) {
      this.play(videoId, true /* opt_updateState */, startTime, attribution);
    }
  }.bind(this);

  // Loads YouTube iframe API.
  events.addDelegatedListener(document, 'click', this.delegatedListener_);

  // Only add the script tag if it doesn't exist
  var scriptTag =
    document.querySelector('script[src="https://www.youtube.com/iframe_api"]');
  if (!scriptTag) {
    var tag = document.createElement('script');
    tag.setAttribute('src', 'https://www.youtube.com/iframe_api');
    this.parentElement.appendChild(tag);
  }
}
function YouTubeModal ( config ) { this . config = config ; this . parentElement = document . querySelector ( this . config . parentSelector ) ; this . closeEventListener_ = this . setActive_ . bind ( this , false ) ; this . popstateListener_ = this . onHistoryChange_ . bind ( this ) ; this . el_ = null ; this . closeEl_ = null ; this . attributionEl_ = null ; this . initDom_ ( ) ; this . lastActiveVideoId_ = null ; this . scrollY = 0 ; this . delegatedListener_ = function ( targetEl ) { var data = 'data-' + this . config . className + '-video-id' ; var videoId = targetEl . getAttribute ( data ) ; var startDataAttribute = 'data-' + this . config . className + '-video-start-seconds' ; var startTime = + targetEl . getAttribute ( startDataAttribute ) ; var attributionAttribute = 'data-' + this . config . className + '-attribution' ; var attribution = targetEl . getAttribute ( attributionAttribute ) ; if ( videoId ) { this . play ( videoId , true /* opt_updateState */ , startTime , attribution ) ; } } . bind ( this ) ; // Loads YouTube iframe API. events . addDelegatedListener ( document , 'click' , this . delegatedListener_ ) ; // Only add the script tag if it doesn't exist var scriptTag = document . querySelector ( 'script[src="https://www.youtube.com/iframe_api"]' ) ; if ( ! scriptTag ) { var tag = document . createElement ( 'script' ) ; tag . setAttribute ( 'src' , 'https://www.youtube.com/iframe_api' ) ; this . parentElement . appendChild ( tag ) ; } }
Plays a YouTube video in a modal dialog.
@constructor
Plays a YouTube video in a modal dialog .