-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscripts2.js
More file actions
92 lines (68 loc) · 2.4 KB
/
scripts2.js
File metadata and controls
92 lines (68 loc) · 2.4 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Set a default namespace
var timerApp = {};
// set the default seconds
timerApp.seconds = 0;
// setSeconds Function
// this starts the timer when you pass it any number of seconds
timerApp.setSeconds = function(seconds){
// clear any existing countdown timers
window.clearInterval(timerApp.countdown);
timerApp.countdown = window.setInterval(function() {
// these are purely for displaying the mins and seconds left
var visualMins = Math.floor(seconds / 60);
var visualSeconds = seconds % 60;
// pre-pend a zero incase we have less than 10 seconds left
// turns '6' seconds to '06'
if(visualSeconds < 10) {
visualSeconds = "0" + visualSeconds;
}
// Update the time left element
$('.seconds').text(visualMins + ":" + visualSeconds);
// Update the browsers tab to reflect how much time is left
$('title').text(visualMins + ":" + visualSeconds);
// Decrement the number of seconds left
seconds--;// or seconds = seconds -1;
// if there are 10 or less seconds left, turn the background yellow. Use the css() method
if (seconds > 10) {
$('body').css('background','#3498db');
}
if(seconds < 10) {
$('body').css('background','#f1c40f');
};
if (seconds < 0) {
$('body').css('background','red');
window.clearInterval(timerApp.countdown);
};
},1000); // 1000 means run this every 1000 milliseconds or 1 second
}; //close setSeconds function
timerApp.playMusic = function() {
// plays the final countdown
var finalCountdownHtml = '<iframe width="420" height="315" src="https://www.youtube.com/embed/EG7wB3G-xp0?autoplay=1#t=3m52s" frameborder="0" allowfullscreen></iframe>';
$('body').append(finalCountdownHtml);
}
// Document ready
$(function(){
$(".clearClock").on("click", function() {
location.reload(true);
}); //end clear clock
$(".fifteen").on("click", function(e){
e.preventDefault();
timerApp.setSeconds(900);
});
$(".lunchBreak").on("click", function(e){
e.preventDefault();
timerApp.setSeconds(3600);
});
$(".afternoonBreak").on("click", function(e){
e.preventDefault();
timerApp.setSeconds(1800);
});
$("input").on("change", function(){
var inputSeconds = $(this).val();
var inputMinutes = inputSeconds*60
timerApp.setSeconds(inputMinutes);
});
$(".mirrorClock").on("click", function(){
$(".countdown").toggleClass("flipscreen");
});
}); //end doc ready