4 import {htmlToDom} from "../services/dom";
9 this.input = this.$refs.input;
10 this.suggestions = this.$refs.suggestions;
11 this.suggestionResultsWrap = this.$refs.suggestionResults;
13 this.setupListeners();
17 this.input.addEventListener('input', () => {
18 const value = this.input.value;
19 if (value.length > 0) {
20 this.updateSuggestions(value);
22 this.hideSuggestions();
27 async updateSuggestions(search) {
28 const {data: results} = await window.$http.get('/ajax/search/entities', {term: search, count: 5});
29 const resultDom = htmlToDom(results);
31 const childrenToTrim = Array.from(resultDom.children).slice(9);
32 for (const child of childrenToTrim) {
36 this.suggestions.style.display = 'block';
37 this.suggestionResultsWrap.innerHTML = '';
38 this.suggestionResultsWrap.append(resultDom);
42 this.suggestions.style.display = null;
43 this.suggestionResultsWrap.innerHTML = '';
47 export default GlobalSearch;