-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
270 lines (247 loc) · 9.23 KB
/
script.js
File metadata and controls
270 lines (247 loc) · 9.23 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
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
"use strict";
// import { click } from "@testing-library/user-event/dist/click.js";
import { Projects } from "./projects.js";
// selectors///////////
const checkbox = document.querySelector(".nav__check-box");
const navList = document.querySelector(".nav__list");
const navLink = document.querySelectorAll(".nav__link");
const findOutBtn = document.querySelector("#findOut");
const headerSection = document.querySelector("#header");
const nav = document.querySelector(".nav");
const overlay = document.querySelector(".overlay");
const aboutDescription = document.querySelector(".about__description");
const showMoreButton = document.querySelector(".show_more");
const moredetailsContainer = document.querySelector(".more_details");
//tabbed component
const tabs = document.querySelectorAll(".button__tab");
const jobTabs = document.querySelector(".job-tabs");
const jobDescriptionContent = document.querySelectorAll(
".job__description-content"
);
const showMoreBtn = document.querySelector(".showMore");
const projectContainer = document.querySelector(".project__sub__container");
const message = document.querySelector(".message");
const messageOverlay = document.querySelector(".message-overlay");
/////////////
const allSection = document.querySelectorAll(".section");
const ul = document.querySelector(".project__sub__container");
const li = ul.querySelector(".project_list");
/////FUNCTIONALITY
/////scroll bar functionality ///////
const disableScroll = function () {
document.body.style.overflowY = "hidden";
};
const enableScroll = function () {
document.body.style.overflowY = "auto";
};
//sticky navigation 1
const navheight = Math.round(nav.getBoundingClientRect().height);
const observerFunc = function (entries) {
const [entry] = entries;
if (!entry.isIntersecting) nav.classList.add("sticky");
else {
nav.classList.remove("sticky");
}
};
const observerOps = {
root: null,
threshold: 0,
rootMargin: `-${navheight}px`,
};
const observer = new IntersectionObserver(observerFunc, observerOps);
observer.observe(headerSection);
//sticky navigation 2
//smooth scroll into the sections//////
const addHideOverlay = function () {
overlay.classList.add("hideoverlay");
checkbox.checked = false;
// document.body.style.overflowY = "auto";
enableScroll();
};
navList.addEventListener("click", function (e) {
e.preventDefault();
if (e.target.classList.contains("nav__link")) {
let id = e.target.getAttribute("href");
document.querySelector(id).scrollIntoView({ behavior: "smooth" });
}
//collapses the nav
setTimeout(addHideOverlay, 300);
});
// resets the default of the resume button
navList.querySelector(".resume").addEventListener("click", function (e) {
// e.cancelBubble = true;
// alert(`resume downloaded`)
e.stopImmediatePropagation();
addHideOverlay();
});
const NavOverlay = function () {
if (this.checked == true) {
// document.body.style.overflowY = "hidden";
disableScroll();
overlay.classList.remove("hideoverlay");
} else {
overlay.classList.add("hideoverlay");
// document.body.style.overflowY = "hidden";
// document.body.style.overflowY = "auto";
enableScroll();
}
};
checkbox.addEventListener("click", NavOverlay);
overlay.addEventListener("click", addHideOverlay);
/// find out more scroll
findOutBtn.addEventListener("click", function () {
document.querySelector(".about").scrollIntoView({
behavior: "smooth",
});
});
////////////////////////
///////show more details functionaliy/////
let show = true;
moredetailsContainer.style.display = "none";
const toggleShow = function () {
if (show === true) {
moredetailsContainer.style.display = "block";
// showMoreButton.textContent = "show less";
showMoreButton.style.display = "none";
show = false;
} else {
moredetailsContainer.style.display = "none";
showMoreButton.textContent = `Show more`;
show = true;
}
};
showMoreButton.addEventListener("click", toggleShow);
////////////////////////
//navbar and overlay bar function on phone2
//add event handler to each of the buttons in the tab by using event delegation, i.e targeting the parent element
//tabbed component
jobTabs.addEventListener("click", function (e) {
const clicked = e.target.closest(".button__tab");
if (!clicked) return;
//activate content area
//remove all active class on the element
jobDescriptionContent.forEach((cont) => {
cont.classList.remove("describe--active");
});
//link
document
.querySelector(`.job__description--${clicked.dataset.tab}`)
.classList.add("describe--active");
});
//reveal sections on scroll/////////////
const revealFunct = function (entries, observer) {
const [entry] = entries;
if (!entry.isIntersecting) {
return;
}
entry.target.classList.remove("section-hidden");
observer.unobserve(entry.target);
};
const sectionObj = {
root: null,
threshold: 0.2,
};
let sectionObserver = new IntersectionObserver(revealFunct, sectionObj);
allSection.forEach((sections) => {
sections.classList.add("section-hidden");
sectionObserver.observe(sections);
});
//////////////////////
// console.log(document.body);
// document.body.style.overflowY = "hidden";
// show more functionality /////////
const projectMapped = Projects.map(function (project) {
return `
<li class=""project_list>
<div class="project1 project" data-url="${
project.projectLink
}">
<div class="icon-container">
<div class="project-folder">
<svg class="file-icon">
<use xlink:href="./images/sprite.svg#icon-folder-open-o"></use>
</svg>
</div>
<div class="project-links">
<a href="${
project.githubLink
}" class="github-link" target="_blank">
<svg class="link-icon">
<use xlink:href="./images/sprite.svg#icon-github">
</use>
</svg>
</a>
${
project.projectLink &&
`<a
href="${project.projectLink}"
class="external-link"
target="_blank"
>
<svg class="link-icon">
<use xlink:href="./images/sprite.svg#icon-external-link"></use>
</svg>
</a>`
}
</div>
</div>
<div class="project__details">
<h2 class="heading">
<a href="${
project.projectLink
}" target="_blank"> ${project.projectTitle} </a>
</h2>
<p class="heading_brief">${
project.projectDescription
}</p>
</div>
<div class="project__tools">
${project.projectTools
.map((tool) => `<span>${tool}</span>`)
.join(" ")}
</div>
</div>
<!-- -->
</li>
`;
});
let currCounter = 0;
showMoreBtn.addEventListener("click", function () {
const showResult = 3;
for (let ind = 0; ind < showResult; ind++) {
if (currCounter + ind < projectMapped.length) {
projectContainer.insertAdjacentHTML(
"beforeend",
projectMapped[ind + currCounter]
);
}
if (currCounter > projectMapped.length) {
message.querySelector(
".message__content"
).textContent = `Oops!, That's all the project I have for now.
More projects coming soon!👨🏼💻😉`;
message.classList.remove("hidemessage");
messageOverlay.classList.remove("hideoverlay");
disableScroll();
return;
}
}
currCounter += showResult;
let closebtn = message.querySelector(".btn");
closebtn.addEventListener("click", function () {
message.classList.add("hidemessage");
messageOverlay.classList.add("hideoverlay");
enableScroll();
});
});
// project sub links
ul.addEventListener("click", function (e) {
let clickedElement = e.target.closest(".project");
if (clickedElement) {
let url = clickedElement.getAttribute("data-url");
// window.location.href = url;
window.open(url, "_blank");
}
// let url = e.target.querySelector("");
});
//////////////////////