-
Notifications
You must be signed in to change notification settings - Fork 685
Improve accessibility and security in project grid #2068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PankajSingh34
wants to merge
1
commit into
TusharKesarwani:main
Choose a base branch
from
PankajSingh34:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,135 +1,149 @@ | ||
| import projects from "./projects.js"; | ||
|
|
||
| const urlParams = new URLSearchParams(window.location.search); | ||
| const searchQuery = urlParams.get('s'); | ||
| const searchQuery = urlParams.get("s"); | ||
|
|
||
| let filteredProjects = (searchQuery && searchQuery != "") ? projects.filter((project) => project.title.toLowerCase().includes(searchQuery.toLowerCase())) : projects; | ||
| let filteredProjects = | ||
| searchQuery && searchQuery != "" | ||
| ? projects.filter((project) => | ||
| project.title.toLowerCase().includes(searchQuery.toLowerCase()) | ||
| ) | ||
| : projects; | ||
|
|
||
| // displaying filtered projects | ||
| const projects_div = document.getElementsByClassName("projects")[0] | ||
| const projects_div = document.getElementsByClassName("projects")[0]; | ||
| for (let project of filteredProjects) { | ||
| const project_div = document.createElement("div"); | ||
| project_div.className="project"; | ||
|
|
||
| const img = document.createElement("img") | ||
| img.src = project.img; | ||
| project_div.appendChild(img); | ||
|
|
||
| const project_info = document.createElement("div"); | ||
| project_info.className = "project-info"; | ||
| const heading = document.createElement("h2"); | ||
| heading.innerHTML = project.title; | ||
| project_info.appendChild(heading); | ||
|
|
||
| const row = document.createElement("div"); | ||
| row.className="row"; | ||
| const tech = document.createElement("tech"); | ||
| tech.className="tech"; | ||
|
|
||
| for (let t of project.tags) { | ||
| const span = document.createElement("span"); | ||
| span.innerHTML = t; | ||
| tech.appendChild(span); | ||
| } | ||
|
|
||
| row.appendChild(tech); | ||
|
|
||
| const links = document.createElement("div"); | ||
| links.className = "links"; | ||
|
|
||
| const project_link = document.createElement("a"); | ||
| project_link.href = project['project-link']; | ||
| project_link.innerHTML = `<i class="fa-solid fa-link"></i>`; | ||
| project_link.target="_blank" | ||
| links.appendChild(project_link); | ||
|
|
||
| const github_link = document.createElement("a"); | ||
| github_link.href = project['github-link']; | ||
| github_link.innerHTML = `<i class="fa-brands fa-github"></i>`; | ||
| github_link.target="_blank" | ||
| links.appendChild(github_link); | ||
|
|
||
| row.appendChild(links); | ||
| project_info.appendChild(row); | ||
|
|
||
| const desc = document.createElement('p'); | ||
| desc.className="description"; | ||
| desc.innerHTML=project.description; | ||
| project_info.appendChild(desc); | ||
|
|
||
| project_div.appendChild(project_info); | ||
| projects_div.appendChild(project_div); | ||
| const project_div = document.createElement("div"); | ||
| project_div.className = "project"; | ||
|
|
||
| const img = document.createElement("img"); | ||
| img.src = project.img; | ||
| // Performance & a11y: lazy-load grid images and add descriptive alt | ||
| img.loading = "lazy"; | ||
| img.alt = project.title; | ||
| project_div.appendChild(img); | ||
|
|
||
| const project_info = document.createElement("div"); | ||
| project_info.className = "project-info"; | ||
| const heading = document.createElement("h2"); | ||
| heading.innerHTML = project.title; | ||
| project_info.appendChild(heading); | ||
|
|
||
| const row = document.createElement("div"); | ||
| row.className = "row"; | ||
| const tech = document.createElement("tech"); | ||
| tech.className = "tech"; | ||
|
|
||
| for (let t of project.tags) { | ||
| const span = document.createElement("span"); | ||
| span.innerHTML = t; | ||
| tech.appendChild(span); | ||
| } | ||
|
|
||
| row.appendChild(tech); | ||
|
|
||
| const links = document.createElement("div"); | ||
| links.className = "links"; | ||
|
|
||
| const project_link = document.createElement("a"); | ||
| project_link.href = project["project-link"]; | ||
| project_link.innerHTML = `<i class="fa-solid fa-link"></i>`; | ||
| project_link.target = "_blank"; | ||
| // Security & a11y: prevent opener leak and add label for icon-only link | ||
| project_link.rel = "noopener noreferrer"; | ||
| project_link.setAttribute("aria-label", `${project.title} live demo`); | ||
| links.appendChild(project_link); | ||
|
|
||
| const github_link = document.createElement("a"); | ||
| github_link.href = project["github-link"]; | ||
| github_link.innerHTML = `<i class="fa-brands fa-github"></i>`; | ||
| github_link.target = "_blank"; | ||
| // Security & a11y for icon-only link | ||
| github_link.rel = "noopener noreferrer"; | ||
| github_link.setAttribute("aria-label", `${project.title} source on GitHub`); | ||
| links.appendChild(github_link); | ||
|
|
||
| row.appendChild(links); | ||
| project_info.appendChild(row); | ||
|
|
||
| const desc = document.createElement("p"); | ||
| desc.className = "description"; | ||
| desc.innerHTML = project.description; | ||
| project_info.appendChild(desc); | ||
|
|
||
| project_div.appendChild(project_info); | ||
| projects_div.appendChild(project_div); | ||
| } | ||
|
|
||
| // For search query form | ||
|
|
||
| if (searchQuery && searchQuery != "") | ||
| document.getElementById("search").value = searchQuery | ||
| document.getElementById("search").value = searchQuery; | ||
|
|
||
| const searchForm = document.getElementById("searchForm"); | ||
| searchForm.addEventListener("submit",(e) => { | ||
| const searchText = document.getElementById("search"); | ||
| e.preventDefault(); | ||
|
|
||
| if (searchText.value == (searchQuery ? searchQuery : "")) { | ||
| return; | ||
| } | ||
| searchForm.addEventListener("submit", (e) => { | ||
| const searchText = document.getElementById("search"); | ||
| e.preventDefault(); | ||
|
|
||
| window.location = `/index.html?s=${searchText.value}`; | ||
| }) | ||
| if (searchText.value == (searchQuery ? searchQuery : "")) { | ||
| return; | ||
| } | ||
|
|
||
| window.location = `/index.html?s=${searchText.value}`; | ||
| }); | ||
|
|
||
| // For contributors list | ||
|
|
||
| fetch("https://api.github.com/repos/TusharKesarwani/Front-End-Projects/contributors?per_page=50", { | ||
| headers: { | ||
| 'Authorization': '' | ||
| } | ||
| }).then(response => response.json()) | ||
| .then(data => { | ||
| // Extract the data for each contributor | ||
| const contributors = data.map(contributor => ({ | ||
| username: contributor.login, | ||
| avatarUrl: contributor.avatar_url, | ||
| profileUrl: contributor.html_url | ||
| })); | ||
|
|
||
| // Create and append HTML elements to display the contributors | ||
| const contributorsList = document.querySelector("#contributors-list"); | ||
| contributors.forEach(contributor => { | ||
| const li = document.createElement("li"); | ||
| li.innerHTML = `<a href="${contributor.profileUrl}"><img src="${contributor.avatarUrl}" alt="${contributor.username}"></a>`; | ||
| contributorsList.appendChild(li); | ||
| }); | ||
|
|
||
| fetch( | ||
| "https://api.github.com/repos/TusharKesarwani/Front-End-Projects/contributors?per_page=50", | ||
| { | ||
| headers: { | ||
| Authorization: "", | ||
| }, | ||
| } | ||
| ) | ||
| .then((response) => response.json()) | ||
| .then((data) => { | ||
| // Extract the data for each contributor | ||
| const contributors = data.map((contributor) => ({ | ||
| username: contributor.login, | ||
| avatarUrl: contributor.avatar_url, | ||
| profileUrl: contributor.html_url, | ||
| })); | ||
|
|
||
| // Create and append HTML elements to display the contributors | ||
| const contributorsList = document.querySelector("#contributors-list"); | ||
| contributors.forEach((contributor) => { | ||
| const li = document.createElement("li"); | ||
| li.innerHTML = `<a href="${contributor.profileUrl}"><img src="${contributor.avatarUrl}" alt="${contributor.username}"></a>`; | ||
| contributorsList.appendChild(li); | ||
| }); | ||
| }); | ||
|
|
||
| //-----------for scrollbar button--------------- | ||
|
|
||
|
|
||
| function calculateScrollValue(){ | ||
| //-----------for scrollbar button--------------- | ||
|
|
||
| let scrollProgress=document.getElementById('progress'); | ||
| let progressValue=document.getElementById('progress-value'); | ||
| function calculateScrollValue() { | ||
| let scrollProgress = document.getElementById("progress"); | ||
| let progressValue = document.getElementById("progress-value"); | ||
|
|
||
| let pos=document.documentElement.scrollTop; | ||
| let calcHeight=document.documentElement.scrollHeight-document.documentElement.clientHeight; | ||
| let pos = document.documentElement.scrollTop; | ||
| let calcHeight = | ||
| document.documentElement.scrollHeight - | ||
| document.documentElement.clientHeight; | ||
|
|
||
| let scrollValue=Math.round((pos*100)/calcHeight); | ||
| let scrollValue = Math.round((pos * 100) / calcHeight); | ||
|
|
||
| // for hiding scrollbar button | ||
| if(pos>100){ | ||
| scrollProgress.style.display='grid'; | ||
| } | ||
| else{ | ||
| scrollProgress.style.display='none'; | ||
| } | ||
| // for hiding scrollbar button | ||
| if (pos > 100) { | ||
| scrollProgress.style.display = "grid"; | ||
| } else { | ||
| scrollProgress.style.display = "none"; | ||
| } | ||
|
|
||
|
|
||
| scrollProgress.addEventListener('click',()=>{ | ||
| document.documentElement.scrollTop=0; | ||
| }) | ||
| scrollProgress.style.background=`conic-gradient(#0D4360 ${scrollValue}%, #d7d7d7 ${scrollValue}%)`; | ||
|
|
||
| } | ||
| window.onscroll=calculateScrollValue; | ||
| window.onload=calculateScrollValue; | ||
| scrollProgress.addEventListener("click", () => { | ||
| document.documentElement.scrollTop = 0; | ||
| }); | ||
| scrollProgress.style.background = `conic-gradient(#0D4360 ${scrollValue}%, #d7d7d7 ${scrollValue}%)`; | ||
| } | ||
| window.onscroll = calculateScrollValue; | ||
| window.onload = calculateScrollValue; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused variable progressValue.