-
Notifications
You must be signed in to change notification settings - Fork 2
/
hafcafTest.html
45 lines (42 loc) · 1.36 KB
/
hafcafTest.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
<!DOCTYPE html>
<html>
<head>
<title>hafcaf Test</title>
<link rel="stylesheet" href="hafcaf.css" />
</head>
<body>
<main id="main-container">
<section id="home">
<h1>Home</h1>
<a href="#counter">Counter Test</a>
</section>
</main>
<script type="text/javascript" src="hafcaf.js"></script>
<script type="text/javascript">
hafcaf.addRoute({
id: "home"
});
hafcaf.addRoute({
id: "counter",
innerHTML: "<section><span id='counter__display'>0</span><button id='counter__button'>Add 1</button></sec>",
onRender: function() {
// storing the counter var globally for simplicity’s sake in this demo
window.counter = 0;
// create the event handler
function incrementCounter() {
counter++;
document.getElementById("counter__display").innerHTML = counter;
}
// setup the listener
const button = document.getElementById("counter__button");
button.addEventListener("click", incrementCounter, false);
// create a disposer to remove the event listener on exit
const disposer = function() {
button.removeEventListener("click", incrementCounter, false);
};
hafcaf.exitFunctions.push(disposer);
}
});
</script>
</body>
</html>