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, + }), + ); } }