| @@ -1,4 +1,17 @@ | ||
| 1 | +// Parse a numeric min/max attribute while preserving a legitimate 0. | |
| 2 | +// `parseInt(el.getAttribute('max')) || 99` treated max="0" — what a sold-out | |
| 3 | +// departure renders — as "unset" and fell back to the placeholder ceiling, so | |
| 4 | +// the guest selector stayed usable and ignored the departure's real capacity. | |
| 5 | +// Only an absent or non-numeric value may fall back. Installed once and shared | |
| 6 | +// by every frontend script, so load order does not matter. | |
| 7 | +if (typeof window.yatraNumOr !== 'function') { | |
| 8 | + window.yatraNumOr = function (raw, fallback) { | |
| 9 | + var parsed = parseInt(raw, 10); | |
| 10 | + return isNaN(parsed) ? fallback : parsed; | |
| 11 | + }; | |
| 12 | +} | |
| 13 | + | |
| 1 | 14 | function yatraScrollToBooking() { |
| 2 | 15 | const bookingForm = document.querySelector('.yatra-booking-form'); |
| 3 | 16 | if (bookingForm) { |
| 4 | 17 | bookingForm.scrollIntoView({ behavior: 'smooth', block: 'center' }); |
| @@ -62,9 +75,9 @@ | ||
| 62 | 75 | const targetId = this.getAttribute('data-target'); |
| 63 | 76 | const input = document.getElementById(targetId); |
| 64 | 77 | if (input) { |
| 65 | 78 | const current = parseInt(input.value) || 1; |
| 66 | - const min = parseInt(input.getAttribute('min')) || 1; | |
| 79 | + const min = window.yatraNumOr(input.getAttribute('min'), 1); | |
| 67 | 80 | if (current > min) { |
| 68 | 81 | input.value = current - 1; |
| 69 | 82 | updateMobileTotal(); |
| 70 | 83 | } |
| @@ -77,9 +90,9 @@ | ||
| 77 | 90 | const targetId = this.getAttribute('data-target'); |
| 78 | 91 | const input = document.getElementById(targetId); |
| 79 | 92 | if (input) { |
| 80 | 93 | const current = parseInt(input.value) || 1; |
| 81 | - const max = parseInt(input.getAttribute('max')) || 20; | |
| 94 | + const max = window.yatraNumOr(input.getAttribute('max'), 20); | |
| 82 | 95 | if (current < max) { |
| 83 | 96 | input.value = current + 1; |
| 84 | 97 | updateMobileTotal(); |
| 85 | 98 | } |