-
Notifications
You must be signed in to change notification settings - Fork 5
/
global.js
70 lines (58 loc) · 2.09 KB
/
global.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
window.addEventListener("DOMContentLoaded", (event) => {
console.log("Welcome to the browser inspector! You are in the Console tab, which shows you JavaScript logs and errors.");
console.log("Click the \"Elements\" tab to read the HTML.")
console.log("Click the \"Sources\" tab to read the HTML/CSS/JavaScript source files.")
console.log("Click the \"Application\" tab to read the local storage.")
//
// ---------------------------------------------------------
// Help button functionality
// ---------------------------------------------------------
//
const helpBtn = document.querySelector(".help-button");
const helpBlurb = document.querySelector(".help-blurb");
if (helpBtn) {
helpBtn.addEventListener("click", event => {
helpBlurb.classList.toggle("hidden");
helpBtn.classList.toggle("closed");
});
};
//
// ---------------------------------------------------------
// Network tab challenge
// ---------------------------------------------------------
//
const networkPasswordSubmitBtn = document.querySelector("button.network-btn");
const networkPasswordField = document.querySelector("input.network-password");
const networkPassword = "wahoo"
if (networkPasswordSubmitBtn) {
networkPasswordSubmitBtn.addEventListener("click", event => {
if (networkPasswordField.value == networkPassword) {
window.location.href = "/complete.html";
} else {
throwError();
};
});
};
//
// ---------------------------------------------------------
// Press enter to submit challenge
// ---------------------------------------------------------
//
document.addEventListener("keypress", function (e) {
if (e.key === "Enter") {
const btn = document.querySelector("button[type='submit']");
if (btn) {
btn.click();
}
}
});
});
// Form error handling
let errorTimer;
function throwError() {
clearTimeout(errorTimer);
document.querySelector(".error").classList.remove("hidden");
errorTimer = setTimeout(() => {
document.querySelector(".error").classList.add("hidden");
}, 3000);
}