discourse/plugins/lazy-yt/assets/javascripts/initializers/lazyYT.js.es6

29 lines
717 B
Plaintext
Raw Normal View History

2018-06-16 00:42:20 +08:00
import { withPluginApi } from "discourse/lib/plugin-api";
2014-07-22 10:39:32 +08:00
export default {
name: "apply-lazyYT",
initialize() {
2018-06-16 00:42:20 +08:00
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"), 10);
if (postId) {
api.preventCloak(postId);
}
}
});
},
{ id: "discourse-lazyyt" }
);
});
2014-07-22 10:39:32 +08:00
}
};