Spaces:
Runtime error
Runtime error
Update templates/menu.html
Browse files- templates/menu.html +31 -26
templates/menu.html
CHANGED
@@ -472,33 +472,38 @@
|
|
472 |
}
|
473 |
|
474 |
function filterMenu() {
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
|
|
|
|
501 |
}
|
|
|
|
|
|
|
502 |
|
503 |
function addToCartFromModal() {
|
504 |
const itemName = document.getElementById('modal-name').innerText;
|
|
|
472 |
}
|
473 |
|
474 |
function filterMenu() {
|
475 |
+
let input = document.getElementById('searchBar').value.toLowerCase(); // Get the value from search bar
|
476 |
+
let sections = document.querySelectorAll('h3'); // Select section headers
|
477 |
+
let items = document.querySelectorAll('.menu-card'); // Select all items
|
478 |
+
let matchedSections = new Set(); // Store matched sections
|
479 |
+
|
480 |
+
// Hide all items initially
|
481 |
+
items.forEach(item => {
|
482 |
+
let itemName = item.querySelector('.card-title').innerText.toLowerCase(); // Get item name
|
483 |
+
let itemSection = item.closest('.row').previousElementSibling.innerText.toLowerCase(); // Get section name
|
484 |
+
|
485 |
+
// If the search matches item name or section, show the item
|
486 |
+
if (itemName.includes(input) || (itemSection && itemSection.includes(input))) {
|
487 |
+
item.style.display = 'block'; // Show item if it matches search
|
488 |
+
matchedSections.add(item.closest('.row')); // Add section to matched list
|
489 |
+
} else {
|
490 |
+
item.style.display = 'none'; // Hide item if not matched
|
491 |
+
}
|
492 |
+
});
|
493 |
+
|
494 |
+
// Show or hide sections based on matched items
|
495 |
+
sections.forEach(section => {
|
496 |
+
let sectionRow = section.nextElementSibling; // The row containing items
|
497 |
+
if (matchedSections.has(sectionRow)) {
|
498 |
+
section.style.display = 'block'; // Show section header
|
499 |
+
sectionRow.style.display = 'flex'; // Show section items
|
500 |
+
} else {
|
501 |
+
section.style.display = 'none'; // Hide section header
|
502 |
+
sectionRow.style.display = 'none'; // Hide section items
|
503 |
}
|
504 |
+
});
|
505 |
+
}
|
506 |
+
|
507 |
|
508 |
function addToCartFromModal() {
|
509 |
const itemName = document.getElementById('modal-name').innerText;
|