Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
85 lines (71 loc) · 2.07 KB
/
Copy pathapp.js
File metadata and controls
85 lines (71 loc) · 2.07 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
const PageState = function() {
let currentState = new homeState(this);
this.init = function() {
this.change(new homeState);
}
this.change = function(state) {
currentState = state;
}
};
//Home State
const homeState = function(page) {
document.querySelector('#heading').textContent = null;
document.querySelector('#content').innerHTML = `
<div class="jumbotron">
<h1 class="display-4">Hello, world!</h1>
<p class="lead">This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.</p>
<hr class="my-4">
<p>It uses utility classes for typography and spacing to space content out within the larger container.</p>
<p class="lead">
<a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a>
</p>
</div>
`;
};
//About State
const aboutState = function(page) {
document.querySelector('#heading').textContent = "About Us";
document.querySelector('#content').innerHTML = `
<p>This is the about page</p>
`;
};
//Contact State
const contactState = function(page) {
document.querySelector('#heading').textContent = "Contact Us";
document.querySelector('#content').innerHTML = `
<form>
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control">
</div>
<div class="form-group">
<label>Email address</label>
<input type="email" class="form-control">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
`;
};
//Instantiate pageState
const page = new PageState();
//Init the first state
page.init();
//UI variables
const home = document.getElementById('home'),
about = document.getElementById('about'),
contact = document.getElementById('contact');
//Home
home.addEventListener('click', (e) => {
page.change(new homeState);
e.preventDefault();
});
//About
about.addEventListener('click', (e) => {
page.change(new aboutState);
e.preventDefault();
});
//Contact
contact.addEventListener('click', (e) => {
page.change(new contactState);
e.preventDefault();
})