-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
140 lines (123 loc) Β· 4.62 KB
/
index.js
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* SMOOTH SCROLLING */
const links = document.querySelectorAll('.hero-nav a');
const navContainer = document.querySelector('.hero-nav');
navContainer.addEventListener('click', event => {
event.preventDefault();
const href = event.target.closest('a').getAttribute('href');
document.querySelector(href).scrollIntoView({ behavior: 'smooth' });
});
/* STICKY NAV */
const navElement = document.querySelector('.hero-container');
const navObserver = new IntersectionObserver(
function (entries) {
entries[0].isIntersecting !== true
? navElement.classList.add('sticky')
: navElement.classList.remove('sticky');
},
{
root: null,
threshold: 0.5,
}
);
navObserver.observe(navElement);
// EXPAND ALL HOUSE CARD DETAILS
const expandAll = document.querySelector('.expand-houses');
expandAll.addEventListener('click', function () {
houseContent.forEach(function (house) {
house.style.display = 'flex';
});
});
// TOGGLE BETWEEN DIFFERENT CONTENT
const houseBtns = [
document.querySelector('#gryffindor-btn'),
document.querySelector('#slytherin-btn'),
document.querySelector('#hufflepuff-btn'),
document.querySelector('#ravenclaw-btn'),
];
const houseContent = [
document.querySelector('#gryffindor'),
document.querySelector('#slytherin'),
document.querySelector('#hufflepuff'),
document.querySelector('#ravenclaw'),
];
houseBtns.forEach((button, index) => {
button.addEventListener('click', () => {
houseContent.forEach(content => (content.style.display = 'none'));
houseContent[index].style.display = 'flex';
});
});
// Form Apply Functionality
const apply = () => {
const name = document.querySelector('#name').value;
const age = document.querySelector('#age').value;
const trait = document.querySelector('#trait').value.toLowerCase().trim();
const response = document.querySelector('.submission-response');
// Underage
if (age < 11 && age > 0) {
response.textContent = `π Sorry, you are not qualified. Please try again when you reach your 11th birthday!`;
// Ravenclaw
} else if (
(age >= 11 && trait === 'clever') ||
trait === 'creative' ||
trait === 'witty' ||
trait === 'curious' ||
trait === 'observant'
) {
response.textContent = `π¦
You're a match for Ravenclaw! Congrats, ${name}! We'll be in touch with you soon.`;
// Slytherin
} else if (
(age >= 11 && trait === 'ambitious') ||
trait === 'cunning' ||
trait === 'pride' ||
trait === 'leadership' ||
trait === 'competitive'
) {
response.textContent = `π ${name}, you'd be a great addition to Slytherin! We'll be in touch with you soon.`;
// Gryffindor
} else if (
(age >= 11 && trait === 'brave') ||
trait === 'determination' ||
trait === 'adventurous' ||
trait === 'idealistic' ||
trait === 'daring'
) {
response.textContent = `π¦ ${name}, you'd be a great addition to Gryffindor! We'll be in touch with you soon.`;
// Hufflepuff
} else if (
(age >= 11 && trait === 'dedicated') ||
trait === 'hardworking' ||
trait === 'loyal' ||
trait === 'patient' ||
trait === 'modest'
) {
response.textContent = `𦑠${name}, you'd be a great addition to Hufflepuff! We'll be in touch with you soon.`;
} else {
// Empty Responses
response.textContent = `π¨ Sorry, you have not provided enough information.`;
}
};
const applyBtn = document.getElementById('apply-btn');
applyBtn.addEventListener('click', apply);
// Form Status Functionality
const statusCheck = () => {
const name = document.querySelector('#name').value;
const age = document.querySelector('#age').value;
const applied = document.querySelector('#applied').value.toLowerCase().trim();
const response = document.querySelector('.submission-response');
if (age >= 11 && applied === 'yes') {
response.textContent = `π¦ Thank you for sending your application, ${name}! You are qualified to attend. An owl will be arriving soon with your decision and instructions.`;
} else if ((age <= 11 && applied === 'no') || applied === 'yes') {
response.textContent = `π Unfortunately, you're not old enough, ${name}. Please check back in once you've turned 11. `;
} else if (age >= 11 && applied === 'no') {
response.textContent = `πͺ You are qualified to apply, ${name}!`;
} else {
response.textContent = `π¨ Sorry, you have not provided enough information.`;
}
};
const statusBtn = document.getElementById('status-check-btn');
statusBtn.addEventListener('click', statusCheck);
// Add Hover Functionality for Mobile
const courseListing = document.querySelector('.course-listing-container');
const navButtons = document.querySelector('.hero-nav');
courseListing.addEventListener('touchstart', function () {}, true);
navButtons.addEventListener('touchstart', function () {}, true);