Add start argument to youtube embeds if t arguement is present in url (#1155)
* Add start argument to youtube embeds if t arguement is present in url * Move time argument regex to after match * Allow for units in the t argument of youtube plugin * Allow hash arguments aswell * Correct or in reget for youtube plugin * Shorten regex * Allow argument before t argement that ends in t in youtube links * Also allow youtube links without t argument
This commit is contained in:
parent
788855d2e3
commit
4902f5889d
@ -209,13 +209,18 @@ plugins.factory('userPlugins', function() {
|
|||||||
* See: https://developers.google.com/youtube/player_parameters
|
* See: https://developers.google.com/youtube/player_parameters
|
||||||
*/
|
*/
|
||||||
var youtubePlugin = new UrlPlugin('YouTube video', function(url) {
|
var youtubePlugin = new UrlPlugin('YouTube video', function(url) {
|
||||||
var regex = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})/i,
|
var regex = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})(?:.*t=)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)?/i,
|
||||||
match = url.match(regex);
|
match = url.match(regex);
|
||||||
|
|
||||||
if (match){
|
if (match){
|
||||||
var token = match[1],
|
var token = match[1];
|
||||||
embedurl = "https://www.youtube.com/embed/" + token + "?html5=1&iv_load_policy=3&modestbranding=1&rel=0",
|
var hours = match[2] ? parseInt(match[2]) : 0;
|
||||||
element = angular.element('<iframe></iframe>')
|
var mins = match[3] ? parseInt(match[3]) : 0;
|
||||||
|
var secs = match[4] ? parseInt(match[4]) : 0;
|
||||||
|
var totalSecs = secs + mins*60 + hours*60*60;
|
||||||
|
var embedurl = "https://www.youtube.com/embed/" + token + "?html5=1&iv_load_policy=3&modestbranding=1&rel=0&start=" + totalSecs;
|
||||||
|
|
||||||
|
var element = angular.element('<iframe></iframe>')
|
||||||
.attr('src', embedurl)
|
.attr('src', embedurl)
|
||||||
.attr('width', '560')
|
.attr('width', '560')
|
||||||
.attr('height', '315')
|
.attr('height', '315')
|
||||||
|
Loading…
Reference in New Issue
Block a user