honour start time hash in youtube videos #273, and make youtu.be links embed the video #270

This commit is contained in:
Hannes Mannerheim 2015-11-16 17:40:04 +01:00
parent fefe9f2b87
commit 2ffe165d41
2 changed files with 25 additions and 5 deletions

View File

@ -950,14 +950,14 @@ function expand_queet(q,doScrolling) {
// if there's only one thumb and it's a youtube video, show it inline
if(q.children('.queet').find('.queet-thumbs.thumb-num-1').children('.thumb-container.play-button.youtube').length == 1) {
var youtubeId = q.children('.queet').find('.queet-thumbs.thumb-num-1').children('.thumb-container.play-button.youtube').children('.attachment-thumb').attr('data-full-image-url').replace('http://www.youtube.com/watch?v=','').replace('https://www.youtube.com/watch?v=','').replace('http://youtu.be/','').replace('https://youtu.be/','').substr(0,11);
if(q.children('.queet').find('.expanded-content').children('.media').children('iframe[src="//www.youtube.com/embed/' + youtubeId + '"]').length < 1) { // not if already showed
var youtubeURL = q.children('.queet').find('.queet-thumbs.thumb-num-1').children('.thumb-container.play-button.youtube').children('.attachment-thumb').attr('data-full-image-url');
if(q.children('.queet').find('.expanded-content').children('.media').children('iframe[src="' + youTubeEmbedLinkFromURL(youtubeURL) + '"]').length < 1) { // not if already showed
// hide video thumbnail if it's the only one
if(q.children('.queet').find('.queet-thumbs').children('.thumb-container').length < 2) {
q.children('.queet').find('.queet-thumbs').addClass('hide-thumbs');
}
// show video
q.children('.queet').find('.expanded-content').prepend('<div class="media"><iframe width="510" height="315" src="//www.youtube.com/embed/' + youtubeId + '" frameborder="0" allowfullscreen></iframe></div>');
q.children('.queet').find('.expanded-content').prepend('<div class="media"><iframe width="510" height="315" src="' + youTubeEmbedLinkFromURL(youtubeURL) + '" frameborder="0" allowfullscreen></iframe></div>');
}
}
@ -1841,14 +1841,14 @@ function buildQueetHtml(obj, idInStream, extraClassesThisRun, requeeted_by, isCo
// play button for videos and animated gifs
var playButtonClass = '';
if(this.url.indexOf('://www.youtube.com') > -1
if((this.url.indexOf('://www.youtube.com') > -1 || this.url.indexOf('://youtu.be') > -1)
|| (typeof this.animated != 'undefined' && this.animated === true)) {
var playButtonClass = ' play-button';
}
// youtube class
var youTubeClass = '';
if(this.url.indexOf('://www.youtube.com') > -1) {
if(this.url.indexOf('://www.youtube.com') > -1 || this.url.indexOf('://youtu.be') > -1) {
youTubeClass = ' youtube';
}

View File

@ -1645,3 +1645,23 @@ function theUserOrGroupThisStreamBelongsTo(stream) {
return stream;
}
}
/* ·
·
· Youtube embed link from youtube url
·
· · · · · · · · · · · · · */
function youTubeEmbedLinkFromURL(url) {
var youtubeId = url.replace('http://www.youtube.com/watch?v=','').replace('https://www.youtube.com/watch?v=','').replace('http://youtu.be/','').replace('https://youtu.be/','').substr(0,11);
// get start time hash
var l = document.createElement("a");
l.href = url;
if(l.hash.substring(0,3) == '#t=') {
return '//www.youtube.com/embed/' + youtubeId + '?start=' + l.hash.substring(3);
}
else {
return '//www.youtube.com/embed/' + youtubeId;
}
}