} if (this.isSearchInputClear) { this.clearResults()

admin 全部赛事 2024-03-02 26 0

  0; }, get isShowMoreResults() { return this.scores.length > 0; }, get isNoResults() { return this.scores.length === 0; }, get isSearchInputClear() { return this.searchText.trim() === ''; }, handleSearchInput() { const { searchText } = this; if (this.numberOfActiveRequests) { this.resultsAbortController.abort(); this.resultsAbortController = new AbortController(); } if (this.isSearchInputClear) { this.clearResults(); this.closeSuggester(); return; } this.fetchResults(); }, handleFocus() { const { scores } = this; if (!this.isNoResults) this.openSuggester(); this.isSearchInputFocused = true; }, handleFocusLost(event) { this.isSearchInputFocused = false; if (this.isMouseInsideSuggester) return; this.closeSuggester(); }, handleClickOutsideSuggester() { if (this.isSearchInputFocused) return; this.closeSuggester(); }, applySearch(search) { const { baseURL, removePaginationFromURL } = this; const currentURL = removePaginationFromURL(window.location.href); const isResultsPage = currentURL.includes(baseURL); if (!isResultsPage) { const searchURL = `${baseURL}?search-string=${search}`; window.location.href = searchURL; return; } const updatedURL = new URL(currentURL); updatedURL.searchParams.set('search-string', search); window.location.href = updatedURL; }, fetchResults() { this.openSuggester(); this.numberOfActiveRequests++; const requestURL = this.baseURL.replace('results', 'suggestions'); fetch(`${requestURL}?search-string=${this.searchText}`, { signal: this.resultsAbortController.signal }) .then(response => response.json()) .then(response => this.setResults(response)) .catch(() => this.clearResults()) .finally(() => { this.numberOfActiveRequests--; }) }, setResults({ scores, keywords }) { this.scores = scores || []; this.keywords = keywords || []; }, clearResults() { this.scores = []; this.keywords = []; }, removePaginationFromURL(url) { const regex = //page-d+/i; return url.replace(regex, ''); }, openSuggester() { this.isShowSuggester = true; }, closeSuggester() { this.isShowSuggester = false; }, }" @clear-search.camel.window="applySearch('')" class="custom-input white" >

} if (this.isSearchInputClear) { this.clearResults()

} if (this.isSearchInputClear) { this.clearResults()

评论