-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Carter Anderson <mcanders1@gmail.com>
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const searchElement = document.querySelector('#assets-search') | ||
|
||
searchElement.addEventListener("input", (_) => { | ||
filterSearchTerms() | ||
hideEmptySubSections() | ||
hideEmptySections() | ||
}) | ||
|
||
function filterSearchTerms() { | ||
const searchTerms = searchElement.value.toLowerCase().split(' ') | ||
for (const asset of document.querySelectorAll('.asset-card')) { | ||
const fullText = asset.text.toLowerCase() | ||
const searchMatch = searchTerms.every((term) => fullText.includes(term)) | ||
asset.parentElement.style.display = searchMatch ? 'block' : 'none' | ||
} | ||
} | ||
|
||
function hideEmptySubSections() { | ||
for (const itemGrid of document.querySelectorAll('.item-grid')) { | ||
const cardInGrid = [...itemGrid.querySelectorAll('.asset-card')] | ||
const areAllHidden = (cardInGrid.every((card) => card.parentElement.style.display === 'none')) | ||
itemGrid.style.display = areAllHidden ? 'none' : 'grid' | ||
itemGrid.previousElementSibling.style.display = areAllHidden ? 'none' : 'block' | ||
} | ||
} | ||
|
||
function hideEmptySections() { | ||
document.querySelectorAll('.asset-section').forEach(section => { | ||
let nextElement = section.nextElementSibling | ||
while (nextElement && !nextElement.classList.contains('asset-section')) { | ||
if (nextElement.style.display !== 'none') { | ||
section.style.display = 'block' | ||
return | ||
} | ||
nextElement = nextElement.nextElementSibling | ||
} | ||
section.style.display = 'none' | ||
}) | ||
} |
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