Skip to content

Commit

Permalink
Update search.js
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR authored Mar 26, 2023
1 parent d168e12 commit 4ebef99
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions docs/assets/js/search.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
/* global Fuse:false */

(function () {
"use strict"
'use strict'

var searchInput = document.querySelector("#icons-body #search")
const iconsBody = document.querySelector('#icons-body')

var iconListContainer = document.querySelector("#icons-body ul#icons-list")
var iconElementList = iconListContainer.querySelectorAll(
"#icons-body ul#icons-list li"
)
if (!iconsBody) return

var iconDataList = Array.from(iconElementList).map((el) => ({
name: el.dataset.name,
categories: el.dataset.categories.split(" "),
tags: el.dataset.tags.split(" "),
const searchInput = iconsBody.querySelector('#search')
const iconListContainer = iconsBody.querySelector('#icons-list')
const iconElementList = iconListContainer.querySelectorAll('#icons-list li')

const iconDataList = Array.from(iconElementList).map(element => ({
name: element.dataset.name,
categories: element.dataset.categories.split(' '),
tags: element.dataset.tags.split(' ')
}))

var fuse = new Fuse(iconDataList, {
keys: ["name", "categories", "tags"],
const fuse = new Fuse(iconDataList, {
ignoreLocation: true,
threshold: 0.0,
keys: ['name', 'categories', 'tags'],
threshold: 0
})

function search(searchTerm) {
var searchResult = fuse.search(searchTerm)
const searchResult = fuse.search(searchTerm)

iconListContainer.innerHTML = ""
iconListContainer.innerHTML = ''
if (searchTerm.length) {
var resultElements = searchResult.map(
(result) => iconElementList[result.refIndex]
)
const resultElements = searchResult.map(result => iconElementList[result.refIndex])
iconListContainer.append(...resultElements)
} else {
iconListContainer.append(...iconElementList)
}

var newUrl = new URL(location)
const newUrl = new URL(window.location)
if (searchTerm.length > 0) {
newUrl.searchParams.set("q", searchTerm)
newUrl.searchParams.set('q', searchTerm)
} else {
newUrl.searchParams.delete("q")
newUrl.searchParams.delete('q')
}
history.replaceState(null, null, newUrl)

window.history.replaceState(null, null, newUrl)
}

searchInput.addEventListener("input", () => search(searchInput.value))
searchInput.addEventListener('input', () => search(searchInput.value))

var query = new URLSearchParams(window.location.search).get("q")
const query = new URLSearchParams(window.location.search).get('q')
if (query) {
search(query)
searchInput.value = query
Expand Down

0 comments on commit 4ebef99

Please sign in to comment.