-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
44 lines (32 loc) · 1.14 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Search function
function searchImages(query) {
const sections = document.querySelectorAll("section");
sections.forEach(section => {
const lis = section.querySelectorAll("li");
let hasMatchingLi = false;
lis.forEach(li => {
const img = li.querySelector(`img[data-keywords*="${query}"]`);
li.style.display = (img || !query) ? "block" : "none";
if (img || !query) hasMatchingLi = true;
});
section.style.display = hasMatchingLi ? "block" : "none";
});
}
// Add event listener for input field
const searchInput = document.getElementById("searchInput");
searchInput.addEventListener("input", function() {
const query = this.value.trim().toLowerCase();
searchImages(query);
});
// Filtration function
function filterLinks(category) {
const sections = document.querySelectorAll('section');
sections.forEach(section => {
section.style.display = (category === 'all' || category === section.id) ? 'block' : 'none';
});
}
// Add event listener for select menu
const filterElement = document.getElementById('categorySelect');
filterElement.addEventListener('change', function() {
filterLinks(this.value);
});