Commit 9cd76cbe authored by alejandro cabarcos's avatar alejandro cabarcos Committed by Omar Mohamad - El Hassan Lopesino
Browse files

Issue #3293721: Dispatch event to allow YouTube Videos to be played with a...

Issue #3293721: Dispatch event to allow YouTube Videos to be played with a single click (Oembed lazyload)
parent 70b8a0ae
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -190,6 +190,17 @@ YoutubeCookies.prototype.removeFakeThumbnailAndPlay = function (iframeWrapper) {
  iframeWrapper.querySelector('[data-yc-oembed-button]').click();
};

/**
 * Dispatch event to allow other modules to add
 * their specific behaviours when the thumbnail
 * button is clicked.
 */
YoutubeCookies.prototype.eventDispatch = function(button) {
  var iframeWrapper = button.currentTarget.parentNode;
  const event = new Event('youtube-cookies-thumbnail-click');
  iframeWrapper.querySelector('iframe').dispatchEvent(event);
};

/**
 * Remove the popup.
 */
@@ -449,6 +460,7 @@ YoutubeCookies.prototype.processYoutubeIframes = function (container) {
              button.style.display = 'none';
              var newButton = iframe.parentNode.querySelector('button:not([data-yc-oembed-button])');
              newButton.addEventListener('click', this.onThumbnailClick.bind(this));
              button.addEventListener('click', this.eventDispatch.bind(this));
              newButton.setAttribute('data-yc-fake-button', 1);
            }
          }