| @@ -12,8 +12,21 @@ | ||
| 12 | 12 | |
| 13 | 13 | // Translation helpers — idempotent shim matching booking.js / trip.js so |
| 14 | 14 | // `__()` resolves through wp.i18n when wp-i18n is enqueued, otherwise it |
| 15 | 15 | // falls back to the source string. |
| 16 | +// Parse a numeric min/max attribute while preserving a legitimate 0. | |
| 17 | +// `parseInt(el.getAttribute('max')) || 99` treated max="0" — what a sold-out | |
| 18 | +// departure renders — as "unset" and fell back to the placeholder ceiling, so | |
| 19 | +// the guest selector stayed usable and ignored the departure's real capacity. | |
| 20 | +// Only an absent or non-numeric value may fall back. Installed once and shared | |
| 21 | +// by every frontend script, so load order does not matter. | |
| 22 | +if (typeof window.yatraNumOr !== 'function') { | |
| 23 | + window.yatraNumOr = function (raw, fallback) { | |
| 24 | + var parsed = parseInt(raw, 10); | |
| 25 | + return isNaN(parsed) ? fallback : parsed; | |
| 26 | + }; | |
| 27 | +} | |
| 28 | + | |
| 16 | 29 | (function () { |
| 17 | 30 | var i18n = (window.wp && window.wp.i18n) ? window.wp.i18n : null; |
| 18 | 31 | if (i18n && typeof i18n.__ === 'function') { |
| 19 | 32 | window.__ = function (text, domain) { return i18n.__(text, domain || 'yatra'); }; |
| @@ -457,9 +470,9 @@ | ||
| 457 | 470 | <div class="yatra-group-discount-badge"> |
| 458 | 471 | <svg width="14" height="14" fill="currentColor" viewBox="0 0 20 20"> |
| 459 | 472 | <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/> |
| 460 | 473 | </svg> |
| 461 | - Group discount applied: -${window.yatraTripData?.currencySymbol || '$'}${discountAmount.toFixed(2)} | |
| 474 | + Group discount applied: -${typeof window.yatra_format_price_js === 'function' ? window.yatra_format_price_js(discountAmount) : (window.yatraTripData?.currencySymbol || '$') + discountAmount.toFixed(2)} | |
| 462 | 475 | </div> |
| 463 | 476 | `; |
| 464 | 477 | } else if (indicator) { |
| 465 | 478 | indicator.remove(); |
| @@ -559,10 +572,10 @@ | ||
| 559 | 572 | } |
| 560 | 573 | |
| 561 | 574 | if (!input) return; |
| 562 | 575 | |
| 563 | - const min = parseInt(input.getAttribute('min')) || 0; | |
| 564 | - const max = parseInt(input.getAttribute('max')) || 99; | |
| 576 | + const min = window.yatraNumOr(input.getAttribute('min'), 0); | |
| 577 | + const max = window.yatraNumOr(input.getAttribute('max'), 99); | |
| 565 | 578 | let value = parseInt(input.value) || 0; |
| 566 | 579 | |
| 567 | 580 | // Update value based on button type |
| 568 | 581 | if (btn.classList.contains('yatra-quantity-plus')) { |
| @@ -618,9 +631,9 @@ | ||
| 618 | 631 | // Regular pricing - sync all num_travelers and enquiry_adults inputs |
| 619 | 632 | const regularInputs = document.querySelectorAll('#num_travelers, #enquiry_adults'); |
| 620 | 633 | regularInputs.forEach(input => { |
| 621 | 634 | if (input !== sourceInput) { |
| 622 | - const max = parseInt(input.getAttribute('max')) || 99; | |
| 635 | + const max = window.yatraNumOr(input.getAttribute('max'), 99); | |
| 623 | 636 | input.value = Math.min(sourceValue, max); |
| 624 | 637 | } |
| 625 | 638 | }); |
| 626 | 639 | |
| @@ -627,9 +640,9 @@ | ||
| 627 | 640 | // Also sync to availability section inputs |
| 628 | 641 | const availabilityInputs = document.querySelectorAll('input[id^="num-travelers-"]'); |
| 629 | 642 | availabilityInputs.forEach(input => { |
| 630 | 643 | if (input !== sourceInput) { |
| 631 | - const max = parseInt(input.getAttribute('max')) || 99; | |
| 644 | + const max = window.yatraNumOr(input.getAttribute('max'), 99); | |
| 632 | 645 | input.value = Math.min(sourceValue, max); |
| 633 | 646 | } |
| 634 | 647 | }); |
| 635 | 648 | |
| @@ -654,15 +667,15 @@ | ||
| 654 | 667 | ); |
| 655 | 668 | |
| 656 | 669 | categoryInputs.forEach(input => { |
| 657 | 670 | if (input !== sourceInput) { |
| 658 | - const max = parseInt(input.getAttribute('max')) || 99; | |
| 671 | + const max = window.yatraNumOr(input.getAttribute('max'), 99); | |
| 659 | 672 | input.value = Math.min(sourceValue, max); |
| 660 | 673 | |
| 661 | 674 | // Update button states for this input |
| 662 | 675 | const row = input.closest('.yatra-quantity-row'); |
| 663 | 676 | if (row) { |
| 664 | - const min = parseInt(input.getAttribute('min')) || 0; | |
| 677 | + const min = window.yatraNumOr(input.getAttribute('min'), 0); | |
| 665 | 678 | const minusBtn = row.querySelector('.yatra-quantity-minus'); |
| 666 | 679 | const plusBtn = row.querySelector('.yatra-quantity-plus'); |
| 667 | 680 | if (minusBtn) minusBtn.disabled = input.value <= min; |
| 668 | 681 | if (plusBtn) plusBtn.disabled = input.value >= max; |