mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 12:12:26 +08:00
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:
parent
5a50f18c0c
commit
c0d702f01f
|
@ -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" }
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue
Block a user