From 69696843c63c65fb71796c7d992f60a862aecbe6 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Fri, 28 Apr 2023 15:46:27 +0200 Subject: [PATCH] FIX: allows youtube embeds to respect the `t` param (#21295) --- .../assets/javascripts/discourse/components/lazy-iframe.js | 6 +++++- .../assets/javascripts/discourse/components/lazy-video.hbs | 2 ++ .../assets/javascripts/lib/lazy-video-attributes.js | 3 ++- .../discourse-lazy-videos/lib/lazy-videos/lazy_youtube.rb | 2 ++ .../test/javascripts/components/lazy-video-test.js | 7 +++++++ 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/plugins/discourse-lazy-videos/assets/javascripts/discourse/components/lazy-iframe.js b/plugins/discourse-lazy-videos/assets/javascripts/discourse/components/lazy-iframe.js index 015e0ea521e..b75ad65fa66 100644 --- a/plugins/discourse-lazy-videos/assets/javascripts/discourse/components/lazy-iframe.js +++ b/plugins/discourse-lazy-videos/assets/javascripts/discourse/components/lazy-iframe.js @@ -4,7 +4,11 @@ export default class LazyVideo extends Component { get iframeSrc() { switch (this.args.providerName) { case "youtube": - return `https://www.youtube.com/embed/${this.args.videoId}?autoplay=1`; + let url = `https://www.youtube.com/embed/${this.args.videoId}?autoplay=1`; + if (this.args.startTime > 0) { + url += `&start=${this.args.startTime}`; + } + return url; case "vimeo": return `https://player.vimeo.com/video/${this.args.videoId}${ this.args.videoId.includes("?") ? "&" : "?" diff --git a/plugins/discourse-lazy-videos/assets/javascripts/discourse/components/lazy-video.hbs b/plugins/discourse-lazy-videos/assets/javascripts/discourse/components/lazy-video.hbs index b2f459a5288..0d0ae7138af 100644 --- a/plugins/discourse-lazy-videos/assets/javascripts/discourse/components/lazy-video.hbs +++ b/plugins/discourse-lazy-videos/assets/javascripts/discourse/components/lazy-video.hbs @@ -6,6 +6,7 @@ }} data-video-id={{@videoAttributes.id}} data-video-title={{@videoAttributes.title}} + data-video-start-time={{@videoAttributes.startTime}} data-provider-name={{@videoAttributes.providerName}} > {{#if this.isLoaded}} @@ -13,6 +14,7 @@ @providerName={{@videoAttributes.providerName}} @title={{@videoAttributes.title}} @videoId={{@videoAttributes.id}} + @startTime={{@videoAttributes.startTime}} /> {{else}}
`); + + assert.dom(".youtube-onebox").hasAttribute("data-video-start-time", "234"); + }); + test("displays the correct provider icon", async function (assert) { await render(hbs``);