Skip to content

Commit

Permalink
Merge pull request siddii#44 from johnparn/master
Browse files Browse the repository at this point in the history
Added listener to be able to set countdown value
  • Loading branch information
siddii committed Feb 8, 2014
2 parents c30ff71 + 0ff25fe commit 42d932b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions app/js/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ angular.module('timer', [])
$scope.clear();
});

$scope.$on('timer-set-countdown', function (e, countdown) {
$scope.countdown = countdown;
});

function resetTimeout() {
if ($scope.timeoutId) {
clearTimeout($scope.timeoutId);
Expand Down Expand Up @@ -136,13 +140,6 @@ angular.module('timer', [])
return;
}
calculateTimeUnits();
if ($scope.countdown > 0) {
$scope.countdown--;
}
else if ($scope.countdown <= 0) {
$scope.stop();
return;
}

//We are not using $timeout for a reason. Please read here - https://github.com/siddii/angular-timer/pull/5
$scope.timeoutId = setTimeout(function () {
Expand All @@ -151,6 +148,15 @@ angular.module('timer', [])
}, $scope.interval - adjustment);

$scope.$emit('timer-tick', {timeoutId: $scope.timeoutId, millis: $scope.millis});

if ($scope.countdown > 0) {
$scope.countdown--;
}
else if ($scope.countdown <= 0) {
$scope.stop();
return;
}

};

if ($scope.autoStart === undefined || $scope.autoStart === true) {
Expand Down

0 comments on commit 42d932b

Please sign in to comment.