-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve/fix styles and list of projects
- Loading branch information
Showing
8 changed files
with
141 additions
and
66 deletions.
There are no files selected for viewing
This file contains 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 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 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,30 +1,72 @@ | ||
var projects = document.querySelectorAll('.project-card'); | ||
var searchInput = document.getElementById('search'); | ||
var projectsFound = document.getElementById('projects-found'); | ||
var showMoreButton = document.getElementById('show-more-projects'); | ||
var matchingProjects = projects.length; | ||
var visibleProjects = 0; | ||
var projectsPerPage = 6; | ||
|
||
projects.forEach(function(project, index) { | ||
console.log(project); | ||
project.setAttribute('search-data', project.textContent.replace(/\s/g, " ").toLowerCase()); | ||
}); | ||
|
||
function debounce(callback, wait) { | ||
let timeout; | ||
return (...args) => { | ||
clearTimeout(timeout); | ||
timeout = setTimeout(function () { callback.apply(this, args); }, wait); | ||
}; | ||
} | ||
|
||
searchInput.addEventListener('keyup', debounce( () => { | ||
let search = searchInput.value.toLowerCase(); | ||
let found = 0; | ||
if(searchInput){ | ||
// Add search data to projects and reset their visibility | ||
projects.forEach(function(project, index) { | ||
if (project.getAttribute('search-data').includes(search)) { | ||
console.log(project); | ||
project.setAttribute('search-data', project.textContent.replace(/\s/g, " ").toLowerCase()); | ||
if(visibleProjects < projectsPerPage){ | ||
project.style.display = 'block'; | ||
++found; | ||
++visibleProjects; | ||
} | ||
}); | ||
|
||
function updateShowMoreButton() { | ||
if (visibleProjects < matchingProjects) { | ||
showMoreButton.style.display = 'block'; | ||
} else { | ||
project.style.display = 'none'; | ||
showMoreButton.style.display = 'none'; | ||
} | ||
} | ||
|
||
// Add event listener to show more button | ||
updateShowMoreButton(); | ||
showMoreButton.addEventListener('click', function() { | ||
let projects = document.querySelectorAll('.search-match'); | ||
let newVisibleProjects = visibleProjects + projectsPerPage; | ||
for (var i = visibleProjects; i < newVisibleProjects; ++i) { | ||
if (projects[i]) { | ||
projects[i].style.display = 'block'; | ||
++visibleProjects; | ||
} | ||
} | ||
updateShowMoreButton(); | ||
}); | ||
projectsFound.innerHTML = found.toString(); | ||
}, 500)) | ||
|
||
// Add event listener to search input | ||
function debounce(callback, wait) { | ||
let timeout; | ||
return (...args) => { | ||
clearTimeout(timeout); | ||
timeout = setTimeout(function () { callback.apply(this, args); }, wait); | ||
}; | ||
} | ||
|
||
searchInput.addEventListener('keyup', debounce( () => { | ||
let search = searchInput.value.toLowerCase(); | ||
matchingProjects = 0; | ||
visibleProjects = 0; | ||
projects.forEach(function(project, index) { | ||
project.style.display = 'none'; | ||
if (project.getAttribute('search-data').includes(search)) { | ||
project.classList.add('search-match'); | ||
++matchingProjects; | ||
if(visibleProjects < projectsPerPage){ | ||
project.style.display = 'block'; | ||
++visibleProjects; | ||
} | ||
} else { | ||
project.classList.remove('search-match'); | ||
} | ||
}); | ||
projectsFound.innerHTML = matchingProjects.toString(); | ||
updateShowMoreButton(); | ||
}, 500)); | ||
|
||
} |
This file contains 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 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 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 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 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