nagasurendra commited on
Commit
3b6bd65
·
verified ·
1 Parent(s): ce9af20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -17
app.py CHANGED
@@ -129,43 +129,40 @@ modal_and_cart_js = """
129
  };
130
  let finalized = false;
131
  function openModal(name, image, description, price) {
132
- if (finalized) {
133
  alert("You cannot add more items after finalizing your order.");
134
  return;
135
  }
 
136
  const modal = document.getElementById('modal');
137
  const buttonRect = event.target.getBoundingClientRect(); // Get button position
138
 
139
- // Adjust modal width based on screen size
140
- if (window.innerWidth <= 768) { // For phone screens
141
- modal.style.width = '90%';
142
- }
143
- else { // For larger screens (laptops)
144
- modal.style.width = '30%';
145
- }
146
 
147
  const modalWidth = modal.offsetWidth;
148
  const modalHeight = modal.offsetHeight;
149
 
150
- // Calculate the modal's position dynamically
151
  const modalTop = window.scrollY + buttonRect.top + buttonRect.height / 2 - modalHeight / 2;
152
  const modalLeft = window.scrollX + buttonRect.left + buttonRect.width / 2 - modalWidth / 2;
153
 
154
- // Set modal position
155
  modal.style.display = 'block';
156
- modal.style.position = 'absolute'; // Use absolute to position it dynamically
157
  modal.style.top = `${modalTop}px`;
158
  modal.style.left = `${modalLeft}px`;
159
 
160
- // Update modal content
161
  document.getElementById('modal-image').src = image;
162
  document.getElementById('modal-name').innerText = name;
163
  document.getElementById('modal-description').innerText = description;
164
- document.getElementById('modal-price').innerText = price;
165
 
166
- // Reset extras and input fields
167
- const extrasInputs = document.querySelectorAll('input[name="biryani-extra"]');
168
- extrasInputs.forEach(input => input.checked = false);
169
  document.getElementById('quantity').value = 1;
170
  document.getElementById('special-instructions').value = '';
171
  }
@@ -338,7 +335,7 @@ def app():
338
 
339
  # Modal window
340
  modal_window = gr.HTML("""
341
- <div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
342
  <div style="text-align: right;">
343
  <button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">&times;</button>
344
  </div>
 
129
  };
130
  let finalized = false;
131
  function openModal(name, image, description, price) {
132
+ if (finalized) {
133
  alert("You cannot add more items after finalizing your order.");
134
  return;
135
  }
136
+
137
  const modal = document.getElementById('modal');
138
  const buttonRect = event.target.getBoundingClientRect(); // Get button position
139
 
140
+ // Set modal width based on device size
141
+ if (window.innerWidth <= 768) {
142
+ modal.style.width = '90%'; // For mobile devices
143
+ } else {
144
+ modal.style.width = '30%'; // For laptops and larger screens
145
+ }
 
146
 
147
  const modalWidth = modal.offsetWidth;
148
  const modalHeight = modal.offsetHeight;
149
 
150
+ // Dynamically calculate modal position
151
  const modalTop = window.scrollY + buttonRect.top + buttonRect.height / 2 - modalHeight / 2;
152
  const modalLeft = window.scrollX + buttonRect.left + buttonRect.width / 2 - modalWidth / 2;
153
 
154
+ // Apply positioning styles
155
  modal.style.display = 'block';
 
156
  modal.style.top = `${modalTop}px`;
157
  modal.style.left = `${modalLeft}px`;
158
 
159
+ // Populate modal content
160
  document.getElementById('modal-image').src = image;
161
  document.getElementById('modal-name').innerText = name;
162
  document.getElementById('modal-description').innerText = description;
163
+ document.getElementById('modal-price').innerText = `$${price}`;
164
 
165
+ // Reset inputs
 
 
166
  document.getElementById('quantity').value = 1;
167
  document.getElementById('special-instructions').value = '';
168
  }
 
335
 
336
  # Modal window
337
  modal_window = gr.HTML("""
338
+ <div id="modal" style="display: none; position: absolute; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
339
  <div style="text-align: right;">
340
  <button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">&times;</button>
341
  </div>