Searchbox terminada ?

This commit is contained in:
2020-11-21 02:55:02 -03:00
parent 9b26927909
commit e11ed6cd05
3 changed files with 20 additions and 3 deletions

View File

@@ -188,7 +188,24 @@ const photos = new function() {
}
}
const search = new function () {
this.search_bar = document.getElementById('search-input')
this.submit_search = (query) => {
const encoded = encodeURIComponent(query)
window.location.href = `https://www.duckduckgo.com/?q=${encoded}`
}
this.on_load = () => {
this.search_bar.addEventListener('keydown', (e) => {
if(e.key === 'Enter' && this.search_bar.value.length !== 0)
this.submit_search(this.search_bar.value)
})
}
}
window.addEventListener('load', () => {
currency.on_load()
photos.on_load()
search.on_load()
});