/* * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ "use strict"; $(function() { var copy = $("#page-search-copy"); var expand = $("#page-search-expand"); var searchLink = $("span#page-search-link"); var redirect = $("input#search-redirect"); function setSearchUrlTemplate() { var href = document.location.href.split(/[#?]/)[0]; href += "?q=" + "%s"; if (redirect.is(":checked")) { href += "&r=1"; } searchLink.html(href); copy[0].onmouseenter(); } function copyLink(e) { copyToClipboard(this.previousSibling.innerText); switchCopyLabel(this, this.lastElementChild); } copy.click(copyLink); copy[0].onmouseenter = function() {}; redirect.click(setSearchUrlTemplate); setSearchUrlTemplate(); copy.prop("disabled", false); redirect.prop("disabled", false); expand.click(function (e) { var searchInfo = $("div.page-search-info"); if(this.parentElement.hasAttribute("open")) { searchInfo.attr("style", "border-width: 0;"); } else { searchInfo.attr("style", "border-width: 1px;").height(searchInfo.prop("scrollHeight")); } }); }); $(window).on("load", function() { var input = $("#page-search-input"); var reset = $("#page-search-reset"); var notify = $("#page-search-notify"); var resultSection = $("div#result-section"); var resultContainer = $("div#result-container"); var searchTerm = ""; var activeTab = ""; var fixedTab = false; var visibleTabs = []; var feelingLucky = false; function renderResults(result) { if (!result.length) { notify.html(messages.noResult); } else if (result.length === 1) { notify.html(messages.oneResult); } else { notify.html(messages.manyResults.replace("{0}", result.length)); } resultContainer.empty(); var r = { "types": [], "members": [], "packages": [], "modules": [], "searchTags": [] }; for (var i in result) { var item = result[i]; var arr = r[item.category]; arr.push(item); } if (!activeTab || r[activeTab].length === 0 || !fixedTab) { Object.keys(r).reduce(function(prev, curr) { if (r[curr].length > 0 && r[curr][0].score > prev) { activeTab = curr; return r[curr][0].score; } return prev; }, 0); } if (feelingLucky && activeTab) { notify.html(messages.redirecting) var firstItem = r[activeTab][0]; window.location = getURL(firstItem.indexItem, firstItem.category); return; } if (result.length > 20) { if (searchTerm[searchTerm.length - 1] === ".") { if (activeTab === "types" && r["members"].length > r["types"].length) { activeTab = "members"; } else if (activeTab === "packages" && r["types"].length > r["packages"].length) { activeTab = "types"; } } } var categoryCount = Object.keys(r).reduce(function(prev, curr) { return prev + (r[curr].length > 0 ? 1 : 0); }, 0); visibleTabs = []; var tabContainer = $("
").appendTo(resultContainer); for (var key in r) { var id = "#result-tab-" + key.replace("searchTags", "search_tags"); if (r[key].length) { var count = r[key].length >= 1000 ? "999+" : r[key].length; if (result.length > 20 && categoryCount > 1) { var button = $("").appendTo(tabContainer); button.click(key, function(e) { fixedTab = true; renderResult(e.data, $(this)); }); visibleTabs.push(key); } else { $("" + categories[key] + " (" + count + ")").appendTo(tabContainer); renderTable(key, r[key]).appendTo(resultContainer); tabContainer = $("").appendTo(resultContainer); } } } if (activeTab && result.length > 20 && categoryCount > 1) { $("button#result-tab-" + activeTab).addClass("active-table-tab"); renderTable(activeTab, r[activeTab]).appendTo(resultContainer); } resultSection.show(); function renderResult(category, button) { activeTab = category; setSearchUrl(); resultContainer.find("div.summary-table").remove(); renderTable(activeTab, r[activeTab]).appendTo(resultContainer); button.siblings().removeClass("active-table-tab"); button.addClass("active-table-tab"); } } function selectTab(category) { $("button#result-tab-" + category).click(); } function renderTable(category, items) { var table = $("