DEV: migrate audio cloak-prevention to decorateCookedElement (#15502)

Migrate deprecated decorateCooked to decorateCookedElement for audio cloak-prevention.

This might give a minimal performance boost: running audio cloak-prevention for 20 (non-audio) posts takes 1 ms and not 15 ms.

Co-authored-by: Jarek Radosz <jradosz@gmail.com>
This commit is contained in:
Ayke Halder 2022-01-09 01:57:49 +01:00 committed by GitHub
parent 5a50f18c0c
commit c0d702f01f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,20 +39,19 @@ export default {
nativeLazyLoading(api);
api.decorateCooked(
($elem) => {
const players = $("audio", $elem);
if (players.length) {
players.on("play", () => {
api.decorateCookedElement(
(elem) => {
elem.querySelectorAll("audio").forEach((player) => {
player.addEventListener("play", () => {
const postId = parseInt(
$elem.closest("article").data("post-id"),
elem.closest("article")?.dataset.postId,
10
);
if (postId) {
api.preventCloak(postId);
}
});
}
});
},
{ id: "discourse-audio" }
);