Browse Source

Introduces the youtube embed changes.

This is a consolidation of the January youtube.js changes
main
nonmakina 3 years ago
committed by discomrade
parent
commit
ba235ac2bd
  1. 42
      js/youtube.js

42
js/youtube.js

@ -24,22 +24,34 @@
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;
function addEmbedButton(index, videoNode) {
videoNode = $(videoNode);
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){
embedNode.remove();
span.text(OFF);
} else{
videoNode.append(embedNode);
span.text(ON);
}
});
};
do_embed_yt(document);
// allow to work with auto-reload.js, etc.
$(document).on('new_post', function(e, post) {
do_embed_yt(post);
});
});
videoNode.append(span);
}
$('div.video-container', document).each(addEmbedButton);
// allow to work with auto-reload.js, etc.
$(document).on('new_post', function(e, post) {
$('div.video-container', post).each(addEmbedButton);
});
});

Loading…
Cancel
Save