Adds support for embed button for youtube. Eliminates preview image fetched from youtube that was causing a leak

This commit is contained in:
nonmakina 2021-01-26 00:44:23 -06:00
parent 0b86471076
commit 1afb5a5f31
2 changed files with 22 additions and 12 deletions

View file

@ -25,21 +25,32 @@
onready(function(){
var do_embed_yt = function(tag) {
$('div.video-container a', tag).click(function() {
var videoID = $(this.parentNode).data('video');
$(this.parentNode).html('<iframe style="float:left;margin: 10px 20px" type="text/html" '+
'width="360" height="270" src="//www.youtube.com/embed/' + videoID +
'?autoplay=1&html5=1" allowfullscreen frameborder="0"/>');
const ON = "[Remove]";
const OFF = "[Embed]";
return false;
var videoNode = $('div.video-container', tag);
var videoId = videoNode.data('video');
var span = $("<span>[Embed]</span>");
var embedNode = $('<iframe style="float:left;margin: 10px 20px" type="text/html" '+
'width="360" height="270" src="//www.youtube.com/embed/' + videoId +
'?autoplay=1&html5=1" allowfullscreen frameborder="0"/>')
span.click(function() {
if (span.text() == ON){
videoNode.remove("iframe");
span.text(OFF);
} else{
videoNode.append(embedNode);
span.innerHTML = ON;
}
});
videoNode.append(span);
};
do_embed_yt(document);
// allow to work with auto-reload.js, etc.
$(document).on('new_post', function(e, post) {
do_embed_yt(post);
});
// allow to work with auto-reload.js, etc.
$(document).on('new_post', function(e, post) {
do_embed_yt(post);
});
});