1$(document).ready(function () { 2 var lastQuery = ""; 3 var cachedResults = null; 4 var cachedResultsGlobalHeader = null; 5 var debounceTimer = null; 6 var searchHistory = getSearchHistoryFromCookies(); 7 var abortController = null; 8 var hasShownHistory = false; 9 var baseApiUrl = ""; 10 var key = ""; 11 12 baseApiUrl = 13 "https://peregrine-api-257861816711.asia-northeast1.run.app/v1/suggest?query="; 14 key = "PtBlgAtdnQXMz69FTHKg5RRxYoiQ99eCZ3VOKSuDdescFKH8djrQNRgrWc5zCx3G"; 15 if (SERVER_TYPE == "dev" || SERVER_TYPE == "test") { 16 baseApiUrl = 17 "https://peregrine-api-dev-736285889722.asia-northeast1.run.app/v1/suggest?query="; 18 key = "wkxP6TyRp109jeIbNmj6wuhuZv4wkBBORN348U43Rxa7reWfrrlxFoQXbNDkvPw9"; 19 } else if (HOST_NAME == SERVER_PROTOCOL + "debug.veltra.com") { 20 baseApiUrl = 21 "https://peregrine-api-stage-257861816711.asia-northeast1.run.app/v1/suggest?query="; 22 key = "PtBlgAtdnQXMz69FTHKg5RRxYoiQ99eCZ3VOKSuDdescFKH8djrQNRgrWc5zCx3G"; 23 } 24 25 var departureValues = { 26 mobile: $('input[name="departure-mobile"]:checked').val() || "", 27 pc: $('input[name="departure-pc"]:checked').val() || "", 28 }; 29 30 //set translation 31 var translations = { 32 en: { 33 radioTitle: "Search history", 34 deleteHistory: "Clear history", 35 }, 36 ja: { 37 radioTitle: "æ¤ç´¢å±¥æ´", 38 deleteHistory: "å±¥æ´ãã¯ãªã¢", 39 }, 40 }; 41 42 //translate text for en and jp 43 function translate(key, lang_id) { 44 var language = lang_id == "1" ? "en" : "ja"; 45 46 return translations[language] && translations[language][key] 47 ? translations[language][key] 48 : key; 49 } 50 51 //check if user is currently using mobile form 52 function isMobileForm() { 53 return ( 54 document.querySelector(".search-renewal-mobile .search-renewal") === 55 document.activeElement && 56 $(".search-renewal-mobile .search-renewal").val() 57 ); 58 } 59 60 //check if user is currently using pc form 61 function isPCForm() { 62 return ( 63 document.querySelector(".search-renewal-pc .search-renewal") === 64 document.activeElement && $(".search-renewal-pc .search-renewal").val() 65 ); 66 } 67 68 //set cookie 69 function setCookie(name, value, days) { 70 var expires = ""; 71 if (days) { 72 var date = new Date(); 73 date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); 74 expires = "; expires=" + date.toUTCString(); 75 } 76 document.cookie = 77 name + "=" + (encodeURIComponent(value) || "") + expires + "; path=/"; 78 } 79 80 //get cookie 81 function getCookie(name) { 82 var nameEQ = name + "="; 83 var ca = document.cookie.split(";"); 84 for (var i = 0; i < ca.length; i++) { 85 var c = ca[i]; 86 while (c.charAt(0) == " ") c = c.substring(1, c.length); 87 if (c.indexOf(nameEQ) == 0) 88 return decodeURIComponent(c.substring(nameEQ.length, c.length)); 89 } 90 return null; 91 } 92 93 //erase cookie 94 function eraseCookie(name) { 95 document.cookie = name + "=; Max-Age=0; path=/;"; 96 } 97 98 //get searchHistory cookie 99 function getSearchHistoryFromCookies() { 100 var cookieValue = getCookie("searchHistory"); 101 return cookieValue ? JSON.parse(cookieValue) : []; 102 } 103 104 //save as search history to cookie 105 function saveSearchHistoryToCookies(historyArray) { 106 setCookie("searchHistory", JSON.stringify(historyArray), 14); 107 } 108 109 //save search keyword to peregrine 110 function saveSearchKeywordToPeregrine(keyword, originId) { 111 $.ajax({ 112 url: "/tr_json/store_search_keyword", 113 type: "POST", 114 contentType: "application/json", 115 data: JSON.stringify({ keyword: keyword, origin_id: originId }), 116 }); 117 } 118 119 //delete search history from peregrine 120 function deleteSearchHistoryFromPeregrine() { 121 $.ajax({ 122 url: "/tr_json/delete_search_history", 123 type: "GET", 124 }); 125 } 126 127 //add search history and pass to saveSearchHistoryToCookies 128 function addSearchToHistory( 129 searchTerm, 130 url, 131 domain, 132 lang, 133 created, 134 originId 135 ) { 136 var newEntry = { 137 domain: domain, 138 lang: lang, 139 text: searchTerm, 140 url: url, 141 created: created, 142 }; 143 144 var exists = searchHistory.some(function (entry) { 145 return ( 146 entry.text === searchTerm && 147 entry.url === url && 148 entry.domain === domain && 149 entry.lang === lang 150 ); 151 }); 152 153 if (!exists) { 154 searchHistory.unshift(newEntry); 155 if (searchHistory.length > 10) { 156 // Limit the size 157 searchHistory.pop(); 158 } 159 saveSearchHistoryToCookies(searchHistory); 160 } 161 162 // always save search keyword to peregrine 163 saveSearchKeywordToPeregrine(searchTerm, originId); 164 } 165 166 //highlight the text based on user input 167 function matchText(text, query) { 168 var regex = new RegExp("(" + query + ")", "gui"); 169 return text.replace(regex, '<span class="highlight">$1</span>'); 170 } 171 172 function getAddress(addresses, departure, query) { 173 if (Array.isArray(addresses) && addresses.length > 0) { 174 var matchedAddress = addresses.find(function (address) { 175 return address.toLowerCase() === query.toLowerCase(); 176 }); 177 if (matchedAddress) { 178 return matchedAddress + "ã»"; 179 } 180 } 181 return departure; 182 } 183 184 //return html for search history 185 function showSearchHistory() { 186 var searchHistoryParent = 187 '<div class="search-renewal-search-history-container">' + 188 '<div class="title">' + 189 "<span>" + 190 translate("radioTitle", LANG_ID) + 191 "</span>" + 192 '<a class="delete-history" href="#" >' + 193 translate("deleteHistory", LANG_ID) + 194 "<a/>" + 195 "</div>" + 196 '<div class="search-history-results">'; 197
198 searchHistory.forEach(function (historyItem) { 199 searchHistoryParent += 200 '<div class="search-results-div"><a href="' + 201 historyItem.url + 202 '" class="result-label"><span class="history-result">' + 203 historyItem.text + 204 "</span></a></div>"; 205 }); 206 207 searchHistoryParent += "</div></div>"; 208 209 return searchHistoryParent; 210 } 211 212 //debounce function 213 function debounce(func, delay) { 214 return function () { 215 var args = arguments; 216 clearTimeout(debounceTimer); 217 debounceTimer = setTimeout(function () { 218 func.apply(this, args); 219 }, delay); 220 }; 221 } 222 223 //update device on changed radio button for this area or all area 224 function updateOnChange(element, targetDevice) { 225 var getQuery = element.val().trim().toLowerCase(); 226 var type = targetDevice === "departure-pc" ? "pc" : "mobile"; 227 228 if (getQuery) { 229 fetchSuggestions(getQuery, type); 230 } 231 } 232 233 //handle radio button function 234 function handleRadioChange(inputName, searchClass, key) { 235 document 236 .querySelectorAll('input[name="' + inputName + '"]') 237 .forEach(function (element) { 238 element.addEventListener("change", function () { 239 var newValue = $(this).val(); 240 var placeholderText = this.getAttribute("data-placeholder"); 241 var getOriginId = this.getAttribute("data-origin"); 242 var formElement = this.closest( 243 ".search-renewal-conditions" 244 ).previousElementSibling; 245 var submitElement = formElement.querySelector( 246 '[data-class="submit-renewal-results-button"]' 247 ); 248 249 if (this.checked) { 250 departureValues[key] = newValue; 251 var inputElement = document.querySelector( 252 searchClass + " .search-renewal" 253 ); 254 255 if (inputElement) { 256 inputElement.placeholder = placeholderText || ""; 257 } 258 259 submitElement.value = getOriginId; 260 261 updateOnChange($(searchClass + " .search-renewal"), inputName); 262 } 263 }); 264 }); 265 } 266 267 //fetch data from api 268 function fetchSuggestions(query, isRadioChangeDevice, isGlobalHeader) { 269 isGlobalHeader = 270 typeof isGlobalHeader !== "undefined" ? isGlobalHeader : false;
271 var globalTopPostfix = isGlobalHeader ? "-global-header" : ""; 272 var language = LANG_ID == 2 ? "ja" : "en"; 273 var size = 8; 274 275 var checkedRadioPC = $('input[name="departure-pc"]:checked'); 276 var checkedRadioMobile = $('input[name="departure-mobile"]:checked'); 277 278 apiUrl = 279 baseApiUrl + 280 encodeURIComponent(query) + 281 "&language=" + 282 language + 283 "&size=" + 284 size; 285 286 if(IS_HA) { 287 apiUrl += "&domain=www.hawaiiactivities.com"; 288 } 289 else { 290 apiUrl += "&domain=www.veltra.com"; 291 } 292 293 if ( 294 (isMobileForm() || isRadioChangeDevice === "mobile") && 295 departureValues.mobile.length > 0 296 ) { 297 if ( 298 checkedRadioMobile && 299 checkedRadioMobile.hasClass("all-area") && 300 IS_HA 301 ) { 302 apiUrl += "&addresses=" + encodeURIComponent(departureValues.mobile); 303 } else { 304 if (AREA_HAS_CHILD) { 305 apiUrl += "&addresses=" + encodeURIComponent(departureValues.mobile); 306 } else { 307 apiUrl += "&departure=" + encodeURIComponent(departureValues.mobile); 308 } 309 } 310 } else if ( 311 (isPCForm() || isRadioChangeDevice === "pc") && 312 departureValues.pc.length > 0 313 ) { 314 if (checkedRadioPC && checkedRadioPC.hasClass("all-area") && IS_HA) { 315 apiUrl += "&addresses=" + encodeURIComponent(departureValues.pc); 316 } else { 317 if (AREA_HAS_CHILD) { 318 apiUrl += "&addresses=" + encodeURIComponent(departureValues.pc); 319 } else { 320 apiUrl += "&departure=" + encodeURIComponent(departureValues.pc); 321 } 322 } 323 } 324 325 if (abortController) { 326 abortController.abort(); 327 } 328 329 abortController = new AbortController(); 330 331 fetch(apiUrl, { 332 signal: abortController.signal, 333 method: "GET", 334 headers: { 335 "x-api-key": key, 336 "Content-Type": "application/json", 337 }, 338 }) 339 .then(function (response) { 340 return response.json(); 341 }) 342 .then(function (data) { 343 var currentCacheResult = null; 344 if (isGlobalHeader) { 345 cachedResultsGlobalHeader = data.results; 346 currentCacheResult = cachedResultsGlobalHeader; 347 } else { 348 cachedResults = data.results; 349 currentCacheResult = cachedResults; 350 } 351 if (currentCacheResult.length > 0) { 352 displaySuggestions( 353 data.results, 354 query, 355 isRadioChangeDevice, 356 isGlobalHeader 357 ); 358 } else { 359 $(".search-renewal-results-container" + globalTopPostfix).hide(); 360 $(".search-renewal-results" + globalTopPostfix).empty(); 361 } 362 }) 363 .catch(function (error) { 364 if (error.name === "AbortError") { 365 return; 366 } 367 368 console.error("Error fetching suggestions:", error); 369 }); 370 } 371 372 //present data/search suggestion to search renewal results 373 function displaySuggestions(matchedResults, query, device, isGlobalHeader) { 374 isGlobalHeader = 375 typeof isGlobalHeader !== "undefined" ? isGlobalHeader : false;
376 var globalTopPostfix = isGlobalHeader ? "-global-header" : ""; 377 378 $(".search-renewal-results-container" + globalTopPostfix).hide(); 379 $(".search-renewal-results" + globalTopPostfix).empty(); 380 381 query = query.normalize("NFC"); 382 383 if (matchedResults.length > 0) { 384 var areaCount = 0; 385 var categoryCount = 0; 386 var acCount = 0; 387 var keywordCount = 0; 388 389 matchedResults.forEach(function (suggestion) { 390 if (suggestion.documentType === "area") { 391 if (areaCount >= 4) return; 392 areaCount++; 393 } 394 395 if (suggestion.documentType === "keyword") { 396 if (keywordCount >= 4) return; 397 keywordCount++; 398 } 399 400 if (suggestion.documentType === "category") { 401 if (categoryCount >= 4) return; 402 categoryCount++; 403 } 404 405 if (suggestion.documentType === "activity") { 406 if (acCount >= 8) return; 407 acCount++; 408 } 409 410 var normalizedName = suggestion.name 411 ? suggestion.name.normalize("NFC") 412 : ""; 413 var normalizedDeparture = suggestion.departure 414 ? suggestion.departure.normalize("NFC") 415 : ""; 416 417 var highlightedName = matchText(normalizedName, query); 418 var highlightDeparture = matchText(normalizedDeparture, query); 419 var childList = 420 suggestion.child !== null && suggestion.child.length > 0 421 ? suggestion.child 422 .slice(0, 4) 423 .map(function (child) { 424 return ( 425 '<a href="' + 426 HOST_NAME + 427 "/" + 428 SITE_CODE + 429 child.url + 430 '" class="result-label word-link" data-term="' + 431 child.name + 432 '">' + 433 '<span class="area-result">' + 434 child.name + 435 "</span>" + 436 "</a>" 437 ); 438 }) 439 .join("") 440 : ""; 441 442 var setImage = 443 suggestion.images && suggestion.images.length > 0 444 ? suggestion.images[0] 445 : "https://d2cl8o4a9a2idh.cloudfront.net/ptr/no_img_8.jpg"; 446 447 var setURL = 448 suggestion.documentType === "activity" 449 ? suggestion.url 450 : HOST_NAME + "/" + SITE_CODE + suggestion.url; 451 452 var setDeparture = suggestion.departure 453 ? suggestion.departure.length > 0 454 ? suggestion.departure + "ã»" 455 : "" 456 : ""; 457 458 var setAddresses = ""; 459 if (suggestion.documentType !== "keyword" && suggestion.addresses) { 460 setAddresses = getAddress(suggestion.addresses, setDeparture, query); 461 } else { 462 setAddresses = setDeparture; 463 } 464 465 var highlightAddress = matchText(setAddresses, query); 466 467 var getArea = function () { 468 var value = 469 device === "pc" ? departureValues.pc : departureValues.mobile; 470 471 if (value === "") { 472 return ""; 473 } 474 475 if (value === "Hawaii" && IS_HA) { 476 return "hawaii/"; 477 } 478 479 return AREA_URL; 480 }; 481 482 var showAreaUrl = getArea(); 483 484 var resultHTML = ""; 485 486 switch(suggestion.documentType) { 487 case 'area': 488 resultHTML = 489 '<li class="word-suggestions ' + (suggestion.child.length > 0 ? 'pb-0' : '') +'">' + 490 '<a class="word-suggest '+ (suggestion.child.length > 0 ? 'spacer' : '') + 491 ' word-link" href="' + 492 "/" + 493 SITE_CODE + 494 suggestion.url + 495 '" data-term="'+ 496 suggestion.name + 497 '">' + 498 '<img class="word-icon" src="/_tr/vt/1/img/enhanced_search_handler/location-o.svg" alt="area-icon" width="20" height="20" />' + 499 '<div class="suggestion-results"><div class="suggestion-title">' + 500 highlightedName + 501 '</div>' + 502 (suggestion.addresses[2] !== undefined ? '<div class="city-country-name">' + suggestion.addresses[1] + '</div>' : '') + 503 '</div>' + 504 '</a>' + 505 (suggestion.child.length > 0 ? '<div class="country-results">' + childList + '</div>' : '') + 506 '</li>'; 507 break; 508 case 'keyword': 509 resultHTML = 510 '<li class="word-suggestions">' + 511 '<a class="word-suggest word-link" href="' + 512 window.location.origin + 513 "/" + 514 SITE_CODE + 515 showAreaUrl + 516 suggestion.url + 517 '" data-term="' + 518 setAddresses + 519 suggestion.name + 520 '">' + 521 '<img class="word-icon" src="/_tr/vt/1/img/enhanced_search_handler/magnifier-o.svg" alt="keyword-icon" width="20" height="20" />' + 522 '<div class="suggestion-results"><div class="suggestion-title">' + 523 highlightAddress + 524 highlightedName + 525 '</div>' + 526 (suggestion.addresses[2] !== undefined ? '<div class="city-country-name">' + suggestion.addresses[1] + '</div>' : '') + 527 '</div>' + 528 '</a>' + 529 '</li>'; 530 break; 531 case 'category': 532 if (setAddresses == "ããããã¼ã¸ã»") { 533 setAddresses = ""; 534 } 535 resultHTML = 536 '<li class="word-suggestions">' + 537 '<a class="word-suggest word-link" href="' + 538 window.location.origin + 539 "/" + 540 SITE_CODE + 541 suggestion.url + 542 '" data-term="' + 543 setAddresses + 544 suggestion.name + 545 '">' + 546 '<img class="word-icon" src="/_tr/vt/1/img/enhanced_search_handler/threeshapes-o.svg" alt="category-icon" width="20" height="20" />' + 547 '<div class="suggestion-results"><div class="suggestion-title">' + 548 highlightedName + 549 '</div>' + 550 (suggestion.addresses[2] !== undefined ? '<div class="city-country-name">' + suggestion.addresses[1] + '</div>' : '') + 551 '</div>' + 552 '</a>' + 553 '</li>'; 554 break; 555 default: 556 resultHTML = 557 "<li>" + 558 '<a class="results" href="' + 559 setURL + 560 '">' + 561 '<div class="search-renewal-image" style="background-image: url(\'' + 562 setImage + 563 "')\"></div>" + 564 '<div class="search-renewal-content">' + 565 '<div class="search-renewal-title">' + 566 highlightedName + 567 (highlightDeparture.length > 0 ? "ã»" + highlightDeparture : "") + 568 "</div>" + 569 (suggestion.departure 570 ? '<div class="search-renewal-location">' + 571 suggestion.departure + 572 "</div>" 573 : "") + 574 "</div>" + 575 "</a>" + 576 "</li>"; 577 break; 578 } 579 580 $(".search-renewal-results" + globalTopPostfix).append(resultHTML); 581 }); 582 583 $(".search-renewal-results-container" + globalTopPostfix).show(); 584 $(".search-renewal-results" + globalTopPostfix).show(); 585 586 document.querySelectorAll(".word-link").forEach(function (links) { 587 links.addEventListener("click", function () { 588 var searchTerm = this.getAttribute("data-term"); 589 var url = this.getAttribute("href"); 590 addSearchToHistory(searchTerm, url); 591 }); 592 }); 593 } else { 594 if (searchHistory.length > 0) { 595 $(".search-renewal-results-container" + globalTopPostfix).show(); 596 $(".search-renewal-results" + globalTopPostfix).show(); 597 $(".search-renewal-results" + globalTopPostfix).append( 598 showSearchHistory() 599 ); 600 } else { 601 $(".search-renewal-results-container" + globalTopPostfix).hide(); 602 $(".search-renewal-results" + globalTopPostfix).hide(); 603 } 604 } 605 } 606 607 handleRadioChange("departure-mobile", ".search-renewal-mobile", "mobile"); 608 handleRadioChange("departure-pc", ".search-renewal-pc", "pc"); 609 610 //when search input box is in focus, show search history or show search suggestion or new search suggestions 611 document 612 .querySelectorAll(".search-renewal, .search-renewal-global-header") 613 .forEach(function (element) { 614 var isGlobalHeader = element.classList.contains( 615 "search-renewal-global-header" 616 ); 617 var globalTopPostfix = isGlobalHeader ? "-global-header" : "";
618 var id = element.id; 619 element.addEventListener("focus", function () { 620 var currentCacheResult = isGlobalHeader 621 ? cachedResultsGlobalHeader 622 : cachedResults; 623 var device = 624 $(this).attr("id") === "pc-search-renewal" + globalTopPostfix 625 ? "pc" 626 : "mobile"; 627 var query = $(this).val().trim().toLowerCase(); 628 629 if ( 630 id && 631 id == "global-search-global-top-jp" && 632 window.innerWidth < 992 633 ) { 634 var positionElement; 635 636 if (/Android/i.test(navigator.userAgent)) { 637 positionElement = $("#" + id).offset().top - 50; 638 } else { 639 positionElement = $("#" + id).offset().top - 20; 640 } 641 642 $([document.documentElement, document.body]).animate( 643 { scrollTop: positionElement }, 644 500 645 ); 646 } 647 648 if (query.length === 0) { 649 if (searchHistory.length > 0) { 650 $(".search-renewal-results-container" + globalTopPostfix).show(); 651 $(".search-renewal-results" + globalTopPostfix) 652 .html(showSearchHistory()) 653 .show(); 654 } 655 } else if (currentCacheResult.length > 0) { 656 displaySuggestions( 657 currentCacheResult, 658 lastQuery, 659 device, 660 isGlobalHeader 661 ); 662 } else if (query.length > 0) { 663 debouncedFetchSuggestions(query, device, isGlobalHeader); 664 } 665 }); 666 }); 667 668 var debouncedFetchSuggestions = debounce(function ( 669 query, 670 device, 671 isGlobalHeader 672 ) { 673 isGlobalHeader = 674 typeof isGlobalHeader !== "undefined" ? isGlobalHeader : false;
675 if (query.length > 0) { 676 lastQuery = query; 677 fetchSuggestions(query, device, isGlobalHeader); 678 } 679 }, 680 100); 681 682 //when user is typing on the search input box, show search suggestions and search history if there is any 683 document 684 .querySelectorAll(".search-renewal, .search-renewal-global-header, .search-renewal-billboard-ha") 685 .forEach(function (element) { 686 var isGlobalHeader = element.classList.contains( 687 "search-renewal-global-header" 688 )||element.classList.contains("search-renewal-billboard-ha"); 689 var globalTopPostfix = isGlobalHeader ? "-global-header" : ""; 690 element.value = ""; 691 element.addEventListener("keyup", function () { 692 var device = 693 $(this).attr("id") === "pc-search-renewal" + globalTopPostfix 694 ? "pc" 695 : "mobile"; 696 var query = $(this).val().trim().toLowerCase(); 697 698 if (query.length === 0) { 699 if (abortController) { 700 abortController.abort(); 701 } 702 if (isGlobalHeader) cachedResultsGlobalHeader = null; 703 else cachedResults = null; 704 if (searchHistory.length > 0) { 705 $(".search-renewal-results-container" + globalTopPostfix).show(); 706 $(".search-renewal-results" + globalTopPostfix) 707 .html(showSearchHistory()) 708 .show(); 709 } 710 } else { 711 debouncedFetchSuggestions(query, device, isGlobalHeader); 712 } 713 }); 714 715 element.addEventListener("compositionend", function (event) { 716 var device = 717 $(this).attr("id") === "pc-search-renewal" + globalTopPostfix 718 ? "pc" 719 : "mobile"; 720 var query = event.target.value.trim().toLowerCase().normalize("NFC"); 721 if (query.length > 0) { 722 debouncedFetchSuggestions(query, device, isGlobalHeader); 723 } 724 }); 725 }); 726 727 document.addEventListener("click", function (e) { 728 //delete cookies when click on delete history 729 if (e.target.closest(".delete-history")) { 730 e.preventDefault(); 731 $(".search-renewal-results-container").hide(); 732 $(".search-renewal-results").empty().hide(); // Clear the search result 733 searchHistory = []; // Clear the history data 734 eraseCookie("searchHistory"); 735 deleteSearchHistoryFromPeregrine(); 736 } 737 738 //hide search result element when click outside of these classes 739 if ( 740 !$(e.target).closest( 741 ".search-renewal, .search-renewal-results, .search-renewal-submit, .search-renewal-icon, .middle-search-renewal, .middle-search-renewal-ha, .open-search-menu-list, .search-renewal-modal-title, .search-menu-list, .ha-search, .delete-history, #body-search-trigger" 742 ).length 743 ) { 744 $(".search-renewal-results-container").hide(); 745 $(".search-renewal-results").hide(); 746 hasShownHistory = false; 747 } 748 749 //hide search result element when click outside of these classes 750 if ( 751 $(e.target).closest( 752 '.search-menu .close, .menu-toggle[data-element="ha-menu-toggle"]' 753 ).length 754 ) { 755 $( 756 ".search-renewal-results-container, .search-renewal-results-container-global-header" 757 ).hide(); 758 $(".search-renewal-results, .search-renewal-results-global-header") 759 .empty() 760 .hide(); 761 hasShownHistory = false; 762 } 763 764 //hide search result element when click outside of these classes 765 if ( 766 !$(e.target).closest( 767 ".search-renewal-global-header, .search-renewal-results-container-global-header, .search-renewal-icon, .open-search-menu-list, .search-menu-list" 768 ).length 769 ) { 770 $(".search-renewal-results-container-global-header").hide(); 771 $(".search-renewal-results-global-header").empty().hide(); 772 hasShownHistory = false; 773 } 774 }); 775 776 //when submit, add search query to cookies and go to search?kw page 777 document 778 .querySelectorAll( 779 'form[name="keyword-search-renewal"], form[name="keyword-search-renewal-global-header"]' 780 ) 781 .forEach(function (form) { 782 form.addEventListener("submit", function (e) { 783 var globalTopPostfix = 784 form.getAttribute("name") === "keyword-search-renewal-global-header" 785 ? "-global-header" 786 : ""; 787 e.preventDefault(); 788 var url; 789 var language = LANG_ID == 2 ? "jp" : "en"; 790 var domain; 791 var lang = LANG_ID == 2 ? "ja" : "en"; 792 var created = new Date().toISOString().replace(/\.\d{3}/, ""); 793 var query = form 794 .querySelector(".search-renewal" + globalTopPostfix) 795 .value.trim(); 796 var hiddenInput = form.querySelector( 797 'input[data-class="submit-renewal-results-button' + 798 globalTopPostfix + 799 '"]' 800 ); 801 var originId = hiddenInput.value; 802 803 if (query.length > 0) { 804 if (originId == "10000") { 805 url = 806 window.location.origin + 807 "/" + 808 language + 809 "/search?kw=" + 810 encodeURIComponent(query); 811 domain = "www.veltra.com"; 812 } else if (originId == "50106") { 813 url = 814 window.location.origin + 815 "/" + 816 language + 817 "/hawaii" + 818 "/search?kw=" + 819 encodeURIComponent(query); 820 domain = "www.hawaiiactivities.com"; 821 } else { 822 url = 823 window.location.origin + 824 "/" + 825 language + 826 "/" + 827 AREA_URL + 828 "search?kw=" + 829 encodeURIComponent(query); 830 domain = "www.veltra.com"; 831 } 832 addSearchToHistory(query, url, domain, lang, created, originId); 833 form.submit(); 834 } 835 }); 836 }); 837 838 var middleSearchBar = document.querySelector(".middle-search-renewal"); 839 var middleSearchBarHA = document.querySelector(".middle-search-renewal-ha"); 840 var searchRenewalMobile = document.querySelector(".search-menu"); 841 var searchRenewalMobileHA = document.querySelector("#ha-search-container"); 842 843 // if there is middle search bar JP mobile, clicking the search input will open the right search menu 844 if (middleSearchBar) { 845 document 846 .querySelector(".middle-search-renewal") 847 .addEventListener("click", function () { 848 document.querySelector(".open-search-menu-list").click(); 849 setTimeout(function () { 850 window.scrollTo({ top: 0, behavior: "smooth" }); 851 }, 50); 852 }); 853 } 854 855 // if there is middle search bar HA mobile, clicking the search input will open the right search menu 856 if (middleSearchBarHA) { 857 document 858 .querySelector(".middle-search-renewal-ha") 859 .addEventListener("click", function () { 860 document.querySelector(".ha-search").click(); 861 setTimeout(function () { 862 window.scrollTo({ top: 0, behavior: "smooth" }); 863 }, 50); 864 }); 865 } 866 867 //will run when the side menu is open in mobile only, show search history, reset it when its closed. 868 var observer = new MutationObserver(function (mutationsList) { 869 mutationsList.forEach(function (mutation) { 870 if (mutation.attributeName === "class") { 871 var shouldShowHistory = 872 (searchRenewalMobile && 873 searchRenewalMobile.classList.contains("show")) || 874 (searchRenewalMobileHA && 875 searchRenewalMobileHA.classList.contains("opened")); 876 877 if (shouldShowHistory && !hasShownHistory && searchHistory.length > 0) { 878 $( 879 ".search-renewal-results-container, .search-renewal-results-container-global-header" 880 ).show(); 881 var searchHistoryParentContainer = $( 882 ".search-renewal-mobile .search-renewal-results, .search-renewal-mobile .search-renewal-results-global-header" 883 ); 884 if ( 885 searchHistoryParentContainer.find( 886 ".search-renewal-search-history-container" 887 ).length === 0 888 ) { 889 searchHistoryParentContainer.append(showSearchHistory()).show(); 890 } 891 hasShownHistory = true; 892 } else if (!shouldShowHistory) { 893 hasShownHistory = false;
894 } 895 } 896 }); 897 }); 898 899 if (searchRenewalMobile) { 900 observer.observe(searchRenewalMobile, { attributes: true }); 901 } 902 903 if (searchRenewalMobileHA) { 904 observer.observe(searchRenewalMobileHA, { attributes: true }); 905 } 906});
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.