Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -80,7 +80,7 @@ def display_dishes(category):
|
|
| 80 |
<div id="item-{index}" style='margin: 10px; display: flex; align-items: center; justify-content: space-between;
|
| 81 |
width: 80%; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
|
| 82 |
background-color: #f9f9f9; cursor: pointer;'
|
| 83 |
-
onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}',
|
| 84 |
<div style='flex: 1; margin-right: 20px;'>
|
| 85 |
<h4 style='font-size: 18px; color: #444; margin: 0;'>{dish['name']}</h4>
|
| 86 |
<p style='font-size: 14px; color: #666; margin: 5px 0;'>{dish['description']}</p>
|
|
@@ -118,10 +118,9 @@ with gr.Blocks() as demo:
|
|
| 118 |
border-radius: 5px; cursor: pointer;">Close</button>
|
| 119 |
</div>
|
| 120 |
<script>
|
| 121 |
-
function showPopup(image, title, description,
|
| 122 |
// Get the item's position
|
| 123 |
-
const
|
| 124 |
-
const rect = item.getBoundingClientRect();
|
| 125 |
|
| 126 |
// Set pop-up content
|
| 127 |
const popup = document.getElementById('popup');
|
|
@@ -130,7 +129,7 @@ with gr.Blocks() as demo:
|
|
| 130 |
document.getElementById('popup-description').textContent = description;
|
| 131 |
|
| 132 |
// Position the pop-up near the item
|
| 133 |
-
popup.style.top = window.scrollY + rect.top + 'px';
|
| 134 |
popup.style.left = rect.left + 'px';
|
| 135 |
popup.style.display = 'block';
|
| 136 |
}
|
|
@@ -146,4 +145,4 @@ with gr.Blocks() as demo:
|
|
| 146 |
btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
|
| 147 |
btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
|
| 148 |
|
| 149 |
-
demo.launch()
|
|
|
|
| 80 |
<div id="item-{index}" style='margin: 10px; display: flex; align-items: center; justify-content: space-between;
|
| 81 |
width: 80%; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
|
| 82 |
background-color: #f9f9f9; cursor: pointer;'
|
| 83 |
+
onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}', this)">
|
| 84 |
<div style='flex: 1; margin-right: 20px;'>
|
| 85 |
<h4 style='font-size: 18px; color: #444; margin: 0;'>{dish['name']}</h4>
|
| 86 |
<p style='font-size: 14px; color: #666; margin: 5px 0;'>{dish['description']}</p>
|
|
|
|
| 118 |
border-radius: 5px; cursor: pointer;">Close</button>
|
| 119 |
</div>
|
| 120 |
<script>
|
| 121 |
+
function showPopup(image, title, description, element) {
|
| 122 |
// Get the item's position
|
| 123 |
+
const rect = element.getBoundingClientRect();
|
|
|
|
| 124 |
|
| 125 |
// Set pop-up content
|
| 126 |
const popup = document.getElementById('popup');
|
|
|
|
| 129 |
document.getElementById('popup-description').textContent = description;
|
| 130 |
|
| 131 |
// Position the pop-up near the item
|
| 132 |
+
popup.style.top = window.scrollY + rect.top + rect.height + 'px';
|
| 133 |
popup.style.left = rect.left + 'px';
|
| 134 |
popup.style.display = 'block';
|
| 135 |
}
|
|
|
|
| 145 |
btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
|
| 146 |
btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
|
| 147 |
|
| 148 |
+
demo.launch()
|