Spaces:
Sleeping
Sleeping
Update app.py
Browse files125 unmodified lines126127128129130131132133134135136137138139140141142143144129130131132133134135136137138139140141142143146147148149150144145146147148149152153154155156150151152153154155156157158158159160161159160161162163163164165166167168169170171172173174164165166167168169170171172173174175176177178179180125 unmodified lines
# JavaScript for managing the pop-up gr.HTML(""" <div id=\"popup\" style=\"display: none; position: absolute; background-color: white; padding: 20px; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;\"> <p id=\"popup-image\" style=\"font-size: 14px; word-break: break-all; color: #444; margin-top: 10px;\"></p> <h2 id=\"popup-title\" style=\"margin-top: 20px; color: #444;\"></h2> <p id=\"popup-description\" style=\"margin-top: 10px; font-size: 16px; color: #666;\"></p> <p id=\"popup-price\" style=\"margin-top: 10px; font-size: 16px; color: #444;\"></p> <h4 style=\"text-align: left; margin-top: 20px;\">Choose a spice level</h4> <div style=\"display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;\"> """ + """".join([f'<label style=\"margin-right: 10px; display: block;\"><input type=\"radio\" name=\"spice\" value=\"{spice}\" style=\"margin-right: 5px;\">{spice}</label>' for spice in spice_levels]) + """ </div>
<h4 style=\"text-align: left; margin-top: 20px;\">Choose Extras</h4> <div style=\"display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;\"> """ + """".join([f'<label style=\"margin-right: 10px; display: block;\"><input type=\"checkbox\" name=\"extras\" value=\"{extra["name"]}\" style=\"margin-right: 5px;\">{extra["name"]} + {extra["price"]}</label>' for extra in extras]) + """ </div> <div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: white; padding: 20px; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;"> <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;"> <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2> <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p> <p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p> <h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4> <div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;"> """ + "".join([ f'<label style="margin-right: 10px; display: block;"><input type="radio" name="spice" value="{spice}" style="margin-right: 5px;">{spice}</label>' for spice in spice_levels]) + """ </div>
<button onclick=\"addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)\" style=\"margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;\">Add to Cart</button> <button onclick=\"closePopup()\" style=\"margin-top: 20px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;\">Close</button> <h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4> <div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;"> """ + "".join([ f'<label style="margin-right: 10px; display: block;"><input type="checkbox" name="extras" value="{extra["name"]}" style="margin-right: 5px;">{extra["name"]} + {extra["price"]}</label>' for extra in extras]) + """ </div> <script> function showPopup(dishId, image, title, description, price) { const dishElement = document.getElementById(`dish-${dishId}`); const rect = dishElement.getBoundingClientRect(); const popup = document.getElementById('popup');
<button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)" style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button> <button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button> </div> <script> function showPopup(image, title, description, price) { document.getElementById('popup-image').textContent = image; document.getElementById('popup-title').textContent = title; document.getElementById('popup-description').textContent = description; document.getElementById('popup-price').textContent = "Price: " + price; document.getElementById('popup-image').src = image; document.getElementById('popup-title').textContent = title; document.getElementById('popup-description').textContent = description; document.getElementById('popup-price').textContent = "Price: " + price;
popup.style.top = `${rect.bottom + window.scrollY}px`; popup.style.left = `${rect.left + window.scrollX}px`; popup.style.display = 'block'; } function closePopup() { document.getElementById('popup').style.display = 'none'; } function addToCart(dishName, spiceLevel) { const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", "); alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!"); } </script> // Display the popup document.getElementById('popup').style.display = 'block'; } function closePopup() { document.getElementById('popup').style.display = 'none'; } function addToCart(dishName, spiceLevel) { const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", "); alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!"); } </script>""")
# Button click events btn_all.click( lambda: gr.update(value=display_dishes("ALL")),app.py+43-42