FIX: Don't cloak videos once they begin playing

This commit is contained in:
Robin Ward
2016-02-29 13:56:38 -05:00
parent 01e1bb53f1
commit d538bcbe40
4 changed files with 40 additions and 4 deletions

View File

@ -4,7 +4,15 @@ export default {
name: "apply-lazyYT",
initialize() {
withPluginApi('0.1', api => {
api.decorateCooked($elem => $('.lazyYT', $elem).lazyYT());
api.decorateCooked($elem => $('.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);
}
}
}));
});
}
};

View File

@ -6,9 +6,12 @@
* Contributors: https://github.com/tylerpearson/lazyYT/graphs/contributors || https://github.com/daugilas/lazyYT/graphs/contributors
*
* Usage: <div class="lazyYT" data-youtube-id="laknj093n" data-parameters="rel=0">loading...</div>
*
* Note: Discourse has forked this from the original, beware when updating the file.
*
*/
;(function ($) {
(function ($) {
'use strict';
function setUp($el, settings) {
@ -100,10 +103,15 @@
.addClass('lazyYT-image-loaded')
.on('click', function (e) {
e.preventDefault();
if (!$el.hasClass('lazyYT-video-loaded') && $thumb.hasClass('lazyYT-image-loaded')) {
$el.html('<iframe src="//www.youtube.com/embed/' + id + '?autoplay=1&' + youtube_parameters + '" frameborder="0" allowfullscreen></iframe>')
.addClass('lazyYT-video-loaded');
}
if (settings.onPlay) {
settings.onPlay(e, $el);
}
});
}
@ -122,4 +130,4 @@
});
};
}(jQuery));
})(jQuery);