Rammohan0504 commited on
Commit
3875b13
·
verified ·
1 Parent(s): 4565494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -95,11 +95,17 @@ extras = [
95
  # JavaScript for popup modal
96
  popup_js = """
97
  <script>
98
- function showPopup(name, description, price, image) {
99
  const popup = document.getElementById("custom-popup");
100
  const overlay = document.getElementById("overlay");
 
 
 
 
 
 
101
  popup.innerHTML = `
102
- <img src="${image}" alt="${name}" style="width: 100%; height: 200px; align-item:center; border-radius: 10px; margin-bottom: 10px;">
103
  <h3 style="margin-top: 10px;">${name}</h3>
104
  <p>${description}</p>
105
  <p style="font-weight: bold;">Price: ${price}</p>
@@ -125,6 +131,12 @@ popup_js = """
125
  <button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button>
126
  <button onclick="closePopup()" style="margin-top: 20px; margin-left: 10px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
127
  `;
 
 
 
 
 
 
128
  popup.style.display = "block";
129
  overlay.style.display = "block";
130
  }
@@ -136,6 +148,7 @@ popup_js = """
136
  overlay.style.display = "none";
137
  }
138
  </script>
 
139
  """
140
 
141
  # HTML for popup modal
@@ -160,10 +173,8 @@ def display_dishes(category):
160
  </div>
161
  <div style='flex: 1; text-align: center;'>
162
  <img src='{dish['image']}' alt='{dish['name']}' style='width: 120px; height: 80px; object-fit: cover; border-radius: 10px;'>
163
- <button onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}', '{dish['image']}')"
164
- style='margin-top: 10px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;'>
165
- Add
166
- </button>
167
  </div>
168
  </div>
169
  """
 
95
  # JavaScript for popup modal
96
  popup_js = """
97
  <script>
98
+ function showPopup(name, description, price, image, element) {
99
  const popup = document.getElementById("custom-popup");
100
  const overlay = document.getElementById("overlay");
101
+
102
+ // Get the bounding rectangle of the clicked element
103
+ const rect = element.getBoundingClientRect();
104
+ const offsetX = 10; // Offset for better alignment
105
+ const offsetY = 10;
106
+
107
  popup.innerHTML = `
108
+ <img src="${image}" alt="${name}" style="width: 200px; height: auto; border-radius: 10px; margin-bottom: 10px;">
109
  <h3 style="margin-top: 10px;">${name}</h3>
110
  <p>${description}</p>
111
  <p style="font-weight: bold;">Price: ${price}</p>
 
131
  <button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button>
132
  <button onclick="closePopup()" style="margin-top: 20px; margin-left: 10px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
133
  `;
134
+
135
+ // Set popup position based on the clicked element
136
+ popup.style.position = "absolute";
137
+ popup.style.top = `${rect.top + window.scrollY + offsetY}px`;
138
+ popup.style.left = `${rect.left + window.scrollX + offsetX}px`;
139
+
140
  popup.style.display = "block";
141
  overlay.style.display = "block";
142
  }
 
148
  overlay.style.display = "none";
149
  }
150
  </script>
151
+
152
  """
153
 
154
  # HTML for popup modal
 
173
  </div>
174
  <div style='flex: 1; text-align: center;'>
175
  <img src='{dish['image']}' alt='{dish['name']}' style='width: 120px; height: 80px; object-fit: cover; border-radius: 10px;'>
176
+ <button onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}', '{dish['image']}', this)"
177
+ style="margin-top: 10px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">Add</button>
 
 
178
  </div>
179
  </div>
180
  """