-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
163 lines (144 loc) · 4.84 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
'use strict';
const menuButton = document.querySelector('.menuButton');
const menu = document.querySelector('.menu');
const skillsEl = document.querySelector('.skills');
const projectsEl = document.querySelector('.projects');
const contactForm = document.querySelector('#contact-form');
const modal = document.querySelector('#modal');
menuButton.addEventListener('click', toggleMenu);
document.body.addEventListener('click', hideMenu);
window.addEventListener('load', populateHtml);
contactForm.addEventListener('submit', onContactSubmit);
document.addEventListener('scroll', e => {
const body = document.body,
html = document.documentElement;
const fullHeight = Math.max(
body.scrollHeight,
body.offsetHeight,
html.clientHeight,
html.scrollHeight,
html.offsetHeight
);
const scrolledDown = html.scrollTop;
const clientHeight = document.documentElement.clientHeight;
if (scrolledDown + clientHeight > fullHeight - 70) {
menuButton.classList.add('hide');
} else if (menuButton.classList.contains('hide')) {
menuButton.classList.remove('hide');
}
});
function toggleMenu(e) {
e.stopPropagation();
menuButton.classList.toggle('clicked');
if (menu.classList.contains('show')) {
menu.classList.add('hide');
menu.classList.remove('show');
} else {
menu.classList.remove('hide');
menu.classList.add('show');
}
}
function hideMenu() {
if (menu.classList.contains('show')) {
menuButton.classList.remove('clicked');
menu.classList.add('hide');
menu.classList.remove('show');
}
}
function onContactSubmit(e) {
let name = e.target[0].value;
let email = e.target[1].value;
let message = e.target[2].value;
e.target.action = `mailto:hasansoso343@gmail.com?subject=Hi Hasan!&body=Hi this is ${name},%0D%0A%0D%0A${message}`;
const success = document.querySelector('#success');
success.classList.add('show');
}
function openModal(url) {
const project = projects.find(project => project.url === url);
modal.style.display = 'flex';
modal.classList.add('show');
const header = modal.querySelector('.modalHeader');
const body = modal.querySelector('.modalBody');
const footer = modal.querySelector('.modalFooter');
const img = `
<img src="${
project.src ? project.src : './assets/noImage.png'
}" class="modalHeaderImage" >
`;
const projectName = `<h2 class="modalHeaderText">${project.name}</h2>`;
const position = `
<p data-title='Position' class="position">${project.position}</p>
`;
console.log(project.url);
const link = `<a href="${
project.url
}" target="_blank" class="link">See website</a>`;
body.innerHTML = `
${img}
${link}
`;
header.innerHTML = `${projectName} `;
footer.innerHTML = `
<p data-title='Description'>${
project.description
}</p> ${position} <button class="closeModal">Close</button>`;
footer.querySelector('.closeModal').addEventListener('click', closeModal);
modal.addEventListener('click', handleModalClick);
}
function handleModalClick(e) {
if (e.target.id === 'modal') {
closeModal();
}
}
function closeModal() {
const hide = setTimeout(() => {
modal.style.display = 'none';
clearTimeout(hide);
}, 400);
modal.classList.remove('show');
modal.removeEventListener('click', handleModalClick);
}
function populateHtml() {
let skillsHtml = '';
for (const skill of skills) {
const html = `
<div class="skillTitle" aria-title="My Skill Title">${skill.title}</div>
<div class="percentage" aria-percentage="My Skill Percentage">
<span class="skillPercentageIndicator" style="width: ${
skill.percentage
}%;"></span>
<span class="skillPercentage">${skill.percentage}%</span>
</div>
`;
skillsHtml += html;
}
skillsEl.setAttribute('aria-skills-list', 'This is my skills list');
skillsEl.innerHTML = skillsHtml;
let projectsHtml = '';
for (const project of projects) {
const html = `
<a class="project animated fade-in" aria-projects="My Projects" onclick="openModal('${
project.url
}')">
<img class="projectImg ${!project.src ? 'noImage' : ''}" src="${
project.src ? project.src : './assets/noImage.png'
}" alt="${project.name} Photo" >
<h3 class="projectTitle" aria-name="This is ${project.name}" >${
project.name
}</h3>
<button class="learnMore" aria-info="Click to read more" id="${
project.url
}" onclick="openModal(this.id)">Read More!</button>
</a>
`;
projectsHtml += html;
}
projectsEl.setAttribute('aria-projects', 'This is my projects');
projectsEl.innerHTML = projectsHtml;
}
function scrollToSection(section) {
const target = document.querySelector(section);
target.scrollIntoView({
behavior: 'smooth'
});
}