Searchbox terminada ?
This commit is contained in:
17
script.js
17
script.js
@@ -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()
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user