From 0d5441bcdc9fbe394aa4ba647d72d1da1af3a1a3 Mon Sep 17 00:00:00 2001 From: Yann Weyer Date: Fri, 29 Nov 2024 18:02:29 +0100 Subject: [PATCH] Add new eventListener to force rendering of embedded toots --- public/embed.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/public/embed.js b/public/embed.js index bc1fac3864..a13849c869 100644 --- a/public/embed.js +++ b/public/embed.js @@ -72,7 +72,7 @@ }); // Legacy embeds - document.querySelectorAll('iframe.mastodon-embed').forEach(iframe => { + var renderLegacyEmbed = function (iframe) { var id = generateId(embeds); embeds.set(id, iframe); @@ -91,10 +91,11 @@ }; iframe.onload(); // In case the script is executing after the iframe has already loaded - }); + }; + document.querySelectorAll('iframe.mastodon-embed').forEach(renderLegacyEmbed); // New generation of embeds - document.querySelectorAll('blockquote.mastodon-embed').forEach(container => { + var renderEmbed = function (container) { var id = generateId(embeds); embeds.set(id, container); @@ -122,6 +123,14 @@ }; container.appendChild(iframe); + }; + document.querySelectorAll('blockquote.mastodon-embed').forEach(renderEmbed); + + // Listen to "mastodon.render" to force rendering of embedded posts + document.addEventListener('mastodon.render', function (e) { + if (e.target.matches('blockquote.mastodon-embed')) { + renderEmbed(e.target); + } }); }); })((document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT' && document.currentScript.dataset.allowedPrefixes) ? document.currentScript.dataset.allowedPrefixes.split(' ') : []);