-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
230 lines (213 loc) · 7.85 KB
/
script.js
File metadata and controls
230 lines (213 loc) · 7.85 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
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
const hamburger = document.querySelector('#hamb');
const navBar = document.querySelector('#mobile-navbar');
const body = document.querySelector('body');
const headline = document.querySelector('#headline');
const popup = document.querySelector('#popup');
const bg = document.querySelector('#popbg');
const work = document.querySelector('#work');
const close = document.querySelector('.close-btn');
const content = document.querySelector('#content h2');
const popImg = document.querySelector('#pop-img');
const popupProjType = document.querySelector('#content .proj-info .proj-type');
const popupProjCompany = document.querySelector(
'#content .proj-info .proj-company',
);
const popupProjYear = document.querySelector('#content .proj-info .proj-year');
const popupDescription = document.querySelector('#pop-description');
const liveLink = document.querySelector('.live-link');
const sourceLink = document.querySelector('.source-link');
const skillsList = document.querySelector('#popup-skills-buttons');
const form = document.getElementById('form-wrapper');
const errorMsg = document.getElementById('error-msg');
const email = document.querySelector('#email');
const personName = document.querySelector('#name');
const message = document.querySelector('#form-message-input');
const storage = window.localStorage;
const projects = [
{
name: 'Tonic',
description:
'A daily selection of privately personalized reads; no accounts or sign-ups required.',
projtype: 'Back End Developer',
projYear: '2015',
projCompany: 'Tonic',
image: './assets/SnapshootPortfolio.png',
technologies: ['html', 'css', 'javaScript', 'github'],
'live link': 'https://natanima.github.io/Microverse-Portfolio-Project/',
'source link': 'https://github.com/NatanimA/Microverse-Portfolio-Project',
},
{
name: 'Multi-Post Stories',
description:
'Experimental content creation feature that allows users to add to an existing story over the course of a day without spamming their friends.',
projtype: 'Full Stack Dev',
projYear: '2015',
projCompany: 'Facebook',
image: './assets/SnapshootPortfolio2.png',
technologies: ['html', 'ruby on rails', 'css', 'javascript'],
'live link': 'https://natanima.github.io/Microverse-Portfolio-Project/',
'source link': 'https://github.com/NatanimA/Microverse-Portfolio-Project',
},
{
name: 'Facebook-360',
description:
'Exploring the future of media in Facebook first Virtual Reality app; a place to discover and enjoy 360 photos and videos on Gear VR.',
projtype: 'Full Stack Dev',
projYear: '2015',
projCompany: 'Facebook',
image: './assets/SnapshootPortfolio3.png',
technologies: ['html', 'ruby on rails', 'css', 'javascript'],
'live link': 'https://natanima.github.io/Microverse-Portfolio-Project/',
'source link': 'https://github.com/NatanimA/Microverse-Portfolio-Project',
},
{
name: 'Uber Navigations',
description:
'A smart assistant to make driving more safe, efficient, and fun by unlocking your most expensive computer: your car.',
projtype: 'Lead Developer',
projYear: '2018',
projCompany: 'Uber',
image: './assets/SnapshootPortfolio4.png',
technologies: ['html', 'ruby on rails', 'css', 'javascript'],
'live link': 'https://natanima.github.io/Microverse-Portfolio-Project/',
'source link': 'https://github.com/NatanimA/Microverse-Portfolio-Project',
},
];
projects.forEach((project) => {
const projectContainer = document.createElement('div');
projectContainer.className = 'project';
projectContainer.innerHTML = `<img class="project-picture" src="${
project.image
}" alt="project screenshot"> <div class="proj-div"> <h2 class="proj-title">${
project.name
}</h2> <p class="proj-info"> <span class="proj-company">${
project.projCompany
}</span> <span><img src="./assets/Counter.png" alt=" "></span> <span class="proj-type">${
project.projtype
}</span> <span><img src="./assets/Counter.png" alt=" "></span> <span class="proj-year">${
project.projYear
}</span> </p> <p class="proj-description">${
project.description
}</p> <ul class="proj-lang">${project.technologies
.map((tech) => `<li class='lang'>${tech}</li>`)
.join('')}</ul> <button class="enabled-btn">See Project</button> </div>`;
work.appendChild(projectContainer);
});
const ul = document.createElement('ul');
ul.className = 'proj-lang';
skillsList.prepend(ul);
function popupDetailsWindow(index) {
ul.innerHTML = '';
content.innerText = projects[index].name;
popImg.src = projects[index].image;
popupDescription.innerText = projects[index].description;
popupProjType.innerText = projects[index].projtype;
popupProjCompany.innerText = projects[index].projCompany;
popupProjYear.innerText = projects[index].projYear;
projects[index].technologies.forEach((skill) => {
const li = document.createElement('li');
li.className = 'lang';
li.innerText = skill;
ul.appendChild(li);
});
liveLink.href = projects[index]['live link'];
sourceLink.href = projects[index]['source link'];
}
const projectBtn = document.querySelectorAll('.project .enabled-btn');
projectBtn.forEach((btn) => btn.addEventListener('click', () => {
popup.classList.add('active');
body.classList.add('active');
bg.classList.add('active');
popupDetailsWindow(Array.prototype.indexOf.call(projectBtn, btn));
}));
close.addEventListener('click', () => {
popup.classList.remove('active');
body.classList.remove('active');
bg.classList.remove('active');
});
hamburger.addEventListener('click', () => {
headline.classList.toggle('active');
hamburger.classList.toggle('active');
navBar.classList.toggle('active');
body.classList.toggle('active');
});
document.querySelectorAll('.mobile-nav-link').forEach((link) => link.addEventListener('click', () => {
headline.classList.remove('active');
hamburger.classList.remove('active');
navBar.classList.remove('active');
body.classList.remove('active');
}));
form.addEventListener('submit', (event) => {
event.preventDefault();
if (event.target[1].value === event.target[1].value.toLowerCase()) {
form.submit();
} else {
email.classList.add('active');
errorMsg.innerText = "Please Enter E-mail with lowercase like 'abcd@gmail.com'";
}
});
const inputData = {
personName: '',
email: '',
message: '',
};
function storageAvailable(type) {
let storage;
try {
storage = window[type];
const x = '__storage_test__';
storage.setItem(x, x);
storage.removeItem(x);
return true;
} catch (e) {
const { code, name } = e;
return (
e instanceof DOMException
&& (code === 22
|| code === 1014
|| name === 'QuotaExceededError'
|| name === 'NS_ERROR_DOM_QUOTA_REACHED')
&& storage.length !== 0
);
}
}
personName.addEventListener('change', () => {
inputData.personName = personName.value;
inputData.email = email.value;
inputData.message = message.value;
storage.setItem('formData', JSON.stringify(inputData));
});
email.addEventListener('change', () => {
inputData.email = email.value;
inputData.message = message.value;
storage.setItem('formData', JSON.stringify(inputData));
});
message.addEventListener('change', () => {
inputData.personName = personName.value;
inputData.email = email.value;
inputData.message = message.value;
storage.setItem('formData', JSON.stringify(inputData));
});
function retrieveForm() {
if (storageAvailable('localStorage')) {
const formDataInput = storage.getItem('formData');
const formData = JSON.parse(formDataInput);
return formData;
}
return null;
}
function populateFormData() {
const formData = retrieveForm();
if (formData) {
if (formData.personName) {
personName.value = formData.personName;
}
if (formData.email) {
email.value = formData.email;
}
if (formData.message) {
message.value = formData.message;
}
}
}
populateFormData();