1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2025-02-10 00:08:30 +01:00

Merge pull request #888 from Zankaria/youtube-js

Upstream (some) youtube.js changes
This commit is contained in:
Lorenzo Yario 2025-02-05 11:37:46 -06:00 committed by GitHub
commit d36c6244e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

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