-
Notifications
You must be signed in to change notification settings - Fork 1
/
counter.html
79 lines (71 loc) · 3.05 KB
/
counter.html
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
<!DOCTYPE HTML>
<html>
<head>
<title>Simple modular up-down counter</title>
<meta charset="utf-8">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="./counter.css" />
</head>
<body>
<h1>
Simple counter, using ES6 classes
</h1>
<div class="content-pane">
<div class="description">
<h2>
Description:
</h2>
<p>So I wanted to work on the pomodoro timer for FCC, but I wanted to change a few things. First, I want to build it to be library-agnostic, as much as possible. Second, I want to use "modern" javascript, as in ECMAScript6, as much as possible (or
where really feasible). Third, I wanted to make it more component based.</p>
<p>To that third point, I really want to start building components that follow what I'm starting to see as the three rules: Encapsulation, Delegation and Communication. Here's how I view those:</p>
<ul>
<li><strong>Encapsulation:</strong> Each component should be completely isolated from its siblings or ancestors.</li>
<li><strong>Delegation:</strong> Each component should be able to delegate activities to its own descendants.</li>
<li><strong>Communication:</strong> Each component should communicate with its ancestors.</li>
</ul>
<p>So here's the second of a few components: a Counter class.</p>
Take a look at the <a href="./timer.js" target="_blank">timer source</a>, to see how it works!
</div>
<div id="counter1" class="counter"></div>
</div>
<div class="action-buttons">
<button class='reset-btn'>
Reset
</button>
</div>
<script src="counter.js"></script>
<script>
// Create an instance of our Timer component. It is customizeable, and takes callbacks!
let breakCounter = new Counter({
title: "Break:",
id: 'break',
min: 1,
max: 15,
default: 5,
onReset: () => { console.info("Hey! You reset me! I'm going from "+breakCounter.count+" to 5" )}
});
let sessionCounter = new Counter({
title: "Session:",
id: 'session',
min: 15,
max: 60,
default: 30,
onChange: function(){
console.log("You changed the session length. It is now "+sessionCounter.count+" minutes.");
}
});
// Of course, we want to see it doing something. Let's get its dom node and put that in.
let counterContainer = document.querySelector("#counter1");
counterContainer.appendChild(breakCounter.domEl);
counterContainer.appendChild(sessionCounter.domEl);
// Let's create a reset!
let resetBtn = document.querySelector('.reset-btn');
resetBtn.addEventListener("click", function(){
// The counter class has a reset function, which simply restores the display to
// the default value. Let's call that on both counters.
breakCounter.reset();
sessionCounter.reset();
})
</script>
</body>
</html>