mirror of
https://github.com/discourse/discourse.git
synced 2024-12-16 16:53:45 +08:00
c322cccd53
* Remove long-deprecated method * FIX: Memory Leaks when decorating posts Previously we'd keep creating mixins dynamically when decorating the same class. This code changes the API to recommend an `id` parameter for each decorator which will avoid leaks. All plugins should be updated to include this parameter, although if they don't in the meantime it'll just mean a warning in the console (and a continued leak.)
29 lines
713 B
JavaScript
29 lines
713 B
JavaScript
import { withPluginApi } from "discourse/lib/plugin-api";
|
|
|
|
export default {
|
|
name: "apply-lazyYT",
|
|
initialize() {
|
|
withPluginApi("0.1", api => {
|
|
api.decorateCooked(
|
|
$elem => {
|
|
const iframes = $(".lazyYT", $elem);
|
|
if (iframes.length === 0) {
|
|
return;
|
|
}
|
|
|
|
$(".lazyYT", $elem).lazyYT({
|
|
onPlay(e, $el) {
|
|
// don't cloak posts that have playing videos in them
|
|
const postId = parseInt($el.closest("article").data("post-id"));
|
|
if (postId) {
|
|
api.preventCloak(postId);
|
|
}
|
|
}
|
|
});
|
|
},
|
|
{ id: "discourse-lazyyt" }
|
|
);
|
|
});
|
|
}
|
|
};
|