Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// Detect which page we are on
// ============================================================
// !! trick turns the DOM result into a simple true/false
var isIndexPage = !!document.getElementById("recommend-form");
var isIndexPage = !!document.getElementById("recommend-form");
// PROJECT_ID is set by the server only on detail pages, so if it's missing we're elsewhere
var isDetailPage = typeof PROJECT_ID !== "undefined";
var modal = document.getElementById('github-modal-overlay');
Expand Down Expand Up @@ -92,7 +92,7 @@ if (isIndexPage) {
"C#", "Ruby", "PHP", "Go", "Swift", "TypeScript", "Angular", "Vue.js",
"Spring", "Flutter", "TensorFlow", "PyTorch", "Data Science",
"Machine Learning", "Artificial Intelligence", "DevOps", "Cybersecurity",
"Blockchain", "UI/UX Design", "Game Development", "CI/CD", "REST API", "GraphQL",
"Blockchain", "UI/UX Design", "Game Development", "CI/CD", "REST API", "GraphQL",
"Rust", "Kotlin"
];
}
Expand Down Expand Up @@ -498,10 +498,10 @@ if (isIndexPage) {
//combine form values into an object to send to server/api
var payload = {
// Prefer the hidden input value; fall back to raw text box if hidden input is empty
skills: skillsHidden.value.trim() || skillsTextInput.value.trim(),
level: document.getElementById("level").value,
skills: skillsHidden.value.trim() || skillsTextInput.value.trim(),
level: document.getElementById("level").value,
interest: document.getElementById("interest").value,
time: document.getElementById("time").value
time: document.getElementById("time").value
};

//post the data to backend api as JSON, then handle the response
Expand Down Expand Up @@ -725,7 +725,12 @@ if (isDetailPage) {
return;
}
if (codePanelFilename) codePanelFilename.textContent = data.filename;
if (codeContentEl) codeContentEl.textContent = data.code;
if (codeContentEl) {
codeContentEl.textContent = "";
renderCodeWithLineNumbers(data.code).forEach(function (row) {
codeContentEl.appendChild(row);
});
}
// Mark as fetched so we don't hit the API again on the next open
codeFetched = true;
})
Expand Down Expand Up @@ -764,11 +769,11 @@ if (isDetailPage) {
// Swap icons on the button(copy and checkmark icons)
var copyIcon = btnCopyCode.querySelector(".copy-icon");
var checkIcon = btnCopyCode.querySelector(".check-icon");
var btnLabel = btnCopyCode.querySelector(".copy-btn-label");
var btnLabel = btnCopyCode.querySelector(".copy-btn-label");

if (copyIcon) copyIcon.style.display = "none";
if (copyIcon) copyIcon.style.display = "none";
if (checkIcon) checkIcon.style.display = "inline";
if (btnLabel) btnLabel.textContent = "Copied!";
if (btnLabel) btnLabel.textContent = "Copied!";
btnCopyCode.classList.add("copied");
// Disable button so user can't spam click it while toast is showing
btnCopyCode.disabled = true;
Expand All @@ -782,9 +787,9 @@ if (isDetailPage) {
// Clear any previous timeout first so timers don't stack up
clearTimeout(toastTimeout);
toastTimeout = setTimeout(function () {
if (copyIcon) copyIcon.style.display = "inline";
if (copyIcon) copyIcon.style.display = "inline";
if (checkIcon) checkIcon.style.display = "none";
if (btnLabel) btnLabel.textContent = "Copy Code";
if (btnLabel) btnLabel.textContent = "Copy Code";
btnCopyCode.classList.remove("copied");
btnCopyCode.disabled = false;
if (copyToast) copyToast.classList.remove("show");
Expand All @@ -793,7 +798,11 @@ if (isDetailPage) {

if (btnCopyCode) {
btnCopyCode.addEventListener("click", function () {
var code = codeContentEl ? codeContentEl.textContent : "";
var code = codeContentEl
? Array.from(codeContentEl.querySelectorAll(".line-content"))
.map(function (el) { return el.textContent; })
.join("\n")
: "";
// Don't copy if the code hasn't loaded yet β€” just ignore the click
if (!code || code === "Loading..." || code === "Loading starter code...") return;

Expand Down Expand Up @@ -895,17 +904,17 @@ var scrollTopBtn = document.getElementById('scroll-top-btn');

/* Add or remove the .visible class based on scroll position */
function handleScroll() {
if (!scrollTopBtn) return;
if (window.pageYOffset > SCROLL_THRESHOLD) {
scrollTopBtn.classList.add('visible');
} else {
scrollTopBtn.classList.remove('visible');
}
if (!scrollTopBtn) return;
if (window.pageYOffset > SCROLL_THRESHOLD) {
scrollTopBtn.classList.add('visible');
} else {
scrollTopBtn.classList.remove('visible');
}
}

/* Smooth-scroll to the very top of the page */
function scrollToTop() {
window.scrollTo({ top: 0, behavior: 'smooth' });
window.scrollTo({ top: 0, behavior: 'smooth' });
}

/* Only wire up listeners if the button exists on this page */
Expand Down
Loading
Loading