Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -105,6 +105,7 @@ def display_dishes(category):
|
|
| 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 |
"""
|
|
@@ -126,27 +127,15 @@ with gr.Blocks() as demo:
|
|
| 126 |
|
| 127 |
# JavaScript for managing the pop-up
|
| 128 |
gr.HTML("""
|
| 129 |
-
<div id="popup" style="display: none; position:
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
<div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 139 |
-
""" + "".join([
|
| 140 |
-
f'<label style="margin-right: 10px; display: block;"><input type="radio" name="spice" value="{spice}" style="margin-right: 5px;">{spice}</label>'
|
| 141 |
-
for spice in spice_levels]) + """
|
| 142 |
-
</div>
|
| 143 |
-
|
| 144 |
-
<h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
|
| 145 |
-
<div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 146 |
-
""" + "".join([
|
| 147 |
-
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>'
|
| 148 |
-
for extra in extras]) + """
|
| 149 |
-
</div>
|
| 150 |
|
| 151 |
<button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)"
|
| 152 |
style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
|
|
@@ -160,17 +149,17 @@ with gr.Blocks() as demo:
|
|
| 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`; //
|
| 173 |
-
popup.style.left = `${rect.left + window.scrollX}px`; // Align with the left
|
| 174 |
}
|
| 175 |
|
| 176 |
function closePopup() {
|
|
@@ -182,6 +171,7 @@ with gr.Blocks() as demo:
|
|
| 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(
|
|
|
|
| 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 |
+
|
| 109 |
</div>
|
| 110 |
</div>
|
| 111 |
"""
|
|
|
|
| 127 |
|
| 128 |
# JavaScript for managing the pop-up
|
| 129 |
gr.HTML("""
|
| 130 |
+
<div id="popup" style="display: none; position: absolute; background-color: white; padding: 20px; border-radius: 10px;
|
| 131 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 300px;">
|
| 132 |
+
<img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
|
| 133 |
+
<h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
|
| 134 |
+
<p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
|
| 135 |
+
<p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
|
| 136 |
+
<button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #007bff;
|
| 137 |
+
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 138 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
<button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)"
|
| 141 |
style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
|
|
|
|
| 149 |
const rect = event.target.getBoundingClientRect();
|
| 150 |
|
| 151 |
// Set the content of the pop-up
|
| 152 |
+
const popup = document.getElementById('popup');
|
| 153 |
document.getElementById('popup-image').src = image;
|
| 154 |
document.getElementById('popup-title').textContent = title;
|
| 155 |
document.getElementById('popup-description').textContent = description;
|
| 156 |
document.getElementById('popup-price').textContent = "Price: " + price;
|
| 157 |
|
| 158 |
// Position the pop-up near the clicked item
|
|
|
|
| 159 |
popup.style.display = 'block';
|
| 160 |
popup.style.position = 'absolute';
|
| 161 |
+
popup.style.top = `${rect.top + window.scrollY + rect.height + 10}px`; // Slightly below the button
|
| 162 |
+
popup.style.left = `${rect.left + window.scrollX}px`; // Align with the button's left side
|
| 163 |
}
|
| 164 |
|
| 165 |
function closePopup() {
|
|
|
|
| 171 |
alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
|
| 172 |
}
|
| 173 |
</script>
|
| 174 |
+
|
| 175 |
""")
|
| 176 |
# Button click events
|
| 177 |
btn_all.click(
|