1(() => { 2 const additionalOptions = {}; 3 const isSpeechRecognitionAPIAvailable = !!(window.SpeechRecognition || window.webkitSpeechRecognition); 4 5 const loadAssets = async (assets) => { 6 if (assets?.ASSETS) { 7 BX.load(assets.ASSETS); 8 } 9 10 if (assets?.EXT) { 11 BX.loadExt(assets.EXT); 12 } 13 }; 14 15 const selectOptionsHandler = async (eventdata) => { 16 const nodeSelectOptions = eventdata.target.closest(".search-title-options__button"); 17 if (!nodeSelectOptions) { 18 return; 19 } 20 21 BX.removeCustomEvent("app.document.click", selectOptionsHandler); 22 23 nodeSelectOptions.classList.add("loadings"); 24 await BX.Aspro.Loader.addExt("popover"); 25 nodeSelectOptions.classList.remove("loadings"); 26 BX.Aspro.xPopover.get(nodeSelectOptions).toggle(); 27 28 const updateCurrentPopover = (html) => { 29 const nodeActivePopover = document.querySelector(".xpopover .loading-state-before"); 30 if (nodeActivePopover) { 31 nodeActivePopover.insertAdjacentHTML("afterend", html); 32 nodeActivePopover.remove(); 33 } 34 }; 35 36 const updateDropdownList = (html) => { 37 const nodeDropdownContent = document.createRange().createContextualFragment(html); 38 39 const nodeListSearchTitleOptionsButton = document.querySelectorAll(".search-title-options__button"); 40 nodeListSearchTitleOptionsButton.forEach((nodeSearchTitleOptionsButton) => { 41 nodeSearchTitleOptionsButton 42 .querySelector(".xpopover-template") 43 .content.replaceChildren(nodeDropdownContent.cloneNode(true)); 44 }); 45 }; 46 47 const setContent = (html) => { 48 if (html) { 49 updateCurrentPopover(html); 50 updateDropdownList(html); 51 } 52 }; 53 54 BX.ajax 55 .runComponentAction("aspro:search.title.options", "load", { 56 mode: "ajax", 57 data: { 58 conditions: { 59 voice: isSpeechRecognitionAPIAvailable ? "Y" : "N", 60 }, 61 }, 62 }) 63 .then((response) => { 64 setContent(response.data?.html); 65 loadAssets(response.data?.componentResult); 66 }); 67 }; 68 69 const removeAdditionalOptions = () => { 70 const nodeListSearchTitleAdditionalOption = document.querySelectorAll(".search-title__additional-option"); 71 nodeListSearchTitleAdditionalOption.forEach((nodeSearchTitleAdditionalOption) => { 72 nodeSearchTitleAdditionalOption.remove(); 73 }); 74 }; 75 76 const refreshActiveButton = (option) => { 77 removeAdditionalOptions(); 78 79 const nodeListSearchTitleOptions = document.querySelectorAll(".search-title-options"); 80 nodeListSearchTitleOptions.forEach((nodeSearchTitleOptions) => { 81 if (additionalOptions[option]) { 82 nodeSearchTitleOptions.insertAdjacentHTML("afterend", additionalOptions[option]); 83 } 84 }); 85 }; 86 87 const changeOptionsHandler = async (eventdata) => { 88 const nodeSearchAreaOption = eventdata.target.closest(".dropdown-select__list-item-label"); 89 if (!nodeSearchAreaOption) { 90 return; 91 } 92 93 const { name, value } = nodeSearchAreaOption; 94 95 const changeOptionState = (option, activeValue) => { 96 const isActive = option.value === activeValue; 97 98 option.classList.toggle("dropdown-menu-item--current", isActive); 99 option.toggleAttribute("disabled", isActive); 100 }; 101 102 const setCurrentOption = (name, value) => { 103 const nodeForm = BX.Aspro?.xPopover?.toggleNode?.closest?.("form"); 104 if (nodeForm) { 105 const nodeListAreaOption = nodeForm?.querySelectorAll(`.dropdown-select__list-item-label[name="${name}"]`); 106 if (nodeListAreaOption.length) { 107 nodeListAreaOption.forEach((nodeAreaOption) => { 108 changeOptionState(nodeAreaOption, value); 109 }); 110 } 111 } 112 113 BX.Aspro?.xPopover?.hide?.(); 114 }; 115 116 const syncPopoverOptions = (name, value) => { 117 const nodeListSearchFormXpopover = document.querySelectorAll(".search-title-options__button .xpopover-template"); 118 119 nodeListSearchFormXpopover.forEach((nodeSearchFormXpopover) => { 120 const nodeListAdditionalOption = nodeSearchFormXpopover.content.querySelectorAll(`[name="${name}"]`); 121 nodeListAdditionalOption.forEach((nodeAdditionalOption) => { 122 changeOptionState(nodeAdditionalOption, value); 123 }); 124 }); 125 }; 126 127 const searchDropdownSelectAreaHandler = (target) => { 128 const nodeInputSearchType = target.closest('[name="type"]'); 129 if (!nodeInputSearchType) { 130 return; 131 } 132 133 const clearSearchResults = () => { 134 const nodeListSearchResult = document.querySelectorAll(".title-search-result"); 135 if (nodeListSearchResult.length) { 136 nodeListSearchResult.forEach((nodeSearchResult) => { 137 nodeSearchResult.classList.add("hidden"); 138 }); 139 } 140 }; 141 142 const setFormSearchArea = (searchArea) => { 143 const LIST_SEARCH_AREA = { 144 all: arAsproOptions.PAGES.SEARCH_PAGE_URL, 145 catalog: arAsproOptions.PAGES.CATALOG_PAGE_URL, 146 }; 147 148 const nodeListSearchTitleForm = document.querySelectorAll(".search-title__form"); 149 nodeListSearchTitleForm.forEach((nodeSearchTitleForm) => { 150 nodeSearchTitleForm.setAttribute("action", LIST_SEARCH_AREA[searchArea]); 151 nodeSearchTitleForm.querySelector('input[name="type"]').value = searchArea; 152 nodeSearchTitleForm.querySelector('input[name="q"]').placeholder = BX.message( 153 `SEARCH_AREA_${searchArea.toUpperCase()}` 154 ); 155 156 BX.message("SEARCH_AREA_DEFAULT", BX.message(`SEARCH_AREA_${searchArea.toUpperCase()}`)); 157 }); 158 }; 159 160 const resolveSearchInputFocus = (form) => { 161 if (!form) { 162 return; 163 } 164 165 const nodeSearhTitleFormInput = form.querySelector(".search-title__input"); 166 nodeSearhTitleFormInput?.setSelectionRange?.( 167 nodeSearhTitleFormInput.value.length, 168 nodeSearhTitleFormInput.value.length 169 ); 170 nodeSearhTitleFormInput.focus(); 171 }; 172 173 const nodeSearchForm = BX.Aspro?.xPopover?.toggleNode?.closest("form"); 174 const searchArea = nodeInputSearchType.value; 175 176 BX.Aspro.Loader.addExt("set_cookie_on_domains").then(() => {
177 setCookieOnDomains(BX.message("SEARCH_AREA_COOKIE_NAME"), searchArea); 178 }); 179 180 clearSearchResults(); 181 setFormSearchArea(searchArea); 182 resolveSearchInputFocus(nodeSearchForm); 183 }; 184 185 const searchDropdownSelectAdditionalOptionHandler = async (target) => { 186 const nodeInputAdditionalOption = target.closest('[name="additional"]'); 187 if (!nodeInputAdditionalOption) { 188 return; 189 } 190 191 BX.onCustomEvent("onAsproSearchOptionsChange"); 192 193 const searchDropdownAdditionalOptionToggleLoadingState = (active) => { 194 const nodeListAdditionalOption = document.querySelectorAll(".search-title__additional-option"); 195 if (nodeListAdditionalOption.length) { 196 nodeListAdditionalOption.forEach((nodeAdditionalOption) => { 197 nodeAdditionalOption.toggleAttribute("disabled", active); 198 nodeAdditionalOption.classList.toggle("loading-state-before", active); 199 }); 200 } 201 }; 202 203 searchDropdownAdditionalOptionToggleLoadingState(true); 204 205 try { 206 const option = nodeInputAdditionalOption.value; 207 208 if (typeof additionalOptions[option] === "undefined") { 209 const response = await BX.ajax.runComponentAction("aspro:search.title.options", "getButton", { 210 mode: "ajax", 211 data: { 212 option: option, 213 }, 214 }); 215 216 additionalOptions[option] = response.data?.BUTTON; 217 } else { 218 BX.ajax.runComponentAction("aspro:search.title.options", "refreshActiveButton", { 219 data: { 220 option: option, 221 }, 222 }); 223 } 224 225 refreshActiveButton(option); 226 } catch (e) { 227 console.error(e); 228 searchDropdownAdditionalOptionToggleLoadingState(false); 229 } 230 }; 231 232 setCurrentOption(name, value); 233 syncPopoverOptions(name, value); 234 searchDropdownSelectAreaHandler(nodeSearchAreaOption); 235 searchDropdownSelectAdditionalOptionHandler(nodeSearchAreaOption); 236 }; 237 238 BX.addCustomEvent("app.document.click", selectOptionsHandler); 239 240 BX.addCustomEvent("app.document.click", (eventdata) => { 241 changeOptionsHandler(eventdata); 242 }); 243 244 const requestDefaultOption = (option) => { 245 const nodeListSearchTitleAdditionalOption = document.querySelectorAll( 246 `.search-title__additional-option--${option}` 247 ); 248 if (nodeListSearchTitleAdditionalOption.length) { 249 const nodeSearchTitleOptionsButton = document.querySelector(".search-title-options__button"); 250 if (!nodeSearchTitleOptionsButton) { 251 removeAdditionalOptions(); 252 return; 253 } 254 255 try { 256 let arSearchOptions = JSON.parse(nodeSearchTitleOptionsButton?.dataset?.options); 257 if (arSearchOptions.length) { 258 arSearchOptions = arSearchOptions.filter((value) => value !== "area"); 259 } 260 261 const index = arSearchOptions.indexOf("voice"); 262 if (!!~index) { 263 if (!isSpeechRecognitionAPIAvailable) { 264 arSearchOptions.splice(index, 1); 265 } 266 } 267 268 if (!arSearchOptions.length) { 269 removeAdditionalOptions(); 270 return; 271 } 272 } catch (error) {} 273 274 const currentOption = nodeListSearchTitleAdditionalOption[0].value; 275 nodeListSearchTitleAdditionalOption.forEach((nodeSearchTitleAdditionalOption) => { 276 nodeSearchTitleAdditionalOption.classList.add("loading-state-before"); 277 }); 278 279 BX.ajax 280 .runComponentAction("aspro:search.title.options", "getDefaultButton", { 281 mode: "ajax", 282 data: { 283 option: currentOption, 284 }, 285 }) 286 .then((response) => { 287 additionalOptions[currentOption] = response.data?.BUTTON; 288 refreshActiveButton(currentOption); 289 loadAssets(response.data); 290 }); 291 } 292 }; 293 294 const updatePopoverContent = (option) => { 295 const nodePopover = document.querySelector(".xpopover"); 296 nodePopover?.querySelector(`.dropdown-select__list-item--${option}`)?.remove(); 297 nodePopover?.querySelector(".dropdown-select__list-item")?.classList?.add?.("dropdown-menu-item--current"); 298 299 const nodeListPopover = document.querySelectorAll(".search-title-options__button .xpopover-template"); 300 if (nodeListPopover.length) { 301 let content = ""; 302 nodeListPopover.forEach((nodePopover) => { 303 if (!content) { 304 content = nodePopover.content.cloneNode(true); 305 content?.querySelector(`.dropdown-select__list-item--${option}`)?.remove(); 306 content?.querySelector(".dropdown-select__list-item")?.classList?.add?.("dropdown-menu-item--current"); 307 } 308 309 nodePopover.content.replaceChildren(content.cloneNode(true)); 310 }); 311 } 312 }; 313 314 BX.addCustomEvent("onAsproSearchOptionsHandleOption", (eventdata) => { 315 if (!eventdata.option) { 316 return; 317 } 318 319 requestDefaultOption(eventdata.option); 320 updatePopoverContent(eventdata.option); 321 }); 322 323 BX.Aspro.Utils.readyDOM(() => { 324 const nodeSearchTitleOptionsButton = document.querySelector(".search-title-options__button"); 325 if (!nodeSearchTitleOptionsButton) { 326 return; 327 } 328 329 const options = nodeSearchTitleOptionsButton?.dataset?.options; 330 if (options) {
331 try { 332 let arSearchOptions = JSON.parse(options); 333 if (!arSearchOptions.length) { 334 nodeSearchTitleOptionsButton.remove(); 335 return; 336 } 337 338 if (!!~arSearchOptions.indexOf("area")) { 339 return; 340 } 341 342 const index = arSearchOptions.indexOf("voice"); 343 if (!!~index) { 344 if (!isSpeechRecognitionAPIAvailable) { 345 arSearchOptions.splice(index, 1); 346 } 347 } 348 349 if (arSearchOptions.length <= 1) { 350 nodeSearchTitleOptionsButton.remove(); 351 } 352 } catch (error) { 353 console.info(error); 354 } 355 } 356 }); 357 358 BX.Aspro.Loader.addExt("popover"); 359})();
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.