discourse/plugins/lazyYT/assets/javascripts/initializers/lazyYT.js.es6

26 lines
633 B
Plaintext
Raw Normal View History

2018-06-15 12:42:20 -04:00
import { withPluginApi } from "discourse/lib/plugin-api";
2014-07-21 22:39:32 -04:00
export default {
name: "apply-lazyYT",
initialize() {
2018-06-15 12:42:20 -04:00
withPluginApi("0.1", api => {
api.decorateCooked($elem => {
2018-06-15 12:42:20 -04:00
const iframes = $(".lazyYT", $elem);
if (iframes.length === 0) {
return;
}
2018-06-15 12:42:20 -04:00
$(".lazyYT", $elem).lazyYT({
onPlay(e, $el) {
// don't cloak posts that have playing videos in them
2018-06-15 12:42:20 -04:00
const postId = parseInt($el.closest("article").data("post-id"));
if (postId) {
api.preventCloak(postId);
}
}
});
});
});
2014-07-21 22:39:32 -04:00
}
};