-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgallery.js
64 lines (57 loc) · 2.1 KB
/
gallery.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class AppletCard {
constructor(title, description, link) {
this.title = title;
this.description = description;
this.link = link;
}
createCard() {
const cardDiv = document.createElement('div');
cardDiv.className = 'card applet-card';
cardDiv.innerHTML = `
<div class="card-body">
<h5 class="card-title" style= "color: #f4a261">${this.title}</h5>
<p class="card-text">${this.description}</p>
<a href="${this.link}" class="btn btn-primary applet-btn" style="">Go to Applet</a>
</div>
`;
return cardDiv;
}
}
class AppletRenderer {
constructor(containerId,searchInputId) {
this.container = document.getElementById(containerId);
//
this.searchInput = document.getElementById(searchInputId);
this.appletData = [];
this.filteredData = [];
this.searchInput.addEventListener('input',()=> this.filterApplets());
}
fetchAppletData(url) {
fetch(url)
.then(response => response.json())
.then(data => {
this.appletData = data;
this.filteredData = data;
this.renderApplets(this.filteredData);
})
.catch(error => console.error('Error loading applet data:', error));
}
renderApplets(data) {
this.container.innerHTML = '';
data.forEach(applet => {
const appletCard = new AppletCard(applet.title, applet.description, applet.link);
const cardElement = appletCard.createCard();
this.container.appendChild(cardElement);
});
}
filterApplets(){
const query = this.searchInput.value.toLowerCase();
this.filteredData = this.appletData.filter(applet =>
applet.title.toLowerCase().includes(query) ||
applet.description.toLowerCase().includes(query)
);
this.renderApplets(this.filteredData);
}
}
const appletRenderer = new AppletRenderer('applet-container','searchApplet');
appletRenderer.fetchAppletData('gallery.json');