@@ -13,7 +13,7 @@ var timerModule = angular.module('timer', [])
13
13
language : '@?' ,
14
14
maxTimeUnit : '='
15
15
} ,
16
- controller : [ '$scope' , '$element' , '$attrs' , '$timeout' , 'I18nService' , '$interpolate' , function ( $scope , $element , $attrs , $timeout , I18nService , $interpolate ) {
16
+ controller : [ '$scope' , '$element' , '$attrs' , '$timeout' , 'I18nService' , '$interpolate' , 'progressBarService' , function ( $scope , $element , $attrs , $timeout , I18nService , $interpolate , progressBarService ) {
17
17
18
18
// Checking for trim function since IE8 doesn't have it
19
19
// If not a function, create tirm with RegEx to mimic native trim
@@ -40,6 +40,10 @@ var timerModule = angular.module('timer', [])
40
40
var i18nService = new I18nService ( ) ;
41
41
i18nService . init ( $scope . language ) ;
42
42
43
+ //progress bar
44
+ $scope . displayProgressBar = 0 ;
45
+ $scope . displayProgressActive = 'active' ; //Bootstrap active effect for progress bar
46
+
43
47
if ( $element . html ( ) . trim ( ) . length === 0 ) {
44
48
$element . append ( $compile ( '<span>' + $interpolate . startSymbol ( ) + 'millis' + $interpolate . endSymbol ( ) + '</span>' ) ( $scope ) ) ;
45
49
} else {
@@ -252,19 +256,30 @@ var timerModule = angular.module('timer', [])
252
256
calculateTimeUnits ( ) ;
253
257
254
258
var tick = function tick ( ) {
255
-
259
+ var typeTimer = null ; // countdown or endTimeAttr
256
260
$scope . millis = moment ( ) . diff ( $scope . startTime ) ;
257
261
var adjustment = $scope . millis % 1000 ;
258
262
259
263
if ( $scope . endTimeAttr ) {
264
+ typeTimer = $scope . endTimeAttr ;
260
265
$scope . millis = moment ( $scope . endTime ) . diff ( moment ( ) ) ;
261
266
adjustment = $scope . interval - $scope . millis % 1000 ;
262
267
}
263
268
264
269
if ( $scope . countdownattr ) {
270
+ typeTimer = $scope . countdownattr ;
265
271
$scope . millis = $scope . countdown * 1000 ;
266
272
}
267
273
274
+ if ( typeTimer !== null ) {
275
+ //calculate progress bar
276
+ $scope . progressBar = progressBarService . calculateProgressBar ( $scope . startTime , $scope . millis , $scope . endTime , $scope . countdownattr ) ;
277
+
278
+ if ( $scope . progressBar === 100 ) {
279
+ $scope . displayProgressActive = '' ; //No more Bootstrap active effect
280
+ }
281
+ }
282
+
268
283
if ( $scope . millis < 0 ) {
269
284
$scope . stop ( ) ;
270
285
$scope . millis = 0 ;
0 commit comments