Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgilbers committed Aug 27, 2024
1 parent 888a926 commit 0321f01
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
13 changes: 12 additions & 1 deletion js/Products.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ export class Product {
this.marker = new L.marker(loadedGraph[this.nodeIndex].latlng)
}

/**
* Show product on map
*/
showPosition = () => {
this.marker.addTo(map)
this.marker.bindPopup(this.name).openPopup()
}

/**
* Hide product on map
*/
hidePosition = () => {
this.marker.remove()
}
Expand Down Expand Up @@ -60,10 +66,15 @@ export function findProduct (query) {
return found
}

/**
* Fuzzy search for products
* @param {String} query Searchquery
* @returns Array of more or less matching products
*/
export function searchProducts (query) {
const fuse = new Fuse(products, {
keys: ['name'],
threshold: 0.3
threshold: 0.3 // 0.0 = perfect match; 1.0 = no match at all
})
return fuse.search(query, { limit: 7 })
}
14 changes: 14 additions & 0 deletions js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ searchBar.addEventListener('keyup', function (event) {
}
})

/**
* Show product on map and hide last product
* @param {String} inputValue Searchquery
*/
window.sendSearchQuery = (inputValue) => {
const product = findProduct(inputValue)
if (product) {
Expand All @@ -290,6 +294,9 @@ window.sendSearchQuery = (inputValue) => {
resetSearchbar()
}

/**
* Add x-Button behind input field
*/
function addClearButton () {
if (!document.getElementById('clearSearchButton')) {
searchGroup.appendChild(clearSearchButton)
Expand All @@ -299,6 +306,9 @@ function addClearButton () {
searchBar.classList.add('rounded-end-0')
}

/**
* Remove x-Button from search group
*/
function resetSearchbar () {
searchBar.value = ''
document.getElementById('clearSearchButton').remove()
Expand All @@ -312,6 +322,10 @@ searchList.id = 'searchList'

const topControl = document.getElementById('topControl')

/**
* Show clickable list of possible products
* @param {String} query Searchquery
*/
function showList (query) {
searchList.innerHTML = ''
for (const p of searchProducts(query)) {
Expand Down

0 comments on commit 0321f01

Please sign in to comment.