-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
289 lines (271 loc) · 12.5 KB
/
script.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
/* Open when someone clicks on the span element */
function openNav() {
document.getElementById('myNav').style.width = '100%';
}
/* Close when someone clicks on the 'x' symbol inside the overlay */
function closeNav() {
document.getElementById('myNav').style.width = '0%';
}
// Fetch html elements
const closeBtn = document.getElementById('close-btn');
const hamMenu = document.getElementById('ham-button');
// This returns an HTML collection that needs to be browsed.
const hamItem = document.getElementsByClassName('menu-item');
// Event listeners
closeBtn.addEventListener('click', () => {
closeNav();
});
hamMenu.addEventListener('click', () => {
openNav();
});
// Iterating the hamItem HTMLCollection
for (let index = 0; index < hamItem.length; index += 1) {
hamItem[index].addEventListener('click', () => {
closeNav();
});
}
// Project strucuture
const project1 = {
name: 'Leaderboard',
description: 'Leaderboard app that interacts with an API for the purpose of practicing async Javascript.',
content:
'Leaderboard app that interacts with an API for the purpose of practicing async Javascript. It was built with vanilla JS, Webpack and has a testing suite built with Jest.',
featuredImage: './images/lead-thumb.png',
technologies: ['Javascript', 'Webpack', 'Jest'],
liveVersionLink: '#',
sourceLink: 'https://github.com/lu-jim/leaderboard',
tags: ['Microverse', 'Full Stack Dev', '2021'],
};
const project2 = {
name: 'Math Magicians',
description:
'Math magicians is a website for all fans of mathematics. It is a Single Page App (SPA) that allows users to: Make simple calculations. Read a random math-related quote.',
content:
'Math magicians is a website for all fans of mathematics. It is a Single Page App (SPA) built with React that allows users to: Make simple calculations. Read a random math-related quote. Built With - HTML&CSS - Javascript - React',
featuredImage: './images/mathmag-thumb-sq.png',
technologies: ['Javascript', 'React', 'Jest', 'Netlify'],
liveVersionLink: 'https://vigorous-kalam-1fde6b.netlify.app/',
sourceLink: 'https://github.com/lu-jim/math-magicians',
tags: ['Microverse', 'Full Stack Dev', '2021'],
};
const project3 = {
name: "Space Travelers' Hub",
description:
'App for a company that provides commercial and scientific space travel services. The application will allow users to book rockets and join selected space missions.',
content:
'App for a company that provides commercial and scientific space travel services. The application will allow users to book rockets and join selected space missions. Built With \n -Javascript \n -React \n -Redux \n -Bootstrap',
featuredImage: './images/space-th-sq.png',
technologies: ['Javascript', 'Heroku', 'React', 'Redux'],
liveVersionLink: 'https://cheerful-chimera-e6e9d9.netlify.app',
sourceLink: 'https://github.com/lu-jim/space-hub',
tags: ['Microverse', 'Full Stack Dev', '2021'],
};
const project4 = {
name: 'Recipes on Rails',
description:
'The Recipe app keeps track of all your recipes, ingredients, and inventory. It will allow you to save ingredients, keep track of what you have, create recipes, and generate a shopping list based on what you have and what you are missing from a recipe.',
content:
'The Recipe app keeps track of all your recipes, ingredients, and inventory. It will allow you to save ingredients, keep track of what you have, create recipes, and generate a shopping list based on what you have and what you are missing from a recipe. Built With \n -Ruby \n -Rails \n -Tailwind \n -Postgres',
featuredImage: './images/recipe-thumb.png',
technologies: ['Ruby', 'Rails', 'Heroku', 'Postgres', 'Tailwind'],
liveVersionLink: 'https://recipes-on-rails.fly.dev/',
sourceLink: 'https://github.com/lu-jim/recipes-on-rails',
tags: ['Microverse', 'Full Stack Dev', '2022'],
};
const works = [project1, project2, project3, project4].reverse();
// Setting up the Works section:
// Helper functions
function createNode(type, nodeClass) {
const node = document.createElement(type);
if (nodeClass) node.className = nodeClass;
return node;
}
// Create button
function createButton(content, location, className, id) {
const button = createNode('button', className);
button.innerHTML = content;
button.sourceLink = '#';
button.id = id;
location.appendChild(button);
}
function showWork(referenceNode) {
const portfolio = createNode('section', 'works');
portfolio.id = 'portfolio';
referenceNode.parentNode.insertBefore(portfolio, referenceNode);
works.forEach((project) => {
const cardDiv = createNode('article', `card card-${works.indexOf(project)}`);
portfolio.appendChild(cardDiv);
const cardImg = cardDiv.appendChild(createNode('img', 'project-image'));
cardImg.src = project.featuredImage;
const cardContent = cardDiv.appendChild(createNode('div', 'card-content'));
const cardHeader = cardContent.appendChild(createNode('div', 'card-headers'));
const cardH2 = cardHeader.appendChild(createNode('h2'));
cardH2.innerHTML = `<a href='#' class='project-title'>${project.name}</a>`;
const cardCategories = cardHeader.appendChild(createNode('div', 'card-categories'));
const mainCategory = cardCategories.appendChild(createNode('a', 'main-category'));
mainCategory.innerHTML = `<a href='#' class='main-category'>${project.tags[0]}</a>`;
const divider = cardCategories.appendChild(createNode('img', 'counter-card'));
divider.src = './resources/Counter.svg';
divider.alt = 'counter';
const secCategory = cardCategories.appendChild(createNode('a', 'sec-category'));
secCategory.innerHTML = `<a href='#' class='sec-category'>${project.tags[1]}</a>`;
const divider2 = cardCategories.appendChild(createNode('img', 'counter-card'));
divider2.src = './resources/Counter.svg';
divider2.alt = 'counter';
const secCategory1 = cardCategories.appendChild(createNode('a', 'sec-category'));
secCategory1.innerHTML = `<a href='#' class='sec-category'>${project.tags[2]}</a>`;
const cardText = cardContent.appendChild(createNode('p'));
cardText.innerHTML = project.description;
const hashtagCard = cardContent.appendChild(createNode('ul', 'hashtag-card'));
project.technologies.forEach((element) => {
const argument = `<li><a href="#" class="hashtag">${element}</a></li>`;
const currentTag = hashtagCard.appendChild(createNode('li', 'hashtag'));
currentTag.innerHTML = argument;
});
createButton('See Project', cardContent, 'see-project', `btn-modal-${works.indexOf(project)}`);
});
}
// Create modal
function createModal(project, modalId) {
const newModal = createNode('div', 'modal');
newModal.id = `modal-${modalId}`;
const modalContent = newModal.appendChild(createNode('div', 'modal-content animation effects'));
// Modal Header
const modalHeader = modalContent.appendChild(createNode('div', 'modal-header'));
const modalHeaderLeft = modalHeader.appendChild(createNode('div', 'modal-header-left'));
const modalHeaderRight = modalHeader.appendChild(createNode('div', 'modal-header-right'));
const modalHeaderRightX = modalHeaderRight.appendChild(createNode('span', 'close'));
modalHeaderRightX.innerHTML = 'x';
modalHeaderRightX.id = `modal-close-${modalId}`;
const modalHeaderLeftTitle = modalHeaderLeft.appendChild(createNode('h2', 'modal-header-left-title'));
modalHeaderLeftTitle.innerHTML = project.name;
const modalHeaderLeftCategories = modalHeaderLeft.appendChild(createNode('div', 'card-categories'));
const modalHeaderCategoryMain = modalHeaderLeftCategories.appendChild(createNode('a', 'main-category'));
const mainTag = project.tags[0];
const secTag1 = project.tags[1];
const secTag2 = project.tags[2];
modalHeaderCategoryMain.innerHTML = mainTag;
const modalHeaderDivider = modalHeaderLeftCategories.appendChild(createNode('img', 'counter-card'));
modalHeaderDivider.src = './resources/Counter.svg';
modalHeaderDivider.alt = 'counter';
const modalHeaderCategorySec = modalHeaderLeftCategories.appendChild(createNode('a', 'sec-category'));
modalHeaderCategorySec.innerHTML = secTag1;
const modalHeaderDivider2 = modalHeaderLeftCategories.appendChild(createNode('img', 'counter-card'));
modalHeaderDivider2.src = './resources/Counter.svg';
const modalHeaderCategorySec2 = modalHeaderLeftCategories.appendChild(createNode('a', 'sec-category'));
modalHeaderCategorySec2.innerHTML = secTag2;
// Modal body
const modalBody = modalContent.appendChild(createNode('div', 'modal-body'));
const modalImage = modalBody.appendChild(createNode('img', 'project-image modal-image'));
modalImage.src = project.featuredImage;
const modalText = modalBody.appendChild(createNode('div', 'modal-text'));
const modalTextLeft = modalText.appendChild(createNode('p', 'modal-text-left'));
modalTextLeft.innerHTML = project.content;
const modalTextRight = modalText.appendChild(createNode('div', 'modal-text-right'));
const modalHashtag = modalTextRight.appendChild(createNode('ul', 'hashtag-card hashtag-modal'));
project.technologies.forEach((element) => {
modalHashtag.appendChild(createNode('li')).innerHTML = `<a href="#" class="hashtag">${element}</a>`;
});
modalTextRight.appendChild(createNode('hr', 'modal-divider'));
const modalButtons = modalTextRight.appendChild(createNode('div', 'modal-buttons'));
const imageButton1Content = `<a href="${project.liveVersionLink}" target="_blank">See live</a> <img class= 'image-button' src='./resources/seelive.svg'>`;
createButton(imageButton1Content, modalButtons, 'see-project modal-button-inside');
const imageButton2 = createNode('a', 'modal-button-image');
imageButton2.src = './resources/gitblue.svg';
const imageButton2Content = `<a href="${project.sourceLink}" target="_blank">See Source</a> <img class= 'image-button' src='./resources/gitblue.svg'>`;
createButton(imageButton2Content, modalButtons, 'see-project modal-button-inside');
document.body.appendChild(newModal);
}
// Iterate modal creation
works.forEach((project) => {
createModal(project, works.indexOf(project));
});
// Append section insertBefore, which inserts the node given as the first argument
// before the node given as the second argument.
const aboutNode = document.getElementById('about');
showWork(aboutNode);
// aboutNode.parentNode.insertBefore(portfolioNode, aboutNode);
// Modal setup
const modal0 = document.getElementById('modal-0');
const modal1 = document.getElementById('modal-1');
const modal2 = document.getElementById('modal-2');
const modal3 = document.getElementById('modal-3');
// Fetch opening and closing
const btnModal0 = document.getElementById('btn-modal-0');
const btnModal1 = document.getElementById('btn-modal-1');
const btnModal2 = document.getElementById('btn-modal-2');
const btnModal3 = document.getElementById('btn-modal-3');
const btnClose0 = document.getElementById('modal-close-0');
const btnClose1 = document.getElementById('modal-close-1');
const btnClose2 = document.getElementById('modal-close-2');
const btnClose3 = document.getElementById('modal-close-3');
// Open and close Modal
function openModal0() {
modal0.style.display = 'flex';
}
function openModal1() {
modal1.style.display = 'flex';
}
function openModal2() {
modal2.style.display = 'flex';
}
function openModal3() {
modal3.style.display = 'flex';
}
function closeModal0() {
modal0.style.display = 'none';
}
function closeModal1() {
modal1.style.display = 'none';
}
function closeModal2() {
modal2.style.display = 'none';
}
function closeModal3() {
modal3.style.display = 'none';
}
btnClose0.onclick = closeModal0();
btnClose1.onclick = closeModal1();
btnClose2.onclick = closeModal2();
btnClose3.onclick = closeModal3();
// Event Listeners
btnModal0.addEventListener('click', () => {
openModal0();
});
btnModal1.addEventListener('click', () => {
openModal1();
});
btnModal2.addEventListener('click', () => {
openModal2();
});
btnModal3.addEventListener('click', () => {
openModal3();
});
btnClose0.addEventListener('click', () => {
closeModal0();
});
btnClose1.addEventListener('click', () => {
closeModal1();
});
btnClose2.addEventListener('click', () => {
closeModal2();
});
btnClose3.addEventListener('click', () => {
closeModal3();
});
document.addEventListener(
'click',
(event) => {
// If user either clicks X button OR clicks outside
// the modal window, then close modal by calling closeModal()
if (event.target === modal0
|| event.target === modal1 || event.target === modal2 || event.target === modal3) {
closeModal0();
closeModal1();
closeModal2();
closeModal3();
}
},
false,
);
// Create modal