forked from zdwolfe/angular-nanobar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnanobar.js
More file actions
36 lines (34 loc) · 900 Bytes
/
nanobar.js
File metadata and controls
36 lines (34 loc) · 900 Bytes
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
'use strict';
angular.module('nanobar', [])
.directive('nanobar', function ($log) {
return {
restrict: 'A',
scope: {
percentage: '=',
color: '='
},
link: function postLink(scope, element, attrs) {
if (!Nanobar || element.length > 1) {
$log.error('Nanobar unavailable or too many nanobars found');
return;
}
// @TODO options
var options = {
target: element[0],
bg: scope.color ? scope.color : '#000'
};
var nanobar = new Nanobar(options);
function updatePercentage(percentage) {
if (!nanobar || typeof(nanobar.go) !== 'function') {
return;
}
nanobar.go(percentage);
}
scope.$watch('percentage', function(newPercentage, oldPercentage) {
if (newPercentage) {
updatePercentage(newPercentage);
}
});
}
};
});