newline
S-P/added-pkgin-for-macos-1587338026022
2020-04-19, S P
* Array representing each plugin row * @type {HTMLInputElement} var url = new URL(window.location); var params = url.searchParams; * @type {"All" | "Trusted" | "Community"} publisher: params.get("publisher") || "all", query: params.get("query") || "", * What type of plugin has been selected (params.get("type") || "") document.addEventListener("DOMContentLoaded", function() { // Iterate through rows and populate pluginRow = Array.from($("#plugin-table>tbody>tr")).map(function(elem) { var contents = function(selectorQuery) { head: contents(".plugin-heading"), info: contents(".plugin-info"), repo: contents(".plugin-repo"), isTrusted: elem.getAttribute("isTrusted") == "true", // Set up publisher selector interface var publisherSelectors = $("#publisher-selector"); var publisherChecked = $('input[id="' + searchState.publisher + '"]', publisherSelectors); publisherChecked.prop('checked', true); searchState.publisher = "all"; $('input[id="all"]', publisherSelectors).prop('checked', true); publisherSelectors.click(updateFilters); // Set up search box interface searchTextBox = document.querySelector("#plugin-filter-search"); searchTextBox.value = searchState.query; searchTextBox.addEventListener( debounce(500, updateFilters) // Set up plugin type selector interface document.querySelectorAll("#plugin-selector>label>input") ).forEach(function(elem) { if (searchState.type.has(elem.dataset.type)) { elem.addEventListener("click", pluginTypeSelectorClickEvent); $("#plugin-filters,#search-link-wrap").removeClass("hidden"); * Event handler for plugin type checkboxes * @param {MouseEvent} event * @param {HTMLInputElement} event.target function pluginTypeSelectorClickEvent({ target }) { searchState.type[target.checked ? "add" : "delete"](target.dataset.type); * Visually filters Plugins by toggling visibility function updateFilters() { searchState.query = (searchTextBox.value || "").toLowerCase(); searchState.publisher = $('input[name="publisher"]:checked')[0].value; pluginRow.forEach(function(row) { row.elem.classList.remove("hidden"); row.elem.classList.add("hidden"); params.set("publisher", searchState.publisher); params.set("query", searchState.query); params.set("type", Array.from(searchState.type).join(",")); var urlString = String(url); history.pushState({ path: urlString }, "", urlString); var link = $("#search-link"); link.attr("href", urlString); * Decides if a plugin row should be filtered function shouldFilter(row) { (!searchState.type.size || searchState.type.has(row.elem.dataset.type)) && (searchState.publisher == "all" || (searchState.publisher == "pidgin" && row.isTrusted) || (searchState.publisher == "community" && !row.isTrusted)) && row.head.toLowerCase().includes(searchState.query) || row.info.toLowerCase().includes(searchState.query) || row.repo.toLowerCase().includes(searchState.query)) * Simple Debounce function * @param {function} callback function debounce(time, callback) { return function(...args) { timer = setTimeout(function() {