1document.addEventListener('DOMContentLoaded', function() { 2 const initializedTabs = new Set(); 3 4 // Initialize clear button functionality for FIDS search 5 function initializeFidsSearchClear() { 6 const searchInput = document.querySelector('.tabs-widget__fids-search-input'); 7 const clearIcon = document.querySelector('.tabs-widget__clear-icon'); 8 const clearButton = document.getElementById('tabs-widget-clear-button'); 9 10 if (!searchInput || !clearIcon || !clearButton) { 11 return; 12 } 13 14 // Function to toggle clear icon visibility 15 function toggleClearIcon() { 16 if (searchInput.value.trim()) { 17 clearIcon.classList.remove('tabs-widget__clear-icon--hidden'); 18 } else { 19 clearIcon.classList.add('tabs-widget__clear-icon--hidden'); 20 } 21 } 22 23 // Show/hide clear icon based on initial input value 24 toggleClearIcon(); 25 26 // Show/hide clear icon as user types 27 searchInput.addEventListener('input', toggleClearIcon); 28 29 // Handle clear button click 30 clearButton.addEventListener('click', function(e) { 31 e.preventDefault(); 32 e.stopPropagation(); 33 searchInput.value = ''; 34 toggleClearIcon(); 35 searchInput.focus(); // Keep focus on the input field 36 }); 37 } 38 39 // Replace rental form selects using the shared functionality 40 function replaceRentalSelects() { 41 if (window.RentalFormEnhancements) { 42 window.RentalFormEnhancements.replaceSelects({ 43 containerId: 'VehicleSearchForm' 44 }); 45 } 46 } 47 48 // Handle driver checkbox functionality using the shared functionality 49 function handleDriverCheckbox() { 50 if (window.RentalFormEnhancements) { 51 window.RentalFormEnhancements.handleDriverCheckbox({ 52 applyLayoutClasses: true // Enable layout classes for tabs widget 53 }); 54 } 55 } 56 57 // Make date pickers keyboard accessible 58 function makeRepublicDatePickersAccessible() { 59 if (window.RentalFormEnhancements) { 60 window.RentalFormEnhancements.makeRepublicDatePickersAccessible(); 61 } 62 } 63 64 65 // Load rental widget 66 function loadRentalWidget() { 67 const container = document.getElementById('VehicleSearchForm'); 68 if (!container || initializedTabs.has('rental')) return; 69 70 const scriptUrl = container.dataset.scriptUrl; 71 if (!scriptUrl) return; 72 73 initializedTabs.add('rental'); 74 container.innerHTML = ''; 75 76 const script = document.createElement('script'); 77 script.src = scriptUrl; 78 script.async = true; 79 script.onerror = () => { 80 container.innerHTML = '<div class="tabs-widget__error-message">Failed to load rental search. Please try again later.</div>'; 81 }; 82 script.onload = () => { 83 setTimeout(handleDriverCheckbox, 500); 84 setTimeout(replaceRentalSelects, 600); 85 setTimeout(makeRepublicDatePickersAccessible, 700); 86 }; 87 88 document.body.appendChild(script); 89 } 90 91 // Initialize rental tab visibility observer 92 function initRentalTabObserver() { 93 const rentalContent = document.getElementById('rental-content'); 94 95 // Return early if rental content doesn't exist on this page 96 if (!rentalContent) { 97 return; 98 } 99 100 // Check initial state - tab.js uses 'hidden' class 101 if (!rentalContent.classList.contains('hidden')) { 102 loadRentalWidget(); 103 } 104 105 // Watch for visibility changes 106 const observer = new MutationObserver(mutations => { 107 mutations.forEach(mutation => { 108 if (mutation.type === 'attributes' && mutation.attributeName === 'class') { 109 // Check if element still exists before accessing classList 110 const target = mutation.target; 111 if (target && !target.classList.contains('hidden')) { 112 loadRentalWidget(); 113 } 114 } 115 }); 116 }); 117 118 // Only observe if the element exists 119 try { 120 observer.observe(rentalContent, { 121 attributes: true, 122 attributeFilter: ['class'] 123 }); 124 } catch (error) { 125 // Silently handle any observation errors 126 console.debug('MutationObserver could not be set up for rental content'); 127 } 128 } 129 130 // Initialize 131 initRentalTabObserver(); 132 initializeFidsSearchClear(); 133});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.