// scrolling effect const scrollLimit = 150; window.onscroll = () => { // check if scrolled past limit if so add scrolled class to change background of nav if (document.body.scrollTop >= scrollLimit || document.documentElement.scrollTop >= scrollLimit) { document.querySelector("nav").classList.add("scrolled"); } else { document.querySelector("nav").classList.remove("scrolled"); } let current = ""; //id of current section scrolled to, set to "" if at top // go through all sections and find current section id scrolled to document.querySelectorAll("section").forEach((section) => { const sectionTop = section.offsetTop; if (window.pageYOffset >= sectionTop - 60) { current = section.getAttribute("id"); } }); // go through all nav links, remove active class and add it to the link whose href matches the current id scrolled // to document.querySelectorAll("nav ul li a").forEach((a) => { a.classList.remove("active"); if (a.href.includes(current) && current !== "") { a.classList.add("active"); } else if (current === "") { document.querySelector("nav ul li a").classList.add("active"); // at the top } }); }; // cv timeline data /** * getTimelineData function * Gets the timeline data from backend route and appends the data on to the timeline. */ function getTimelineData() { let dateOptions = { year: "numeric", month: "short" }; fetch("/api/timelineData/edu").then(res => { res.json().then(json => { if (res.ok) { json.forEach(item => { let timelineItem = document.createElement("div") timelineItem.classList.add("timelineItem"); timelineItem.innerHTML = `
${item["course"]}
`; document.getElementById("edu").appendChild(timelineItem); }); } }) }); fetch("/api/timelineData/work").then(res => { res.json().then(json => { if (res.ok) { json.forEach(item => { let timelineItem = document.createElement("div") timelineItem.classList.add("timelineItem"); let endPeriod = item["endPeriod"] === "0000-00-00" ? "Present" : new Date(item["endPeriod"]).toLocaleString('en-gb', dateOptions); timelineItem.innerHTML = `${item["title"]}
`; document.getElementById("work").appendChild(timelineItem); }) } }) }) } /** * getProjectData function * Gets the project data from the backend route and appends the data on to the timeline. */ function getProjectData() { fetch("/api/projectData").then(res => { res.json().then(json => { if (res.ok) { for (let i = 0; i < 4; i++){ if (json[i]["isMainProject"] === 1) { document.getElementById("mainProj").innerHTML = `${json[i]["information"]}