@@ -108,14 +108,58 @@ angular.module('ui.bootstrap.progressbar')
108
108
109
109
. value ( '$progressSuppressWarning' , false )
110
110
111
- . controller ( 'ProgressController' , [ '$scope' , '$attrs' , '$controller ' , '$log' , '$progressSuppressWarning' , function ( $scope , $attrs , $controller , $log , $progressSuppressWarning ) {
111
+ . controller ( 'ProgressController' , [ '$scope' , '$attrs' , 'uibProgressConfig ' , '$log' , '$progressSuppressWarning' , function ( $scope , $attrs , progressConfig , $log , $progressSuppressWarning ) {
112
112
if ( ! $progressSuppressWarning ) {
113
113
$log . warn ( 'ProgressController is now deprecated. Use UibProgressController instead.' ) ;
114
114
}
115
115
116
- return $controller ( 'UibProgressController' , {
117
- $scope : $scope ,
118
- $attrs : $attrs
116
+ var self = this ,
117
+ animate = angular . isDefined ( $attrs . animate ) ? $scope . $parent . $eval ( $attrs . animate ) : progressConfig . animate ;
118
+
119
+ this . bars = [ ] ;
120
+ $scope . max = angular . isDefined ( $scope . max ) ? $scope . max : progressConfig . max ;
121
+
122
+ this . addBar = function ( bar , element , attrs ) {
123
+ if ( ! animate ) {
124
+ element . css ( { 'transition' : 'none' } ) ;
125
+ }
126
+
127
+ this . bars . push ( bar ) ;
128
+
129
+ bar . max = $scope . max ;
130
+ bar . title = attrs && angular . isDefined ( attrs . title ) ? attrs . title : 'progressbar' ;
131
+
132
+ bar . $watch ( 'value' , function ( value ) {
133
+ bar . recalculatePercentage ( ) ;
134
+ } ) ;
135
+
136
+ bar . recalculatePercentage = function ( ) {
137
+ bar . percent = + ( 100 * bar . value / bar . max ) . toFixed ( 2 ) ;
138
+
139
+ var totalPercentage = self . bars . reduce ( function ( total , bar ) {
140
+ return total + bar . percent ;
141
+ } , 0 ) ;
142
+
143
+ if ( totalPercentage > 100 ) {
144
+ bar . percent -= totalPercentage - 100 ;
145
+ }
146
+ } ;
147
+
148
+ bar . $on ( '$destroy' , function ( ) {
149
+ element = null ;
150
+ self . removeBar ( bar ) ;
151
+ } ) ;
152
+ } ;
153
+
154
+ this . removeBar = function ( bar ) {
155
+ this . bars . splice ( this . bars . indexOf ( bar ) , 1 ) ;
156
+ } ;
157
+
158
+ $scope . $watch ( 'max' , function ( max ) {
159
+ self . bars . forEach ( function ( bar ) {
160
+ bar . max = $scope . max ;
161
+ bar . recalculatePercentage ( ) ;
162
+ } ) ;
119
163
} ) ;
120
164
} ] )
121
165
0 commit comments