-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirective-video.js
75 lines (60 loc) · 2.65 KB
/
directive-video.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
72
73
74
75
angular.module('ionicVideoLink', ['ionic'])
.directive('ionicVideoLink', ['$window', '$document', function ($window, $document) {
return {
restict: 'A',
transclude: true,
scope: {
videoSrc: '@videoSrc',
videoName: '@videoName',
onVideoComplete: '&'
},
templateUrl: 'app/app/partials/directive-video.html',
link: function(scope, element) {
//need to double up on these for some items like ion-item
//element.removeAttr('ionic-video-link'); // necessary to avoid infinite compile loop
element.attr('ng-click', 'playVideo(\''+scope.videoName+'\')');
//When things start up, lets make a fader object
//But only if one doesn't exist yet so we can have multiples
if($('#ionicVideoFader')) {
//A fader doesn't exist yet
$('body').prepend('<div' +
' id="ionicVideoFader"' +
' style="' +
' background: black;' +
' position: fixed;' +
' width: 100%;' +
' height: 100%;' +
' z-index: 100;' +
' display: none;' +
' "' +
'></div>');
}
var videoHtml = $('<video id="'+scope.videoName+'" class="display-none"><source src="'+scope.videoSrc+'" type="video/mp4"></source></video>');
videoHtml.insertAfter($(element));
var thisVideo = videoHtml.get(0);
console.log('ionicVideoLink video name ', thisVideo);
thisVideo.addEventListener('webkitendfullscreen', scope.endVideo, false);
thisVideo.addEventListener('ended', scope.endVideo, false);
},
controller: function($scope, $element) {
console.log('ionicVideoLink video name ', $scope.videoName);
$scope.playVideo = function(id) {
$('#ionicVideoFader').fadeIn(500, function(){
//Play the video
console.log('ionicVideoLink playing video ' + id);
console.log('ionicVideoLink playing video jquery ' + $('#' + id).get(0));
$('#' + id).get(0).play();
//$scope.endVideo();
});
}
$scope.endVideo = function() {
if (typeof $scope.onVideoComplete == 'function') {
$scope.onVideoComplete();
}
$('#ionicVideoFader').delay(250).fadeOut(500, function(){
console.log('ionicVideoLink done playing video');
});
}
}
}
}]);