11/**
2- * angular-timer - v1.0.12 - 2014-02-03 9:30 PM
2+ * angular-timer - v1.0.12 - 2014-02-10 9:05 AM
33 * https://github.com/siddii/angular-timer
44 *
55 * Copyright (c) 2014 Siddique Hameed
@@ -52,6 +52,10 @@ angular.module('timer', [])
5252 $scope . clear ( ) ;
5353 } ) ;
5454
55+ $scope . $on ( 'timer-set-countdown' , function ( e , countdown ) {
56+ $scope . countdown = countdown ;
57+ } ) ;
58+
5559 function resetTimeout ( ) {
5660 if ( $scope . timeoutId ) {
5761 clearTimeout ( $scope . timeoutId ) ;
@@ -61,7 +65,9 @@ angular.module('timer', [])
6165 $scope . start = $element [ 0 ] . start = function ( ) {
6266 $scope . startTime = $scope . startTimeAttr ? new Date ( $scope . startTimeAttr ) : new Date ( ) ;
6367 $scope . endTime = $scope . endTimeAttr ? new Date ( $scope . endTimeAttr ) : null ;
64- $scope . countdown = $scope . countdownattr && parseInt ( $scope . countdownattr , 10 ) > 0 ? parseInt ( $scope . countdownattr , 10 ) : undefined ;
68+ if ( ! $scope . countdown ) {
69+ $scope . countdown = $scope . countdownattr && parseInt ( $scope . countdownattr , 10 ) > 0 ? parseInt ( $scope . countdownattr , 10 ) : undefined ;
70+ }
6571 resetTimeout ( ) ;
6672 tick ( ) ;
6773 $scope . isRunning = true ;
@@ -109,6 +115,9 @@ angular.module('timer', [])
109115 $scope . addCDSeconds = $element [ 0 ] . addCDSeconds = function ( extraSeconds ) {
110116 $scope . countdown += extraSeconds ;
111117 $scope . $digest ( ) ;
118+ if ( ! $scope . isRunning ) {
119+ $scope . start ( ) ;
120+ }
112121 } ;
113122
114123 $scope . $on ( 'timer-add-cd-seconds' , function ( e , extraSeconds ) {
@@ -143,13 +152,6 @@ angular.module('timer', [])
143152 return ;
144153 }
145154 calculateTimeUnits ( ) ;
146- if ( $scope . countdown > 0 ) {
147- $scope . countdown -- ;
148- }
149- else if ( $scope . countdown <= 0 ) {
150- $scope . stop ( ) ;
151- return ;
152- }
153155
154156 //We are not using $timeout for a reason. Please read here - https://github.com/siddii/angular-timer/pull/5
155157 $scope . timeoutId = setTimeout ( function ( ) {
@@ -158,6 +160,13 @@ angular.module('timer', [])
158160 } , $scope . interval - adjustment ) ;
159161
160162 $scope . $emit ( 'timer-tick' , { timeoutId : $scope . timeoutId , millis : $scope . millis } ) ;
163+
164+ if ( $scope . countdown > 0 ) {
165+ $scope . countdown -- ;
166+ }
167+ else if ( $scope . countdown <= 0 ) {
168+ $scope . stop ( ) ;
169+ }
161170 } ;
162171
163172 if ( $scope . autoStart === undefined || $scope . autoStart === true ) {
0 commit comments