Simplified regex. Added video info.

This commit is contained in:
Tobias Theuer 2017-03-15 03:29:26 +01:00
parent 90ce0345a1
commit 7e7da76006

View file

@ -209,18 +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|youtu\.be)\/(?:v\/|embed\/|watch(?:\?v=|\/))?([a-zA-Z0-9_-]+)/i, var regex = /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/i,
match = url.match(regex); match = url.match(regex);
if (match){ if (match){
var token = match[1], var token = match[2],
embedurl = "https://www.youtube.com/embed/" + token + "?html5=1&iv_load_policy=3&modestbranding=1&rel=0&showinfo=0", embedurl = "https://www.youtube.com/embed/" + token + "?html5=1&iv_load_policy=3&modestbranding=1&rel=0",
element = angular.element('<iframe></iframe>') element = angular.element('<iframe></iframe>')
.attr('src', embedurl) .attr('src', embedurl)
.attr('width', '560') .attr('width', '560')
.attr('height', '315') .attr('height', '315')
.attr('frameborder', '0') .attr('frameborder', '0')
.attr('allowfullscreen', 'true'); .attr('allowfullscreen', 'true');
return element.prop('outerHTML'); return element.prop('outerHTML');
} }
}); });