Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -141,7 +141,7 @@ with gr.Blocks() as demo:
|
|
| 141 |
|
| 142 |
# JavaScript for managing the pop-up
|
| 143 |
gr.HTML(f"""
|
| 144 |
-
<div id="popup" style="display: none; position:
|
| 145 |
background-color: white; padding: 20px; border-radius: 10px;
|
| 146 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
|
| 147 |
<img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
|
|
@@ -166,12 +166,18 @@ with gr.Blocks() as demo:
|
|
| 166 |
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 167 |
</div>
|
| 168 |
<script>
|
| 169 |
-
function showPopup(image, title, description, price) {
|
| 170 |
document.getElementById('popup-image').src = image;
|
| 171 |
document.getElementById('popup-title').textContent = title;
|
| 172 |
document.getElementById('popup-description').textContent = description;
|
| 173 |
document.getElementById('popup-price').textContent = "Price: " + price;
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
// Display the popup
|
| 176 |
document.getElementById('popup').style.display = 'block';
|
| 177 |
}
|
|
@@ -182,6 +188,11 @@ with gr.Blocks() as demo:
|
|
| 182 |
const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
|
| 183 |
alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
|
| 184 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
</script>
|
| 186 |
""")
|
| 187 |
|
|
|
|
| 141 |
|
| 142 |
# JavaScript for managing the pop-up
|
| 143 |
gr.HTML(f"""
|
| 144 |
+
<div id="popup" style="display: none; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
|
| 145 |
background-color: white; padding: 20px; border-radius: 10px;
|
| 146 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
|
| 147 |
<img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
|
|
|
|
| 166 |
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 167 |
</div>
|
| 168 |
<script>
|
| 169 |
+
function showPopup(event, (image, title, description, price)) {
|
| 170 |
document.getElementById('popup-image').src = image;
|
| 171 |
document.getElementById('popup-title').textContent = title;
|
| 172 |
document.getElementById('popup-description').textContent = description;
|
| 173 |
document.getElementById('popup-price').textContent = "Price: " + price;
|
| 174 |
|
| 175 |
+
// Set the position of the popup
|
| 176 |
+
|
| 177 |
+
popup.style.left = `${event.pageX + 10}px`; // Add a small offset
|
| 178 |
+
popup.style.top = `${event.pageY + 10}px`; // Add a small offset
|
| 179 |
+
|
| 180 |
+
|
| 181 |
// Display the popup
|
| 182 |
document.getElementById('popup').style.display = 'block';
|
| 183 |
}
|
|
|
|
| 188 |
const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
|
| 189 |
alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
|
| 190 |
}
|
| 191 |
+
|
| 192 |
+
const menuItems = document.querySelectorAll('.menu-item');
|
| 193 |
+
menuItems.forEach(item => {item.addEventListener('click', function(event) {showPopup(event, item.getAttribute('data-name'));
|
| 194 |
+
});
|
| 195 |
+
});
|
| 196 |
</script>
|
| 197 |
""")
|
| 198 |
|