-
Notifications
You must be signed in to change notification settings - Fork 57
/
Controls.js
124 lines (96 loc) · 2.93 KB
/
Controls.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
(function Controls($angular) {
"use strict";
/**
* @property module
* @type {Object}
*/
var module = $angular.module('ngVideo');
/**
* List of actions that are available on the video player.
*
* @property actions
* @type {String[]}
*/
var actions = ['play', 'pause'];
/**
* @directive viControls
* @type {Function}
* @param ngVideoOptions {Object}
*/
module.directive('viControls', ['ngVideoOptions',
function ngControlsDirective(ngVideoOptions) {
return {
/**
* @property restrict
* @type {String}
*/
restrict: ngVideoOptions.RESTRICT,
/**
* @property controller
* @type {Array}
* @param $scope {Object}
*/
controller: ['$scope', function controller($scope) {
/**
* @method play
* @return {void}
*/
$scope.play = function play() {
$scope.player.play();
$scope.$apply();
};
/**
* @method pause
* @return {void}
*/
$scope.pause = function pause() {
$scope.player.pause();
$scope.$apply();
};
}]
}
}]);
/**
* @method createControlDirective
* @param name {String}
* @return {Object}
*/
var createControlDirective = function createControlDirective(name) {
/**
* @property directiveLabel
* @type {String}
*/
var directiveLabel = name.charAt(0).toUpperCase() + name.slice(1);
/**
* @directive viControlsItem
* @type {Function}
*/
module.directive('viControls' + directiveLabel, ['video', 'ngVideoOptions',
function viControlsItem(video, ngVideoOptions) {
return {
/**
* @property restrict
* @type {String}
*/
restrict: ngVideoOptions.RESTRICT,
/**
* @method link
* @param scope {Object}
* @param element {Object}
* @return {void}
*/
link: function link(scope, element) {
// Ensure the control type is currently supported.
if (typeof scope[name] !== 'function') {
video.throwException("Control type '" + name + "' is unsupported");
}
element.bind('click', scope[name]);
}
}
}]);
};
// Attach all of our control item directives.
$angular.forEach(actions, function forEach(actionName) {
createControlDirective(actionName);
});
})(window.angular);