-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathscript.js
40 lines (36 loc) · 1.34 KB
/
script.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
document.addEventListener("DOMContentLoaded", () => {
const parentDiv = document.getElementById("component-items");
fetch("./components.json")
.then((response) => response.json())
.then((data) => {
data.forEach((component) => {
const newElement = document.createElement("div");
newElement.innerHTML = ` <div class="card">
<div class="poster"><a href="components/${component.url}"><img
src="${component.imgUrl}" alt="${component.name}" /></a></div>
<div class="details">
<h1>${component.name}</h1>
<h2>By: ${component.authorName}</h2>
</div>
</div>`;
parentDiv.appendChild(newElement);
});
});
});
function searchComponents() {
const searchInput = document
.getElementById("searchInput")
.value.toLowerCase();
const cards = document.querySelectorAll(".card");
cards.forEach((card) => {
const title = card.querySelector(".details h1").textContent.toLowerCase();
const author = card.querySelector(".details h2").textContent.toLowerCase();
console.log(title, author);
if (title.includes(searchInput) || author.includes(searchInput)) {
card.style.display = "block";
foundResults = true;
} else {
card.style.display = "none";
}
});
}