nagasurendra commited on
Commit
b97c68d
·
verified ·
1 Parent(s): fd1f6e4

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +12 -18
templates/menu.html CHANGED
@@ -362,37 +362,31 @@
362
  let sections = document.querySelectorAll('.menu-section'); // Select all sections
363
  let items = document.querySelectorAll('.menu-card'); // Select all items
364
 
365
- // Hide all sections initially
366
- sections.forEach(section => {
367
- section.style.display = 'none';
368
- });
369
-
370
- // Hide all items initially
371
- items.forEach(item => {
372
- item.style.display = 'none';
373
- });
374
-
375
  let matchedSections = new Set(); // Store matched sections
376
 
377
- // Show items that match the search query
378
  items.forEach(item => {
379
  let itemName = item.querySelector('.card-title').innerText.toLowerCase();
380
  let itemSection = item.closest('.menu-section')?.querySelector('h3')?.innerText.toLowerCase();
381
 
382
- // If item name or section name matches the search query, show it
383
  if (itemName.includes(input) || (itemSection && itemSection.includes(input))) {
384
- item.style.display = 'block';
385
- matchedSections.add(item.closest('.menu-section')); // Store the section
 
 
386
  }
387
  });
388
 
389
- // Show matched sections
390
- matchedSections.forEach(section => {
391
- section.style.display = 'block';
 
 
 
 
392
  });
393
  }
394
 
395
-
396
  function addToCartFromModal() {
397
  const itemName = document.getElementById('modal-name').innerText; // Get item name
398
  const itemPrice = parseFloat(document.getElementById('modal-price').innerText.replace('$', '')); // Get item price
 
362
  let sections = document.querySelectorAll('.menu-section'); // Select all sections
363
  let items = document.querySelectorAll('.menu-card'); // Select all items
364
 
 
 
 
 
 
 
 
 
 
 
365
  let matchedSections = new Set(); // Store matched sections
366
 
367
+ // Hide all items initially
368
  items.forEach(item => {
369
  let itemName = item.querySelector('.card-title').innerText.toLowerCase();
370
  let itemSection = item.closest('.menu-section')?.querySelector('h3')?.innerText.toLowerCase();
371
 
 
372
  if (itemName.includes(input) || (itemSection && itemSection.includes(input))) {
373
+ item.style.display = 'block'; // Show item if it matches search
374
+ matchedSections.add(item.closest('.menu-section')); // Add section to matched list
375
+ } else {
376
+ item.style.display = 'none'; // Hide item if not matched
377
  }
378
  });
379
 
380
+ // Show or hide sections based on matched items
381
+ sections.forEach(section => {
382
+ if (matchedSections.has(section)) {
383
+ section.style.display = 'block';
384
+ } else {
385
+ section.style.display = 'none';
386
+ }
387
  });
388
  }
389
 
 
390
  function addToCartFromModal() {
391
  const itemName = document.getElementById('modal-name').innerText; // Get item name
392
  const itemPrice = parseFloat(document.getElementById('modal-price').innerText.replace('$', '')); // Get item price