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