-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathangular-progressbar.js
More file actions
117 lines (92 loc) · 3.04 KB
/
angular-progressbar.js
File metadata and controls
117 lines (92 loc) · 3.04 KB
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
/*
angular-progressbar 0.1.0 - Progressbar.js support for AngularJS http://kimmobrunfeldt.github.io/progressbar.js/
Copyright (C) 2014 - Felipe Campos Clarke <felipecamposclarke@gmail.com> and contributors
License: MIT
Source: https://github.com/felipecamposclarke/angular-progressbar
Date Compiled: 2014-10-28
*/
(function (root) {
'use strict';
function factory(angular, ProgressBar) {
var angularProgressbar = angular.module('angularProgressbar', []),
ProgressbarTypes = ['line', 'circle', 'square', 'path'];
angularProgressbar.factory('$pbService', ['$rootScope', function ($rootScope) {
var config = {};
config.animate = function (key, progress, options, cb) {
$rootScope.$broadcast('progressbar:animate', key, progress, options, cb);
};
config.stop = function (key) {
$rootScope.$broadcast('progressbar:stop', key);
};
config.set = function (key, progress) {
$rootScope.$broadcast('progressbar:stop', key, progress);
};
return config;
}])
angular.forEach(ProgressbarTypes, function(type){
var name = type.charAt(0).toUpperCase() + type.slice(1);
var directiveName = 'pb' + name;
angularProgressbar.directive(directiveName, ['$window', '$timeout', function ($window, $timeout) {
return {
scope: {
options: "="
},
link: function (scope, element, attr) {
if(typeof scope.options !== 'object' && attr.options)
throw new Error("the options aren't correct!");
if(!angular.isDefined(attr.progressKey))
throw new Error("the progress key is not defined");
var ProgressBarConstructor = ProgressBar || $window.ProgressBar;
var el = element[0];
scope.progressbar = null;
scope.key = attr.progressKey;
scope.animate = function (progress, options, cb) {
options = options || {};
if (scope.progressbar)
scope.progressbar.animate(progress, options, cb);
};
scope.stop = function () {
scope.progressbar.stop();
};
scope.set = function (progress) {
scope.progressbar.set(progress);
};
scope.$on('progressbar:animate', function (event, key, progress, options, cb) {
if (key === scope.key)
$timeout(function () {
scope.animate(progress, options, cb);
});
});
scope.$on('progressbar:stop', function (event, key) {
if (key === scope.key)
$timeout(function () {
scope.stop();
});
});
scope.$on('progressbar:set', function (event, key, progress) {
if (key === scope.key)
$timeout(function () {
scope.set(progress);
});
});
scope.$on('$destroy', function () {
el.innerHTML = '';
scope.progressbar = null;
});
scope.$watchCollection('options', function (options) {
el.innerHTML = '';
scope.progressbar = new ProgressBarConstructor[name](el, options);
});
}
};
}]);
});
}
if (typeof define === 'function' && define.amd) {
/* AMD module */
define(['angular', 'progressbar'], factory);
} else {
/* Browser global */
factory(root.angular);
}
}(window));