From a870383f2968dffca1d48cfda1e32595d46087f5 Mon Sep 17 00:00:00 2001 From: Justin Ribeiro Date: Mon, 4 Oct 2021 21:45:12 -0700 Subject: [PATCH] feat: add liteYoutubeIframeLoaded event for iframe load (#39) --- README.md | 9 +++++++++ demo/index.html | 52 ++++++++++++++++++++++++++++++++++++++++++++++++- lite-youtube.ts | 9 +++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ac72a6..9840097 100644 --- a/README.md +++ b/README.md @@ -124,3 +124,12 @@ flexibility. | `nocookie` | Use youtube-nocookie.com as iframe embed uri | `false` | | `autoload` | Use Intersection Observer to load iframe when scrolled into view | `false` | | `params` | Set YouTube query parameters | `` | + +## Events + +The web component allows certain attributes to be give a little additional +flexibility. + +| Event Name | Description | Returns | +| -------------- | ---------------------------------------------------------------- | ------- | +| `liteYoutubeIframeLoaded` | When the iframe is loaded, allowing us of JS API | `detail: { videoId: this.videoId }` | diff --git a/demo/index.html b/demo/index.html index 26896d3..abe1cab 100644 --- a/demo/index.html +++ b/demo/index.html @@ -104,6 +104,7 @@

YouTube QueryParams

<lite-youtube videoid="guJLfqTFfIw" params="controls=0&enablejsapi=1"></lite-youtube> @@ -124,6 +125,55 @@

YouTube QueryParams

+ + diff --git a/lite-youtube.ts b/lite-youtube.ts index de9ef58..520c5b9 100644 --- a/lite-youtube.ts +++ b/lite-youtube.ts @@ -274,6 +274,15 @@ export class LiteYTEmbed extends HTMLElement { this.domRefFrame.insertAdjacentHTML('beforeend', iframeHTML); this.domRefFrame.classList.add('lyt-activated'); this.iframeLoaded = true; + this.dispatchEvent( + new CustomEvent('liteYoutubeIframeLoaded', { + detail: { + videoId: this.videoId, + }, + bubbles: true, + cancelable: true, + }), + ); } }