Created
November 27, 2015 18:16
-
-
Save Insayt/c7f1b0f0ad63ae16a947 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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