-
Notifications
You must be signed in to change notification settings - Fork 2
/
hafcafModuleTest.html
70 lines (63 loc) · 2.13 KB
/
hafcafModuleTest.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
<!DOCTYPE html>
<html>
<head>
<title>hafcaf Test</title>
<link rel="stylesheet" href="hafcaf.css" />
</head>
<body>
<main id="main-container">
<section id="subroutes">
<h1>Subroutes</h1>
<a href="#subroutes/a">Subroute A</a>
<a href="#subroutes/b">Subroute B</a>
<a href="#subroutes/c">Subroute C</a>
</section>
<section id="subroutes/a">
<p>This is the A section. Alphabet eat your heart out.</p>
</section>
<section id="subroutes/b">
<p>This is the B section. Bouncing baby bok choys.</p>
</section>
<section id="subroutes/c">
<p>This is the C section. Over there is Sandy Bottoms.</p>
</section>
<section id="home">
<h1>Home</h1>
<a href="#counter">Counter Test</a>
<a href="#subroutes">Subroute Testing</a>
</section>
</main>
<script type="module">
import hafcaf from "./hafcaf-module.js";
hafcaf.init();
const routes = [{ id: "home" }, { id: "subroutes" }, { id: "subroutes/b" }];
routes.forEach(route => hafcaf.addRoute(route));
hafcaf.addRoute({
id: "counter",
innerHTML: `
<section>
<span id='counter__display'>0</span>
<button id='counter__button'>Add 1</button>
<a href='#home'>Go home</a>
</section>`,
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>