whoogle-search/app/static/js/controller.js

20 lines
577 B
JavaScript
Raw Normal View History

2020-01-21 23:26:49 +03:00
document.addEventListener("DOMContentLoaded", function() {
const searchBar = document.getElementById("search-bar");
const searchBtn = document.getElementById("search-submit");
// Automatically focus on search field
searchBar.focus();
searchBar.select();
2020-01-21 23:26:49 +03:00
searchBar.addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
searchBtn.click();
}
});
searchBtn.onclick = function() {
window.location.href = '/search?q=' + encodeURI(searchBar.value);
}
});