Skip to content

Commit 527b47d

Browse files
init check for running timers
1 parent cac81ad commit 527b47d

File tree

3 files changed

+220
-217
lines changed

3 files changed

+220
-217
lines changed

app/js/timer.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ angular.module('timer', [])
1313
}
1414

1515
$scope.startTime = null;
16-
$scope.timeoutId = null;
16+
$scope.timeoutId = null;
1717
$scope.countdown = $scope.countdownattr && parseInt($scope.countdownattr, 10) > 0 ? parseInt($scope.countdownattr, 10) : undefined;
18+
$scope.isRunning = false;
1819

1920
$scope.$on('timer-start', function (){
2021
$scope.start();
@@ -27,20 +28,29 @@ angular.module('timer', [])
2728
$scope.$on('timer-stop', function (){
2829
$scope.stop();
2930
});
31+
32+
function init() {
33+
if ($scope.timeoutId) {
34+
$timeout.cancel($scope.timeoutId);
35+
}
36+
}
3037

3138
$scope.start = $element[0].start = function () {
3239
$scope.startTime = new Date();
40+
init();
3341
tick();
3442
};
3543

3644
$scope.resume = $element[0].resume = function () {
45+
init();
3746
$scope.startTime = new Date() - ($scope.stoppedTime - $scope.startTime);
3847
tick();
3948
};
4049

4150
$scope.stop = $element[0].stop = function () {
4251
$scope.stoppedTime = new Date();
4352
$timeout.cancel($scope.timeoutId);
53+
$scope.timeoutId = null;
4454
};
4555

4656
$element.bind('$destroy', function () {

examples.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
<ul class="dropdown-menu">
9999
<li><a target="_new" href="https://github.com/siddii/angular-timer">View on Github</a></li>
100100
<li><a target="_new" href="https://github.com/siddii/angular-timer/archive/master.zip">Download</a></li>
101+
<li>
102+
<a href="index.html#contribute">Contribute</a></li>
101103
</ul>
102104
</li>
103105
</ul>

0 commit comments

Comments
 (0)