Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -129,30 +129,47 @@ modal_and_cart_js = """
|
|
| 129 |
};
|
| 130 |
let finalized = false;
|
| 131 |
function openModal(name, image, description, price) {
|
| 132 |
-
|
| 133 |
alert("You cannot add more items after finalizing your order.");
|
| 134 |
return;
|
| 135 |
}
|
| 136 |
const modal = document.getElementById('modal');
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
| 140 |
modal.style.width = '90%';
|
| 141 |
-
}
|
|
|
|
| 142 |
modal.style.width = '30%';
|
| 143 |
}
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
document.getElementById('modal-image').src = image;
|
| 148 |
document.getElementById('modal-name').innerText = name;
|
| 149 |
document.getElementById('modal-description').innerText = description;
|
| 150 |
document.getElementById('modal-price').innerText = price;
|
|
|
|
|
|
|
| 151 |
const extrasInputs = document.querySelectorAll('input[name="biryani-extra"]');
|
| 152 |
extrasInputs.forEach(input => input.checked = false);
|
| 153 |
document.getElementById('quantity').value = 1;
|
| 154 |
document.getElementById('special-instructions').value = '';
|
| 155 |
}
|
|
|
|
| 156 |
function closeModal() {
|
| 157 |
document.getElementById('modal').style.display = 'none';
|
| 158 |
}
|
|
|
|
| 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 |
}
|
| 172 |
+
|
| 173 |
function closeModal() {
|
| 174 |
document.getElementById('modal').style.display = 'none';
|
| 175 |
}
|