forked from jiin/ng-video-preview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo-preview.js
71 lines (62 loc) · 2.26 KB
/
video-preview.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
/* Directives */
angular.module('ngVideoPreview', ['ngSanitize']).
directive('ngVideoPreview', ['$sce', function($sce) {
return {
restrict: 'E',
scope: {
source: '@',
url: '@',
playerWidth: '@',
playerHeight: '@'
},
transclude: true,
replace: true,
template: '<div class="ngVideoPreview element">' +
' <iframe width="{{width}}" height="{{height}}" ng-src="{{iframeSrc}}" frameborder="0" allowfullscreen></iframe>' +
'</div>',
link: function($scope, $element, $attrs) {
var v = '';
$scope.width = $scope.playerWidth || 570;
$scope.height = $scope.playerHeight || 325;
var config = {
'youtube': {
search: [
/(?:https?:\/\/|www.|m.|^)youtu(?:be.com\/watch\?(?:.?&(?:amp;)?)?v=|.be\/)([\w-]+)(?:&(?:amp;)?[\w\?=])?/
],
embed: '//www.youtube.com/embed/@',
index: 1
},
'vimeo': {
search: [
/vimeo\.com\/(.+)/,
/vimeo.com\/channels\/staffpicks\/(.+)/
],
embed: '//player.vimeo.com/video/@',
index: 1
},
'bitlanders': {
search: [
/bitlanders\.com\/movie\/(.+)\/(\d+)/
],
embed: '//bitlanders.com/embed/M@',
index: 2
},
'vine': {
search: [
/vine\.co\/v\/(.+)/
],
embed: '//vine.co/v/@/embed/simple',
index: 1
}
};
var tokens = config[$attrs.source];
Object(tokens.search).forEach(function(t) {
var domain = $attrs.url.substr($attrs.url.indexOf('://')+3),
match = domain.match(t);
if (match) v = match[tokens.index];
});
$scope.iframeSrc = $sce.trustAsResourceUrl(tokens.embed.replace('@', v));
},
};
}]);