|
|
@ -246,10 +246,12 @@ window.addEventListener('load', () => {
|
|
|
|
const input = document.querySelector('#local-search-input input')
|
|
|
|
const input = document.querySelector('#local-search-input input')
|
|
|
|
const statsItem = document.getElementById('local-search-stats-wrap')
|
|
|
|
const statsItem = document.getElementById('local-search-stats-wrap')
|
|
|
|
const $loadingStatus = document.getElementById('loading-status')
|
|
|
|
const $loadingStatus = document.getElementById('loading-status')
|
|
|
|
|
|
|
|
const isXml = !path.endsWith('json')
|
|
|
|
|
|
|
|
|
|
|
|
const inputEventFunction = () => {
|
|
|
|
const inputEventFunction = () => {
|
|
|
|
if (!localSearch.isfetched) return
|
|
|
|
if (!localSearch.isfetched) return
|
|
|
|
const searchText = input.value.trim().toLowerCase()
|
|
|
|
let searchText = input.value.trim().toLowerCase()
|
|
|
|
|
|
|
|
isXml && (searchText = searchText.replace(/</g, '<').replace(/>/g, '>'))
|
|
|
|
if (searchText !== '') $loadingStatus.innerHTML = '<i class="fas fa-spinner fa-pulse"></i>'
|
|
|
|
if (searchText !== '') $loadingStatus.innerHTML = '<i class="fas fa-spinner fa-pulse"></i>'
|
|
|
|
const keywords = searchText.split(/[-\s]+/)
|
|
|
|
const keywords = searchText.split(/[-\s]+/)
|
|
|
|
const container = document.getElementById('local-search-results')
|
|
|
|
const container = document.getElementById('local-search-results')
|
|
|
@ -259,11 +261,14 @@ window.addEventListener('load', () => {
|
|
|
|
resultItems = localSearch.getResultItems(keywords)
|
|
|
|
resultItems = localSearch.getResultItems(keywords)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (keywords.length === 1 && keywords[0] === '') {
|
|
|
|
if (keywords.length === 1 && keywords[0] === '') {
|
|
|
|
container.classList.add('no-result')
|
|
|
|
|
|
|
|
container.textContent = ''
|
|
|
|
container.textContent = ''
|
|
|
|
|
|
|
|
statsItem.textContent = ''
|
|
|
|
} else if (resultItems.length === 0) {
|
|
|
|
} else if (resultItems.length === 0) {
|
|
|
|
container.textContent = ''
|
|
|
|
container.textContent = ''
|
|
|
|
statsItem.innerHTML = `<div class="search-result-stats">${languages.hits_empty.replace(/\$\{query}/, searchText)}</div>`
|
|
|
|
const statsDiv = document.createElement('div')
|
|
|
|
|
|
|
|
statsDiv.className = 'search-result-stats'
|
|
|
|
|
|
|
|
statsDiv.textContent = languages.hits_empty.replace(/\$\{query}/, searchText)
|
|
|
|
|
|
|
|
statsItem.innerHTML = statsDiv.outerHTML
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
resultItems.sort((left, right) => {
|
|
|
|
resultItems.sort((left, right) => {
|
|
|
|
if (left.includedCount !== right.includedCount) {
|
|
|
|
if (left.includedCount !== right.includedCount) {
|
|
|
@ -276,7 +281,6 @@ window.addEventListener('load', () => {
|
|
|
|
|
|
|
|
|
|
|
|
const stats = languages.hits_stats.replace(/\$\{hits}/, resultItems.length)
|
|
|
|
const stats = languages.hits_stats.replace(/\$\{hits}/, resultItems.length)
|
|
|
|
|
|
|
|
|
|
|
|
container.classList.remove('no-result')
|
|
|
|
|
|
|
|
container.innerHTML = `<div class="search-result-list">${resultItems.map(result => result.item).join('')}</div>`
|
|
|
|
container.innerHTML = `<div class="search-result-list">${resultItems.map(result => result.item).join('')}</div>`
|
|
|
|
statsItem.innerHTML = `<hr><div class="search-result-stats">${stats}</div>`
|
|
|
|
statsItem.innerHTML = `<hr><div class="search-result-stats">${stats}</div>`
|
|
|
|
window.pjax && window.pjax.refresh(container)
|
|
|
|
window.pjax && window.pjax.refresh(container)
|
|
|
|