4 import {htmlToDom} from "../services/dom";
9 this.container = this.$el;
10 this.input = this.$refs.input;
11 this.suggestions = this.$refs.suggestions;
12 this.suggestionResultsWrap = this.$refs.suggestionResults;
14 this.setupListeners();
18 this.input.addEventListener('input', () => {
19 const value = this.input.value;
20 if (value.length > 0) {
21 this.updateSuggestions(value);
23 this.hideSuggestions();
28 async updateSuggestions(search) {
29 const {data: results} = await window.$http.get('/ajax/search/entities', {term: search, count: 5});
30 const resultDom = htmlToDom(results);
32 const childrenToTrim = Array.from(resultDom.children).slice(9);
33 for (const child of childrenToTrim) {
37 this.suggestionResultsWrap.innerHTML = '';
38 this.suggestionResultsWrap.append(resultDom);
39 if (!this.container.classList.contains('search-active')) {
40 this.showSuggestions();
45 this.container.classList.add('search-active');
46 window.requestAnimationFrame(() => {
47 this.suggestions.classList.add('search-suggestions-animation');
52 this.container.classList.remove('search-active');
53 this.suggestions.classList.remove('search-suggestions-animation');
54 this.suggestionResultsWrap.innerHTML = '';
58 export default GlobalSearch;