2016-02-17 01:17:22 +08:00
|
|
|
import { withPluginApi } from 'discourse/lib/plugin-api';
|
2014-07-22 10:39:32 +08:00
|
|
|
|
2016-10-31 23:27:07 +08:00
|
|
|
const returnFalse = () => false;
|
|
|
|
|
2014-07-22 10:39:32 +08:00
|
|
|
export default {
|
|
|
|
name: "apply-lazyYT",
|
2016-02-13 04:46:36 +08:00
|
|
|
initialize() {
|
2016-02-17 01:17:22 +08:00
|
|
|
withPluginApi('0.1', api => {
|
2016-10-31 23:27:07 +08:00
|
|
|
api.decorateCooked($elem => {
|
|
|
|
|
|
|
|
// We use this because watching videos fullscreen in Chrome was super buggy
|
|
|
|
// otherwise. Thanks to arrendek from q23 for the technique.
|
|
|
|
$elem.iframeTracker({ blurCallback: () => {
|
|
|
|
$(document).on("scroll.discourse-youtube", returnFalse);
|
|
|
|
window.setTimeout(() => $(document).off('scroll.discourse-youtube', returnFalse), 1500);
|
|
|
|
$(document).scroll();
|
|
|
|
}});
|
|
|
|
|
|
|
|
$('.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);
|
|
|
|
}
|
2016-03-01 02:56:38 +08:00
|
|
|
}
|
2016-10-31 23:27:07 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2016-02-17 01:17:22 +08:00
|
|
|
});
|
2014-07-22 10:39:32 +08:00
|
|
|
}
|
|
|
|
};
|