From 33e78d393411c86cfac8120ec0a0b5470aec2d43 Mon Sep 17 00:00:00 2001 From: heff Date: Thu, 2 Apr 2020 22:35:58 -0700 Subject: [PATCH] Fixed a build bug --- index.js | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index 81d70c3..fb53369 100644 --- a/index.js +++ b/index.js @@ -60,6 +60,27 @@ function getIdFromURL(url) { return (match && match[1]) ? match[1] : url; } +// Handle multiple players with one YT API load +let ytReady = false; +let ytReadyQueue = []; + +function onYTReady(callback) { + if (ytReady) { + callback(); + } else { + ytReadyQueue.push(callback); + } +} + +function handleYoutubeAPILoad() { + ytReady = true; + ytReadyQueue.forEach((callback) => { + callback(); + }); + ytReadyQueue = []; +} + + class YoutubeVideoElement extends HTMLElement { constructor() { super(); @@ -74,24 +95,6 @@ class YoutubeVideoElement extends HTMLElement { } } - // Handle multiple players with one YT API load - static ytReady = false; - static ytReadyQueue = []; - static onYTReady = function(callback) { - if (this.ytReady) { - callback(); - } else { - this.ytReadyQueue.push(callback); - } - }; - static handleYoutubeAPILoad() { - this.ytReady = true; - this.ytReadyQueue.forEach((callback) => { - callback(); - }); - this.ytReadyQueue = []; - } - load() { // Destroy previous videos this.ytPlayer = null; @@ -113,7 +116,7 @@ class YoutubeVideoElement extends HTMLElement { this.shadowRoot.querySelector('#iframeContainer').appendChild(iframeTemplate.content.cloneNode(true)); const iframe = this.shadowRoot.querySelector('iframe'); - YoutubeVideoElement.onYTReady(()=>{ + onYTReady(() => { const onPlayerReady = (event) => { this.dispatchEvent(new Event('volumechange')); @@ -257,7 +260,7 @@ function loadYoutubeAPI() { const firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(YouTubeScriptTag, firstScriptTag); - window.onYouTubeIframeAPIReady = YoutubeVideoElement.handleYoutubeAPILoad.bind(YoutubeVideoElement); + window.onYouTubeIframeAPIReady = handleYoutubeAPILoad; } if (window.customElements.get('youtube-video') || window.YoutubeVideoElement) {