1/******/ (() => { // webpackBootstrap 2(function () { 3 const initMenuBasedDropdownsView = () => { 4 const dropdowns = document.querySelectorAll('.colibri-blocks--menu-based-dropdowns'); 5 const DO_NOT_PRESELECT = '-do-not-preselect-'; 6 if (!dropdowns.length) { 7 return; 8 } 9 dropdowns.forEach(function (ctrl) { 10 const hash = ctrl.dataset.hash; 11 const button = ctrl.querySelector('button[type=submit]'); 12 const sel1 = ctrl.querySelector('.first-level select'); 13 const sel2 = ctrl.querySelector('.second-level select'); 14 const sel3 = ctrl.querySelector('.third-level select'); 15 let sel2Source = sel2 ? Array.from(sel2.querySelectorAll('option:not(:first-child)')) : null; 16 let sel3Source = sel3 ? Array.from(sel3.querySelectorAll('option:not(:first-child)')) : null; 17 if (!sel1 || !button) return; 18 function store(what, val) { 19 if (['sel1', 'sel2', 'sel3'].includes(what)) { 20 try { 21 window.localStorage.setItem('menu-based-dropdowns-' + what + '[' + hash + ']', val); 22 } catch (error) { 23 // Ignore storage errors (private mode / disabled storage). 24 } 25 } 26 } 27 function getStored(what) {
28 if (['sel1', 'sel2', 'sel3'].includes(what)) { 29 try { 30 return window.localStorage.getItem('menu-based-dropdowns-' + what + '[' + hash + ']'); 31 } catch (error) { 32 return null; 33 } 34 } 35 return null; 36 } 37 function getCapitalizedQueryState() { 38 try { 39 const raw = new URLSearchParams(window.location.search).get('state'); 40 return raw && /^[A-Z]{2}$/.test(raw) ? raw : ''; 41 } catch (error) { 42 return ''; 43 } 44 } 45 function restore() { 46 const urlState = getCapitalizedQueryState(); 47 var val1 = urlState ? '' : getStored('sel1'); 48 var val2 = urlState ? DO_NOT_PRESELECT : getStored('sel2'); 49 var val3 = urlState ? DO_NOT_PRESELECT : getStored('sel3'); 50 if (val1) { 51 sel1.value = val1; 52 } else { 53 // Use the option server already preselected (URL ?state or CF region) 54 const preselected = sel1.querySelector('option[selected]'); 55 if (preselected) { 56 sel1.value = preselected.value; 57 store('sel1', preselected.value); // Save option so it persists 58 } else { 59 sel1.value = '0'; 60 } 61 } 62 sel1.classList.add('is-initialized'); 63 sel1.style.color = 'unset'; 64 if (val2 === null || val2 === DO_NOT_PRESELECT) { 65 if (sel2) { 66 sel2.value = '0'; 67 sel2.classList.add('is-initialized'); 68 sel2.style.color = 'unset'; 69 } 70 } 71 if (val3 === null || val3 === DO_NOT_PRESELECT) { 72 if (sel3) { 73 sel3.value = '0'; 74 sel3.classList.add('is-initialized'); 75 sel3.style.color = 'unset'; 76 } 77 } 78 79 // If you were using the .triggerHandler('change') for event delegation or similar, 80 // you'd need to manually create and dispatch the event. 81 const customChangeEvent = new CustomEvent('change', { 82 detail: { 83 isRestoring: true 84 } 85 }); 86 sel1.dispatchEvent(customChangeEvent); 87 } 88 function repopulateOptions(name, sel, currParentVal, options) { 89 /** 90 * count the number of proper options (excluding the first option that only shows the prompt) 91 */ 92 let cntVisible = 0; 93 Array.from(sel.children).forEach((child, idx) => { 94 if (idx !== 0) sel.removeChild(child); 95 }); 96 if (currParentVal !== '0') { 97 cntVisible = 0; 98 options.forEach(opt => { 99 if (String(opt.dataset.parentId) === currParentVal) { 100 sel.appendChild(opt); 101 opt.hidden = false; 102 opt.disabled = false; 103 cntVisible++; 104 } 105 }); 106 if (cntVisible > 0) { 107 sel.disabled = false; 108 sel.parentElement.classList.add('is-interactive'); 109 } else { 110 sel.value = '0'; 111 sel.disabled = true; 112 sel.parentElement.classList.remove('is-interactive'); 113 } 114 } else { 115 sel.value = '0'; 116 sel.disabled = true; 117 sel.parentElement.classList.remove('is-interactive'); 118 } 119 return cntVisible; 120 } 121 function updateControls(name, sel, updateButton) { 122 const val = getStored(name); 123 if (sel.options.length === 2) { 124 /** 125 * if there is only one proper option, do select it automatically 126 */ 127 if (DO_NOT_PRESELECT !== val) { 128 if (sel.options.length >= 2) { 129 sel.options[1].selected = true; //selecting the first real option 130 } 131 if (updateButton) { 132 button.disabled = false; 133 } 134 } 135 } else if (sel.options.length > 2) { 136 sel.value = val === DO_NOT_PRESELECT || val === null ? '0' : val; 137 if (updateButton) { 138 button.disabled = '0' === sel.value; 139 } 140 } else { 141 /** 142 * this level has no applicable options, so just enable the button if an update is requested 143 */ 144 if (updateButton) { 145 button.disabled = false;
146 } 147 } 148 sel.classList.add('is-initialized'); 149 sel.style.color = 'unset'; 150 } 151 window.addEventListener('pageshow', function () { 152 if (!sel1.classList.contains('is-initialized')) { 153 restore(); 154 } 155 }); 156 window.addEventListener('pagehide', function () { 157 button.classList.remove('is-loading'); 158 const el = button.querySelector('i'); 159 if (el) el.classList.remove('has-spinner-icon'); 160 }); 161 sel1.addEventListener('change', function (e) { 162 const curr = sel1.value; 163 if (!e?.detail?.isRestoring) { 164 store('sel1', sel1.value); 165 store('sel2', '0'); 166 store('sel3', '0'); 167 } 168 if (!sel2) { 169 button.disabled = curr === '0'; 170 } else { 171 if (!sel2Source) { 172 sel2Source = Array.from(sel2.querySelectorAll('option:not(:first-child)')); 173 } 174 repopulateOptions('sel2', sel2, curr, sel2Source); 175 updateControls('sel2', sel2, !sel3); 176 sel2.dispatchEvent(new Event('change', { 177 'bubbles': true 178 })); 179 } 180 }); 181 if (sel2) { 182 sel2.addEventListener('change', function (e) { 183 // Disable button if there is nothing selected in the 2nd dropdown 184 let val = sel2.value; 185 store('sel2', val === '0' ? DO_NOT_PRESELECT : val); 186 if (sel3) { 187 let currOption = Array.from(sel2.querySelectorAll('option')).find(opt => opt.value === val); 188 let currParentId = currOption ? currOption.getAttribute('data-object-id') : ''; 189 if (!sel3Source) { 190 sel3Source = Array.from(sel3.querySelectorAll('option:not(:first-child)')); 191 } 192 repopulateOptions('sel3', sel3, currParentId, sel3Source); 193 updateControls('sel3', sel3, false); 194 button.disabled = sel3.options.length > 1 && sel3.value === '0' || val === '0'; 195 } else { 196 button.disabled = val === '0'; 197 } 198 }); 199 } 200 if (sel3) { 201 sel3.addEventListener('change', function (e) { 202 if (!e?.detail?.isRestoring) store('sel3', sel3.value); 203 button.disabled = sel3.value === '0'; 204 }); 205 } 206 button.addEventListener('click', function (e) { 207 let select; 208 if (sel3) { 209 if (sel3.querySelectorAll('option').length > 1) { 210 select = sel3; 211 } 212 } else if (sel2) { 213 if (sel2.querySelectorAll('option').length > 1) { 214 select = sel2; 215 } 216 } else { 217 select = sel1; 218 } 219 if (!select) { 220 e.preventDefault(); 221 return false; 222 } 223 let opt = select.querySelector('option:checked'); 224 let val = opt.value; 225 button.classList.add('is-loading'); 226 let icon = button.querySelector('i'); 227 if (icon) { 228 icon.classList.remove('has-right-angle-icon'); 229 icon.classList.add('has-spinner-icon'); 230 } 231 if (!isNaN(val)) { 232 // Replaces $.isNumeric 233 button.closest('form').submit(); 234 } else { 235 if (val.startsWith('//') || val.startsWith('http://') || val.startsWith('https://')) { 236 window.location.assign(val); 237 } else { 238 window.location.assign(window.location.origin + val); 239 } 240 e.preventDefault(); 241 return false; 242 } 243 return true; 244 }); 245 restore(); 246 }); 247 }; 248 if (document.readyState === 'loading') { 249 document.addEventListener('DOMContentLoaded', initMenuBasedDropdownsView, { 250 once: true 251 }); 252 } else { 253 initMenuBasedDropdownsView(); 254 } 255})(); 256/******/ })() 257; 258//# sourceMappingURL=menu-based-dropdowns-view.js.map
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.