Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
111 lines (101 loc) · 3.54 KB
/
Copy pathscript.js
File metadata and controls
111 lines (101 loc) · 3.54 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
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
//Create portfolio object
const portfolio = {};
// Hamburger Nav Function
portfolio.hamNavToggle = () => {
// Hamburger nav slide-out toggle
hamNavToggle = document.querySelector(".hamNavIcon");
portfolio.hamNav = document.querySelector(".hamNav");
hamNavToggle.addEventListener("click", () => {
portfolio.hamNav.classList.toggle("openNav");
});
// Remove Hamburger Nav from view once links are clicked
const hamLinks = document.querySelectorAll(".hamLinks");
hamLinks.forEach(hamLinks => {
hamLinks.addEventListener('click', () => portfolio.hamNav.classList.remove("openNav"))
});
};
// Typewriter Function
portfolio.typeWriter = () => {
const text = document.querySelector(".secondText");
const textAnimation = () => {
setTimeout(() => {
text.textContent = "Musician"
}, 0);
setTimeout(() => {
text.textContent = "Educator"
}, 3000);
setTimeout(() => {
text.textContent = "Creator"
}, 6000);
setTimeout(() => {
text.textContent = "Learner"
}, 9000);
setTimeout(() => {
text.textContent = "Cat-Mom"
}, 12000);
}
textAnimation();
setInterval(textAnimation, 15000);
// changed from 15000, but technically, not sure why the logic is flawed since the entire function re-runs every 15 seconds...
};
//Contact Form - Prevent Default Behavior
portfolio.formSubmission = () => {
const form = document.getElementById("myForm");
const input = document.querySelectorAll(".input");
async function handleSubmit(event) {
event.preventDefault();
input.textContent = "";
const status = document.getElementById("myFormStatus");
const data = new FormData(event.target);
fetch(event.target.action, {
method: form.method,
body: data,
headers: {
'Accept': 'application/json'
}
}).then(response => {
if (response.ok) {
status.innerHTML = "Thank you for your message!";
status.classList.add("success")
form.reset()
} else {
response.json().then(data => {
if (Object.hasOwn(data, 'errors')) {
status.innerHTML = data["errors"].map(error => error["message"]).join(", ")
} else {
status.innerHTML = "Oops! There was a problem. Please try again."
status.classList.add("error")
}
})
}
}).catch(error => {
status.innerHTML = "Oops! There was a problem. Please try again."
status.classList.add("error")
});
}
form.addEventListener("submit", handleSubmit)
};
//Toggle nightmode and daymode
portfolio.nightMode = () => {
const icon = document.getElementById("icon");
const body = document.querySelector("body");
const img = document.querySelector(".catImg")
icon.onclick = () => {
body.classList.toggle("nightMode");
if (document.body.classList.contains("nightMode")){
icon.src = "assets/dayIcon.png"
img.src = "assets/orangeRun.gif"
} else {
icon.src = "assets/nightIcon.png"
img.src = "assets/orangeSleep.gif"
}
}
}
//init function
portfolio.init = () => {
portfolio.hamNavToggle();
portfolio.typeWriter();
portfolio.formSubmission();
portfolio.nightMode();
}
portfolio.init();