Skip to content

Instantly share code, notes, and snippets.

@Insayt
Created November 27, 2015 18:16
Show Gist options
  • Save Insayt/c7f1b0f0ad63ae16a947 to your computer and use it in GitHub Desktop.
Save Insayt/c7f1b0f0ad63ae16a947 to your computer and use it in GitHub Desktop.
.directive('embedVideoSrc', ['$compile','VideoService', function ($compile, VideoService) {
return {
link: function(scope, element, attrs) {
scope.srcVideo = attrs.embedVideoSrc;
var template = '';
var serviceVideo = VideoService.getVideoServiceByUrl(attrs.embedVideoSrc);
console.log(attrs);
attrs.embedVideoHeight = attrs.embedVideoHeight || 315;
attrs.embedVideoWidth = attrs.embedVideoWidth || 420;
switch(serviceVideo) {
case 'vimeo':
template = '<iframe width=' + attrs.embedVideoWidth + ' height=' + attrs.embedVideoHeight + ' src=' + attrs.embedVideoSrc + ' frameborder="0" allowfullscreen></iframe>';
break;
case 'youtube':
template = '<iframe width=' + attrs.embedVideoWidth + ' height=' + attrs.embedVideoHeight + ' src=' + attrs.embedVideoSrc + ' frameborder="0" allowfullscreen></iframe>';
break;
default:
throw 'Undefined service';
}
element.html(template);
$compile(element.contents())(scope);
}
};
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment