All checks were successful
continuous-integration/drone/push Build is passing
31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
import $ from 'jquery'
|
|
import qs from 'querystring';
|
|
|
|
function search(element) {
|
|
return new Promise(function (resolve, reject) {
|
|
resolve({
|
|
element: element,
|
|
search(query) {
|
|
element.classList.add('is-loading')
|
|
return fetch('/search/?' + qs.encode({q:query}))
|
|
.then(res => res.json())
|
|
.then(data => {
|
|
let actualResult = [];
|
|
$.each(data.hits, (key, value) => {
|
|
actualResult.push({
|
|
ref: value.fields.page,
|
|
title: value.fields.title,
|
|
text: value.fragments.text[0]
|
|
})
|
|
})
|
|
element.classList.remove('is-loading')
|
|
console.log(actualResult)
|
|
return actualResult
|
|
})
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
export default search;
|