2018-06-16 00:42:20 +08:00
|
|
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
2021-07-16 02:32:47 +08:00
|
|
|
import initLazyYt from "../lib/lazyYT";
|
2014-07-22 10:39:32 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "apply-lazyYT",
|
2016-02-13 04:46:36 +08:00
|
|
|
initialize() {
|
2018-06-16 00:42:20 +08:00
|
|
|
withPluginApi("0.1", (api) => {
|
2021-07-16 02:32:47 +08:00
|
|
|
initLazyYt($);
|
2019-06-11 23:21:23 +08:00
|
|
|
api.decorateCooked(
|
|
|
|
($elem) => {
|
|
|
|
const iframes = $(".lazyYT", $elem);
|
|
|
|
if (iframes.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-31 23:27:07 +08:00
|
|
|
|
2019-06-11 23:21:23 +08:00
|
|
|
$(".lazyYT", $elem).lazyYT({
|
|
|
|
onPlay(e, $el) {
|
|
|
|
// don't cloak posts that have playing videos in them
|
2019-11-12 19:07:19 +08:00
|
|
|
const postId = parseInt(
|
|
|
|
$el.closest("article").data("post-id"),
|
|
|
|
10
|
|
|
|
);
|
2019-06-11 23:21:23 +08:00
|
|
|
if (postId) {
|
|
|
|
api.preventCloak(postId);
|
|
|
|
}
|
2016-10-31 23:27:07 +08:00
|
|
|
},
|
2019-06-11 23:21:23 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
{ id: "discourse-lazyyt" }
|
|
|
|
);
|
2016-02-17 01:17:22 +08:00
|
|
|
});
|
2014-07-22 10:39:32 +08:00
|
|
|
},
|
|
|
|
};
|