Add new eventListener to force rendering of embedded toots

This commit is contained in:
Yann Weyer 2024-11-29 18:02:29 +01:00
parent 986a3676d3
commit 0d5441bcdc
No known key found for this signature in database
GPG key ID: 3FD6BB3494F2A0D5

View file

@ -72,7 +72,7 @@
}); });
// Legacy embeds // Legacy embeds
document.querySelectorAll('iframe.mastodon-embed').forEach(iframe => { var renderLegacyEmbed = function (iframe) {
var id = generateId(embeds); var id = generateId(embeds);
embeds.set(id, iframe); embeds.set(id, iframe);
@ -91,10 +91,11 @@
}; };
iframe.onload(); // In case the script is executing after the iframe has already loaded 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 // New generation of embeds
document.querySelectorAll('blockquote.mastodon-embed').forEach(container => { var renderEmbed = function (container) {
var id = generateId(embeds); var id = generateId(embeds);
embeds.set(id, container); embeds.set(id, container);
@ -122,6 +123,14 @@
}; };
container.appendChild(iframe); 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(' ') : []); })((document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT' && document.currentScript.dataset.allowedPrefixes) ? document.currentScript.dataset.allowedPrefixes.split(' ') : []);