-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
51 lines (45 loc) · 1016 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var justaminute = angular.module("justaminute", []);
justaminute.controller("CountdownController", function($scope, $interval){
var intrvl, continuing;
$scope.data = {};
function countdown(seconds) {
intrvl = $interval(function() {
if(seconds > 1) {
seconds -= 1;
$scope.data.seconds = seconds;
} else {
var sound = new Howl({urls: ['ping.wav']}).play();
if (continuing) {
seconds = 60;
$scope.data.seconds = seconds;
} else {
$scope.data.seconds = 0;
$interval.cancel(intrvl);
intrvl = null;
}
}
}, 1000);
}
$scope.reset = function() {
if (intrvl){
$interval.cancel(intrvl);
countdown(60);
} else {
countdown(60)
}
};
$scope.toggleContinuous = function() {
if(!intrvl) {
countdown(60)
}
continuing = !continuing;
$scope.data.continuing = continuing;
};
$scope.stop = function() {
if (intrvl) {
$interval.cancel(intrvl);
$scope.data.seconds = 0;
}
}
countdown(60);
});