-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
371 lines (321 loc) · 13.1 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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
import { trainingMatrix } from "./training.js";
// Set footer
const footer = async () => {
const footerData = await fetch('/footer.html');
const text = await footerData.text();
document.getElementById('footer-container').innerHTML = text;
document.getElementById('footer-text').innerHTML = `${new Date().getFullYear()} © Jay Clark<br>All rights reserved</p> `
};
footer();
// Tech Stack
const stack = [
{ name: "Android SDK", url: "android.png", dimension:"height", competence: 1 },
{ name: "Angular", url: "angular.png", competence: 1 },
{ name: "AWS", url: "aws.png", competence: 1 },
{ name: "Azure", url: "azure.png", competence: 1 },
{
name: "Bootstrap",
url: "bootstrap.png",
dimension: "height",
competence: 1,
},
{ name: "C", url: "c.png", dimension: "height", competence: 1 },
{ name: "C++", url: "cplusplus.png", dimension: "height", competence: 1 },
{ name: "C#", url: "csharp.png", competence: 1 },
{ name: "Chrome Extensions", url: "chromeextension.png", competence: 1 },
{ name: "Cypress", url: "cypress.png", competence: 1 },
{ name: "D3", url: "d3.png", competence: 1 },
{ name: "Dart", url: "dart.png", competence: 1 },
{ name: "Deluge", url: "deluge.jpeg", competence: 1 },
{ name: "Django", url: "django.png", competence: 1 },
{ name: "Docker", url: "docker.png", competence: 1 },
{ name: "Electron", url: "electron.png", competence: 1 },
{ name: "EJS", url: "ejs.png", competence: 1 },
{ name: "Firebase", url: "firebase.png", competence: 1 },
{ name: "Flask", url: "flask.png", competence: 1 },
{ name: "Gatsby", url: "gatsby.png", competence: 1 },
{ name: "Git", url: "git.png", competence: 3 },
{ name: "Go", url: "go.png", competence: 1 },
{ name: "Gradle", url: "gradle.png", competence: 1 },
{ name: "Java", url: "java.png", competence: 1 },
{ name: "JavaScript", url: "javascript.png", competence: 4 },
{ name: "Jekyll", url: "jekyll.png", competence: 1 },
{ name: "Jest", url: "jest.png", competence: 3 },
{ name: "Jinja", url: "jinja.png", competence: 1 },
{ name: "Heroku", url: "heroku.png", competence: 1 },
{ name: "Laravel", url: "laravel.png", competence: 1 },
{ name: "MySQL", url: "mysql.png", competence: 1 },
{ name: "PHP", url: "php.png", competence: 1 },
{ name: "Postgres", url: "postgresql.png", competence: 1 },
{ name: "Puppeteer", url: "puppeteer.png", competence: 1 },
{ name: "Python", url: "python.png", competence: 1 },
{ name: "QT", url: "qt.png", competence: 1 },
{ name: "Ruby", url: "ruby.png", competence: 2 },
{ name: "Ruby on Rails", url: "rails.png", competence: 2 },
{ name: "SASS", url: "sass.png", competence: 1 },
{ name: "Strapi", url: "strapi.png", competence: 1 },
{ name: "Tailwind", url: "tailwindcss.svg", competence: 1 },
{ name: "TravisCI", url: "travisci.png", competence: 1 },
{ name: "Typescript", url: "typescript.png", competence: 1 },
{ name: "Unity", url: "unity.png", dimenson: "height", competence: 1 },
{ name: "Vue", url: "vuejs.svg", competence: 1 },
{ name: "Wix", url: "wix.png", competence: 1 },
{ name: "Wordpress", url: "wordpress.png", competence: 1 },
{ name: "XCode", url: "xcode.png", competence: 1 },
{ name: "Yeoman", url: "yeoman.png", competence: 1 },
]
// Set display consts
const cardWidth = 170;
const imgHeight = 100;
const ribbonHeight = 135;
const arrowWidth = 20;
let startingCard = 0;
let cardsToDisplay = Math.floor((window.innerWidth * 0.8 - 40) / cardWidth);
let scrollInProgress = false;
function Card({name, url, competence, dimension}) {
const div = document.createElement('div');
div.style.width = cardWidth + 'px';
div.style.padding = "0px 10px";
const imgDiv = document.createElement('div');
imgDiv.style.margin = "auto 0px";
imgDiv.style.height = imgHeight;
imgDiv.style.maxHeight = imgHeight;
imgDiv.style.overflow = "hidden";
imgDiv.style.display = "flex";
imgDiv.style.justifyContent = "center";
imgDiv.style.alignItems = "center";
imgDiv.innerHTML = `<div style="border: 1px solid #666; padding: 10px; border-radius: 4px; text-align: center; margin: auto 0px"><b>${name}</b></div>`;
if (url) {
const image = document.createElement('img');
image.src = url;
image.alt = name;
if (dimension === "height") {
image.height = 100;
} else {
image.width = 100;
}
imgDiv.innerHTML = '';
imgDiv.appendChild(image);
}
const ratingDiv = document.createElement('div');
ratingDiv.style.display = "flex";
ratingDiv.style.flexWrap = "nowrap";
ratingDiv.style.justifyContent = "center";
const rating1 = document.createElement('div');
const rating2 = document.createElement('div');
const rating3 = document.createElement('div');
const rating4 = document.createElement('div');
rating1.style.margin = "25px 2px 5px 2px";
rating1.style.boarder = "1px solid #666";
rating1.style.width = "10px";
rating1.style.height = "10px";
rating1.style.backgroundColor = competence >= 1 ? "green" : "#ccc";
rating2.style.margin = "20px 2px 5px 2px";
rating2.style.boarder = "1px solid #666";
rating2.style.width = "10px";
rating2.style.height = "15px";
rating2.style.backgroundColor = competence >= 2 ? "green" : "#ccc";
rating3.style.margin = "15px 2px 5px 2px";
rating3.style.boarder = "1px solid #666";
rating3.style.width = "10px";
rating3.style.height = "20px";
rating3.style.backgroundColor = competence >= 3 ? "green" : "#ccc";
rating4.style.margin = "10px 2px 5px 2px";
rating4.style.boarder = "1px solid #666";
rating4.style.width = "10px";
rating4.style.height = "25px";
rating4.style.backgroundColor = competence >= 4 ? "green" : "#ccc";
ratingDiv.appendChild(rating1);
ratingDiv.appendChild(rating2);
ratingDiv.appendChild(rating3);
ratingDiv.appendChild(rating4);
div.append(imgDiv);
div.append(ratingDiv);
return div;
}
function sliceCards(cards) {
if (startingCard + cardsToDisplay > cards.length) {
return [...cards.slice(startingCard), ...cards.slice(0, startingCard + cardsToDisplay - cards.length)];
}
return cards.slice(startingCard, startingCard + cardsToDisplay);
}
function Ribbon(cards) {
const ribbonDiv = document.createElement('div');
ribbonDiv.style.display = "flex";
ribbonDiv.style.flexWrap = "nowrap";
ribbonDiv.style.justifyContent = "center";
ribbonDiv.style.alignItems = "center";
const arrowLeft = document.createElement('div');
arrowLeft.style.width = arrowWidth + "px";
arrowLeft.style.height = ribbonHeight + "px";
arrowLeft.style.display = "flex";
arrowLeft.style.justifyContent = "center";
arrowLeft.style.alignItems = "center";
arrowLeft.style.backgroundColor = "#ddd";
arrowLeft.addEventListener('click', () => {
if (scrollInProgress) return;
scrollInProgress = true;
// Set new starting card
if (startingCard >= cardsToDisplay) {
startingCard = startingCard - cardsToDisplay;
} else {
startingCard = cards.length - cardsToDisplay - startingCard;
}
// Get old div and its parent
const oldCards = Array.from(document.getElementsByClassName('tech-cards'));
const oldCardsParent = oldCards[0].parentElement;
while (oldCards.length > 1) {
oldCardsParent.removeChild(oldCards[0]);
oldCards.shift();
}
// Create new div and append to ribbon
const newCards = document.createElement('div');
newCards.style.display = "flex";
newCards.style.position = "absolute";
newCards.style.flexWrap = "nowrap";
newCards.style.justifyContent = "center";
newCards.style.alignItems = "center";
newCards.style.transition = "left 0.8s ease";
newCards.classList.add('tech-cards');
sliceCards(cards).forEach(card=>{
const tempDiv = Card(card);
newCards.append(tempDiv);
})
newCards.style.left = (-1 * cardWidth * cardsToDisplay) + 'px';
oldCardsParent.appendChild(newCards);
// Move both to the right
setTimeout(() => {
newCards.style.left = "0px";
oldCards[0].style.left = cardsToDisplay * cardWidth + "px";
}, 20);
setTimeout(() => {scrollInProgress = false}, 500);
// Remove old div
setTimeout(()=> {
oldCards[0].classList.add("old-cards");
const old = Array.from(oldCardsParent.getElementsByClassName("old-cards"));
old.forEach(el => {
oldCardsParent.removeChild(el);
});
}, 900);
})
const arrowImgL = document.createElement('img');
arrowImgL.src = "@/assets/chevron-left.svg";
arrowLeft.appendChild(arrowImgL);
ribbonDiv.appendChild(arrowLeft)
const cardsContainer = document.createElement('div');
cardsContainer.style.display = "flex";
cardsContainer.style.overflow = "hidden";
cardsContainer.style.position = "relative";
cardsContainer.style.width = (cardWidth * cardsToDisplay) + 'px';
cardsContainer.style.height = ribbonHeight + 'px';
const cardsDiv = document.createElement('div');
cardsDiv.style.position = "absolute";
cardsDiv.style.display = "flex";
cardsDiv.style.left = "0px";
cardsDiv.style.flexWrap = "nowrap";
cardsDiv.style.justifyContent = "center";
cardsDiv.style.alignItems = "center";
cardsDiv.style.transition = "left 0.8s ease";
cardsDiv.classList.add('tech-cards');
sliceCards(cards).forEach(card => {
const tempDiv = Card(card);
cardsDiv.appendChild(tempDiv);
})
cardsContainer.appendChild(cardsDiv);
ribbonDiv.appendChild(cardsContainer);
const arrowRight = document.createElement('div');
arrowRight.style.width = arrowWidth + "px";
arrowRight.style.backgroundColor = "#ddd";
arrowRight.style.height = ribbonHeight + "px";
arrowRight.style.display = "flex";
arrowRight.style.justifyContent = "center";
arrowRight.style.alignItems = "center";
const arrowImgR = document.createElement('img');
arrowImgR.src = "@assets/chevron-right.svg";
arrowRight.appendChild(arrowImgR);
arrowRight.addEventListener("click", () => {
if (scrollInProgress) return;
scrollInProgress = true;
// Set new starting card
if (startingCard + cardsToDisplay >= cards.length) {
startingCard = startingCard + cardsToDisplay - cards.length;
} else {
startingCard += cardsToDisplay;
}
// Get old div and its parent
const oldCards = Array.from(document.getElementsByClassName('tech-cards'));
const oldCardsParent = oldCards[0].parentElement;
while (oldCards.length > 1) {
oldCardsParent.removeChild(oldCards[0]);
oldCards.shift();
}
// Create new div and append to ribbon
const newCards = document.createElement('div');
newCards.style.display = "flex";
newCards.style.position = "absolute";
newCards.style.flexWrap = "nowrap";
newCards.style.justifyContent = "center";
newCards.style.alignItems = "center";
newCards.style.transition = "left 0.8s ease";
newCards.classList.add('tech-cards');
sliceCards(cards).forEach(card=>{
const tempDiv = Card(card);
newCards.append(tempDiv);
})
newCards.style.left = (cardWidth * cardsToDisplay) + 'px';
oldCardsParent.appendChild(newCards);
// Move both to the right
setTimeout(() => {
newCards.style.left = "0px";
oldCards[0].style.left = (-1 * cardsToDisplay * cardWidth) + "px";
}, 20);
setTimeout(() => {scrollInProgress = false}, 500);
// Remove old div
setTimeout(()=> {
oldCards[0].classList.add("old-cards");
const old = Array.from(oldCardsParent.getElementsByClassName("old-cards"));
old.forEach(el => {
oldCardsParent.removeChild(el);
});
}, 900);
})
ribbonDiv.appendChild(arrowRight);
return ribbonDiv;
}
function renderTechRibbon() {
const ribbon = document.getElementById('tech-ribbon');
if (ribbon) {
ribbon.innerHTML = '';
const ribbonContent = Ribbon(stack);
ribbon.appendChild(ribbonContent);
}
}
renderTechRibbon();
// adjust percentages
const trainingSections = Object.keys(trainingMatrix);
trainingSections.forEach(section => {
const isDateInPast = (str) => {
const dates = str.split("/");
const [month, day, year] = [Number(dates[0]), Number(dates[1]), Number(dates[2]) + 2000];
const todayMonth = new Date().getMonth() + 1;
const todayDate = new Date().getDate();
const todayYear = new Date().getFullYear();
if (month < todayMonth && year <= todayYear) {
return true;
}
return month === todayMonth && year === todayYear && day < todayDate;
};
const element = document.getElementById(`${section}-progress`);
const span = element.getElementsByClassName("sr-only")[0];
const trainingArray = trainingMatrix[section];
const pointsCompletedToDate = trainingArray.filter(option => isDateInPast(option.date)).reduce((a,b) => a + b.weight, 0);
const totalPoints = trainingArray.reduce((a,b) => (a + b.weight), 0);
const percentProgress = Math.ceil(pointsCompletedToDate * 100 / totalPoints);
element["aria-valuenow"] = percentProgress.toString();
element.style.width = percentProgress + '%';
span.innerHTML = percentProgress + '% Completed';
if (percentProgress === 100) {
const title = document.getElementById(`${section}-title`);
title.innerHTML += ' - COMPLETED!';
}
})