Rammohan0504 commited on
Commit
520df2a
·
verified ·
1 Parent(s): 0a4cf1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -19
app.py CHANGED
@@ -102,9 +102,9 @@ def display_dishes(category):
102
  <div style='text-align: center;'>
103
  <img src='{dish['image']}' alt='{dish['name']}'
104
  style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'>
105
- <button onclick=\"showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}', '{dish['price']}')\"
106
- style=\"margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;
107
- border-radius: 5px; cursor: pointer;\">Add</button>
108
  </div>
109
  </div>
110
  """
@@ -155,23 +155,33 @@ with gr.Blocks() as demo:
155
  color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
156
  </div>
157
  <script>
158
- function showPopup(image, title, description, price) {
159
- document.getElementById('popup-image').src = image;
160
- document.getElementById('popup-title').textContent = title;
161
- document.getElementById('popup-description').textContent = description;
162
- document.getElementById('popup-price').textContent = "Price: " + price;
163
 
164
- // Display the popup
165
- document.getElementById('popup').style.display = 'block';
166
- }
167
- function closePopup() {
168
- document.getElementById('popup').style.display = 'none';
169
- }
170
- function addToCart(dishName, spiceLevel) {
171
- const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
172
- alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
173
- }
174
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
175
  """)
176
  # Button click events
177
  btn_all.click(
 
102
  <div style='text-align: center;'>
103
  <img src='{dish['image']}' alt='{dish['name']}'
104
  style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'>
105
+ <button onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}', '{dish['price']}', event)"
106
+ style="margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;
107
+ border-radius: 5px; cursor: pointer;">Add</button>
108
  </div>
109
  </div>
110
  """
 
155
  color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
156
  </div>
157
  <script>
158
+ function showPopup(image, title, description, price, event) {
159
+ // Get the position of the clicked item
160
+ const rect = event.target.getBoundingClientRect();
 
 
161
 
162
+ // Set the content of the pop-up
163
+ document.getElementById('popup-image').src = image;
164
+ document.getElementById('popup-title').textContent = title;
165
+ document.getElementById('popup-description').textContent = description;
166
+ document.getElementById('popup-price').textContent = "Price: " + price;
167
+
168
+ // Position the pop-up near the clicked item
169
+ const popup = document.getElementById('popup');
170
+ popup.style.display = 'block';
171
+ popup.style.position = 'absolute';
172
+ popup.style.top = `${rect.top + window.scrollY + rect.height + 10}px`; // Below the button
173
+ popup.style.left = `${rect.left + window.scrollX}px`; // Align with the left of the button
174
+ }
175
+
176
+ function closePopup() {
177
+ document.getElementById('popup').style.display = 'none';
178
+ }
179
+
180
+ function addToCart(dishName, spiceLevel) {
181
+ const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
182
+ alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
183
+ }
184
+ </script>
185
  """)
186
  # Button click events
187
  btn_all.click(