-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
56 lines (49 loc) · 2.21 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const navDialog = document.getElementById('nav-dialog');
function handleMenu(){
navDialog.classList.toggle('hidden');
}
document.addEventListener('DOMContentLoaded', function() {
const productList = document.getElementById('product-list');
const sheetURL = 'https://script.google.com/macros/s/AKfycbyT1Dnl5AhmGm_hE61OYW2fnlF2rQHyp9ESKh1SMjKhSOrvu7LNG-HbZ0MxjN0nhIA03w/exec'; // Replace with your web app URL
fetch(sheetURL)
.then(response => response.json())
.then(data => {
data.forEach(product => {
const productCard = document.createElement('div');
productCard.className = 'product-card';
productCard.innerHTML = `
<div class="product-image">
<img src="${product['Image URL']}" alt="${product.Name}">
</div>
<div class="product-info">
<div class="product-title">${product.Name}</div>
<div class="product-description">${product['Product Description']}</div>
<div class="product-links">
<a href="${product['PDF Link']}" target="_blank">View Brochure</a>
<a href="${product['More Images Links']}" target="_blank">View More Images</a>
</div>
</div>
`;
productList.appendChild(productCard);
});
})
.catch(error => {
console.error('Error fetching products:', error);
});
});
// Adding Search Bar
document.addEventListener('DOMContentLoaded', function() {
var searchInput = document.getElementById('search-input');
searchInput.addEventListener('input', function() {
var query = searchInput.value.toLowerCase();
var productCards = document.querySelectorAll('.product-card');
productCards.forEach(function(card) {
var productName = card.querySelector('.product-title').textContent.toLowerCase();
if (productName.includes(query)) {
card.style.display = 'flex';
} else {
card.style.display = 'none';
}
});
});
});