generated from microverseinc/readme-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
205 lines (186 loc) · 6.7 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
const hamMenu = document.querySelector('.ham-menu');
const mobileMenu = document.querySelector('.mobile-menu');
const closeMenu = document.querySelector('.close-icon');
const mobileLinks = document.querySelectorAll('.mobile-link');
const workSection = document.querySelector('.work-section');
const works = [
{
title: 'To-Do List',
image: 'assets/snapshot-1.png',
description:
'A simple to-do list app that allows you to add, edit and delete tasks. It also allows you to mark tasks as complete.',
tags: ['HTML', 'CSS', 'JAVASCRIPT', 'WEBPACK', 'JEST'],
live: 'https://10-menachi.github.io/todo-list/dist/',
source: 'https://github.com/10-menachi/todo-list',
},
{
title: 'Bartending Competition Website',
image: 'assets/snapshot-2.png',
description:
'A website for a bartending competition. It is a simple UI for a competition that allows bartenders to register and submit their recipes.',
tags: ['HTML', 'CSS', 'JAVASCRIPT'],
live: 'https://10-menachi.github.io/capstone',
source: 'https://github.com/10-menachi/capstone',
},
];
const createWork = (work, index) => {
const workDiv = document.createElement('div');
workDiv.classList.add('card');
workDiv.classList.add('card-1');
workDiv.innerHTML = `
<div class="left">
<img
src="${work.image}"
alt="Project Snapshot"
class="snap"
/>
</div>
<div class="right">
<h1>${work.title}</h1>
<div class="canopy">
<h4>Canopy</h4>
<img src="assets/circle.png" alt="Circle" />
<h5>Back End Dev</h5>
<img src="assets/circle.png" alt="Circle" />
<h5>2015</h5>
</div>
<p>${work.description}</p>
<ul>
${work.tags.map((tag) => `<li>${tag}</li>`).join('')}
</ul>
<button class="work-button button" id="${index}">See Project</button>
</div>
`;
return workDiv;
};
const form = document.querySelector('.contact-form');
const email = document.querySelector('.email');
const errorContainer = document.createElement('div');
hamMenu.addEventListener('click', () => {
mobileMenu.classList.toggle('active');
});
closeMenu.addEventListener('click', () => {
mobileMenu.classList.toggle('active');
});
mobileLinks.forEach((link) => {
link.addEventListener('click', () => {
mobileMenu.classList.toggle('active');
});
});
works.forEach((work, index) => {
workSection.appendChild(createWork(work, index));
});
const popupCard = (work) => {
const popup = document.createElement('div');
popup.classList.add('popup');
popup.innerHTML = `
<div class="popup-content">
<div class="popup-header">
<div class="left-side">
<h1>${work.title}</h1>
<div class="canopy">
<h4>Canopy</h4>
<img src="assets/circle.png" alt="Circle" />
<h5>Back End Dev</h5>
<img src="assets/circle.png" alt="Circle" />
<h5>2015</h5>
</div>
</div>
<div class="right-side">
<i class="fas fa-times popup-close"></i>
</div>
</div>
<div class="popup-left">
<img src="${work.image}" alt="Project Snapshot" class="snapshot" />
</div>
<div class="popup-right">
<p>${work.description}</p>
<div class="popup-tags">
<ul>
${work.tags.map((tag) => `<li>${tag}</li>`).join('')}
</ul>
<div class="line"></div>
<div class="popup-buttons">
<a href="${work.live}" class="popup-button button">See Live <img src="assets/Icon.png" alt="External Link" /></a>
<a href="${work.source}" class="popup-button button">See Source <img src="assets/github.png" alt="Github" /></a>
</div>
<div class="next-and-prev">
<button type="button" class="prev-button button"><i class="fas fa-chevron-left"></i> Previous</button>
<button type="button" class="next-button button">Next <i class="fas fa-chevron-right"></i></button>
</div>
</div>
</div>
</div>
`;
const showNextWork = (currentWork) => {
if (currentWork !== works[works.length - 1]) {
const currentIndex = works.indexOf(currentWork);
const nextIndex = (currentIndex + 1) % works.length;
const nextWork = works[nextIndex];
popup.replaceWith(popupCard(nextWork));
}
};
const showPrevWork = (currentWork) => {
if (currentWork !== works[0]) {
const currentIndex = works.indexOf(currentWork);
const prevIndex = (currentIndex - 1 + works.length) % works.length;
const prevWork = works[prevIndex];
popup.replaceWith(popupCard(prevWork));
}
};
// Attach event listeners to next and previous buttons
const nextButton = popup.querySelector('.next-button');
nextButton.addEventListener('click', () => showNextWork(work));
const prevButton = popup.querySelector('.prev-button');
prevButton.addEventListener('click', () => showPrevWork(work));
// Attach event listener to close button
const closeButton = popup.querySelector('.popup-close');
closeButton.addEventListener('click', () => popup.remove());
return popup;
};
const buttons = document.querySelectorAll('.work-button');
buttons.forEach((button) => {
button.addEventListener('click', (e) => {
const work = works[e.target.id];
const popup = popupCard(work);
document.body.appendChild(popup);
});
});
form.addEventListener('submit', (e) => {
if (email.value !== email.value.toLowerCase()) {
e.preventDefault();
email.setCustomValidity('Email must be in lowercase');
form.appendChild(errorContainer);
errorContainer.textContent = 'Email must be in lowercase';
errorContainer.style.color = '#fff';
errorContainer.style.fontSize = '0.8rem';
errorContainer.style.padding = '1rem';
errorContainer.style.backgroundColor = 'red';
errorContainer.style.borderRadius = '0.5rem';
}
});
email.addEventListener('input', () => {
email.setCustomValidity('');
});
const name = document.querySelector('.name');
const message = document.querySelector('textarea');
const getDataFromStorage = () => {
const storageData = JSON.parse(localStorage.getItem('data'));
if (storageData) {
name.value = storageData.name;
email.value = storageData.email;
message.value = storageData.message;
}
};
const saveDataToStorage = () => {
const data = {
name: name.value,
email: email.value,
message: message.value,
};
localStorage.setItem('data', JSON.stringify(data));
};
name.addEventListener('input', saveDataToStorage);
email.addEventListener('input', saveDataToStorage);
message.addEventListener('input', saveDataToStorage);
window.addEventListener('load', getDataFromStorage);