generated from microverseinc/readme-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
334 lines (299 loc) · 10.6 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
const data = [
{
id: 'portfolio-1',
name: 'Booking App',
job: {
client: 'MICROVERSE',
role: 'Full Stack Dev',
year: '2022',
},
description: {
summary: 'This app uses a Rails back-end as an API to send doctor details and appointment data to the react frontend of a booking application.',
portfolio:
'This app uses a Rails back-end as an API to send doctor details and appointment data to the frontend of a booking application.',
},
image: {
mobile: './assets/portfolio/booking-mobile-1.png',
desktop: './assets/desktop/booking-desktop-1.png',
},
technologies: {
programingLanguage: 'JavaScript',
frontendLibrary: 'React',
stateManagment: 'Redux',
backendFramework: 'Rails',
authentication: 'Devise',
test: 'Jest,RSpec',
},
links: {
sourceCode: 'https://github.com/Melaku05/booking-app-backend',
demo: 'https://booking-app1.netlify.app',
},
card: 'card-img-left',
},
{
id: 'portfolio-2',
name: 'Tv Gallery',
job: {
client: 'MICROVERSE',
role: 'Full Stack Dev',
year: '2022',
},
description: {
summary: 'Gallerioni movies is an interactive movie streaming website were movie lovers interact with movies my commenting and liking.',
portfolio:
'Gallerioni movies is an interactive movie streaming website were movie lovers interact with movies my commenting and liking.',
},
image: {
mobile: './assets/portfolio/tv-gallery-mobile-2.png',
desktop: './assets/desktop/tv-gallery-desktop-2.png',
},
technologies: {
programingLanguage: 'JavaScript',
frontendLibrary: 'Linter',
stateManagment: 'bootstrap',
backendFramework: 'Api',
authentication: '',
test: 'jest',
},
links: {
sourceCode: 'https://github.com/Melaku05/JavaScript-capstone-project',
demo: 'https://github.com/Melaku05/JavaScript-capstone-project',
},
card: 'card-img-right',
},
{
id: 'portfolio-3',
name: 'Tonic',
job: {
client: 'MICROVERSE',
role: 'Full Stack Dev',
year: '2022',
},
description: {
summary: 'This website is mobile-friendly and has two pages: Home and Details. The home page lists the 194 countries with the COVID summary. The Details page shows the detailed COVID data of each country selected.',
portfolio:
'This website is mobile-friendly and has two pages: Home and Details. The home page lists the 194 countries with the COVID summary. The Details page shows the detailed COVID data of each country selected.',
},
image: {
mobile: './assets/portfolio/covid-mobile-3.png',
desktop: './assets/desktop/covid-desktop-3.png',
},
technologies: {
programingLanguage: 'JavaScript',
frontendLibrary: 'React',
stateManagment: 'Redux',
backendFramework: 'Api',
authentication: 'Redux-thunk',
test: 'jest',
},
links: {
sourceCode: 'https://github.com/Melaku05/booking-app-backend',
demo: 'https://booking-app1.netlify.app',
},
card: 'card-img-left',
},
{
id: 'portfolio-4',
name: 'E-commerce API ',
job: {
client: 'MICROVERSE',
role: 'Full Stack Dev',
year: '2022',
},
description: {
summary: 'The E-commerce API project and the project allow the opportunity for demand and supply to have a direct connection.',
portfolio:
'The E-commerce API project and the project allow the opportunity for demand and supply to have a direct connection. It was built with python, Django, Django Rest Framework, Djoser, Pytest, Redis, Celery, MYSQL, and PostgreSQL',
},
image: {
mobile: './assets/portfolio/ecommerce-mobile-4.png',
desktop: './assets/desktop/ecommerce-desktop-4.png',
},
technologies: {
programingLanguage: 'Python',
frontendLibrary: 'Django',
stateManagment: 'Celery,Redis',
backendFramework: 'Django-Rest',
authentication: 'Djoser',
test: 'Pytest',
},
links: {
sourceCode: 'https://github.com/Melaku05/Ecommerce_Api',
demo: '#',
},
card: 'card-img-left',
},
];
const hamburger = document.querySelector('#hamburger');
const close = document.querySelector('#close');
const navigation = document.querySelector('.nav-ul');
const textPortfolio = document.querySelector('.nav-text-1');
const about = document.querySelector('.nav-text-2');
const contact = document.querySelector('.nav-text-3');
// hamburger menu
hamburger.addEventListener('click', (e) => {
e.preventDefault();
navigation.classList.toggle('show');
hamburger.classList.add('hide');
close.classList.remove('hide');
textPortfolio.classList.add('menu-text');
about.classList.add('menu-text');
contact.classList.add('menu-text');
});
close.addEventListener('click', () => {
hamburger.classList.remove('hide');
navigation.classList.remove('show');
});
textPortfolio.addEventListener('click', (e) => {
e.stopPropagation();
navigation.classList.remove('show');
hamburger.classList.remove('hide');
});
about.addEventListener('click', (e) => {
e.stopPropagation();
navigation.classList.remove('show');
hamburger.classList.remove('hide');
});
contact.addEventListener('click', (e) => {
e.stopPropagation();
navigation.classList.remove('show');
hamburger.classList.remove('hide');
});
// popup
// dynamic html code from javascript
const portfolio = document.querySelector('#portfolio');
const modal = document.querySelector('#myModal');
portfolio.classList.add('works');
Array.from(portfolio.children).forEach((child, index) => {
child.innerHTML = `
<section class="${data[index].card}">
<ul>
<li><img src="${data[index].image.mobile}" alt="icon" class="img-1-1" /></li>
<li><img src="${data[index].image.desktop}" alt="icon" class="img-1-2" /></li>
</ul>
<div class="block-1">
<div class="text-group">
<h2 class="lg-text-2">${data[index].name}</h2>
<div class="client-info">
<h3 class="client">${data[index].job.client}</h3>
<a href="#"><img src="./assets/Counter.svg" alt="counter" /></a>
<h3 class="role">${data[index].job.role}</h3>
<a href="#"><img src="./assets/Counter.svg" alt="counter" /></a>
<h3 class="year-label">${data[index].job.year}</h3>
</div>
</div>
<h3 class="sm-text-2">${data[index].description.summary}</h3>
<ul class="tags">
<li>${data[index].technologies.programingLanguage}</li>
<li>${data[index].technologies.frontendLibrary}</li>
<li>${data[index].technologies.stateManagment}</li>
<li>${data[index].technologies.backendFramework}</li>
<li>${data[index].technologies.authentication}</li>
<li>${data[index].technologies.test}</li>
</ul>
<div class="actions" id="${data[index].id}">
<button class="btn" id="btn" type="button">See Project</button>
</div>
</div>
</section>`;
});
// modals
Array.from(portfolio.children).forEach((item, index) => {
item.firstElementChild.lastElementChild.lastElementChild.firstElementChild.addEventListener('click', () => {
modal.innerHTML = `
<!-- Modal content -->
<section class="modal-content">
<div class="popup-text-group">
<div class="text-group">
<h2 class="popup-text-lg">${data[index].name}</h2>
<div class="client-info">
<h3 class="client">${data[index].job.client}</h3>
<a href="#"><img src="./assets/Counter.svg" alt="counter" /></a>
<h3 class="role">${data[index].job.role}</h3>
<a href="#"><img src="./assets/Counter.svg" alt="counter" /></a>
<h3 class="year-label">${data[index].job.year}</h3>
</div>
</div>
<span class="close">×</span>
</div>
<ul>
<li><img src="${data[index].image.mobile}" alt="icon" class="img-1-1" /></li>
<li><img src="${data[index].image.desktop}" alt="icon" class="img-1-2 popup-img" /></li>
</ul>
<div class="popup-bottom">
<p class="popup-text-sm">${data[index].description.portfolio}</p>
<div class="popup-block">
<ul class="tags ${data[index].id}">
</ul>
<div class="popup-actions">
<button class="btn btnImg" id="btn" type="button"><a href="${data[index].links.demo}">See Live</a>
<img src="./assets/btnIcon-1.svg" alt="icon" id="imgIcon" />
</button>
<button class="btn btnImg" id="btn" type="button"> <a href="${data[index].links.sourceCode}">See Source</a>
<img src="./assets/cat.svg" alt="icon" id="imgIcon" />
</button>
</div>
</div>
</div>
</section>
`;
const ulList = document.querySelector('.popup-block .tags');
Object.keys(data[index].technologies).forEach((e) => {
ulList.innerHTML += `<li>${data[index].technologies[e]}</li>`;
});
modal.style.display = 'block';
const span = document.getElementsByClassName('close')[0];
span.addEventListener('click', () => {
modal.style.display = 'none';
});
window.addEventListener('click', (e) => {
if (e.target === modal) {
modal.style.display = 'none';
}
});
});
});
// form validation
const form = document.querySelector('.form');
const emailInput = form.elements.email;
const INPUT_LOWERCASE = 'Error : Please enter a lowercase input';
function showMessage(input, message, type) {
const msg = document.querySelector('.error-text');
msg.innerText = message;
input.className = type ? 'success' : 'error';
return type;
}
function showError(input, message) {
return showMessage(input, message, false);
}
function validateEmail(input, invalidLowercase) {
if (input.value === input.value.toLowerCase()) {
return true;
}
return showError(input, invalidLowercase);
}
// local storage
function saveUserDetails() {
const formData = new FormData(form);
const fullname = formData.get('fullname');
const email = formData.get('email');
const feedback = formData.get('feedback');
const myFormData = { name: fullname, email, feedback };
localStorage.setItem('myFormData', JSON.stringify(myFormData));
}
form.addEventListener('submit', (e) => {
e.preventDefault();
const emailValid = validateEmail(emailInput, INPUT_LOWERCASE);
if (emailValid) {
form.submit();
saveUserDetails();
}
});
const stored = localStorage.getItem('myFormData');
function getUserDetails(localObj) {
const userDetails = JSON.parse(localObj);
form.fullname.value = userDetails.name;
form.email.value = userDetails.email;
form.feedback.value = userDetails.feedback;
}
getUserDetails(stored);