2021-03-07 22:04:05 +03:00
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
2022-08-04 02:54:10 +03:00
|
|
|
const advSearchToggle = document.getElementById("adv-search-toggle");
|
|
|
|
const advSearchDiv = document.getElementById("adv-search-div");
|
2021-03-07 22:04:05 +03:00
|
|
|
const searchBar = document.getElementById("search-bar");
|
2022-08-01 23:32:24 +03:00
|
|
|
const countrySelect = document.getElementById("result-country");
|
2022-06-10 01:40:49 +03:00
|
|
|
const arrowKeys = [37, 38, 39, 40];
|
|
|
|
let searchValue = searchBar.value;
|
2021-03-07 22:04:05 +03:00
|
|
|
|
2022-08-01 23:32:24 +03:00
|
|
|
countrySelect.onchange = () => {
|
|
|
|
let str = window.location.href;
|
2022-08-01 23:35:43 +03:00
|
|
|
n = str.lastIndexOf("/search");
|
2022-08-01 23:32:24 +03:00
|
|
|
if (n > 0) {
|
|
|
|
str = str.substring(0, n) +
|
2022-08-04 02:54:10 +03:00
|
|
|
`/search?q=${searchBar.value}&country=${countrySelect.value}`;
|
2022-08-01 23:32:24 +03:00
|
|
|
window.location.href = str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-04 02:54:10 +03:00
|
|
|
const toggleAdvancedSearch = on => {
|
|
|
|
if (on) {
|
|
|
|
advSearchDiv.style.maxHeight = "70px";
|
|
|
|
} else {
|
|
|
|
advSearchDiv.style.maxHeight = "0px";
|
|
|
|
}
|
|
|
|
localStorage.advSearchToggled = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleAdvancedSearch(JSON.parse(localStorage.advSearchToggled));
|
|
|
|
advSearchToggle.onclick = () => {
|
|
|
|
toggleAdvancedSearch(advSearchToggle.checked);
|
|
|
|
}
|
|
|
|
|
2022-06-10 01:40:49 +03:00
|
|
|
searchBar.addEventListener("keyup", function(event) {
|
|
|
|
if (event.keyCode === 13) {
|
2021-03-07 22:04:05 +03:00
|
|
|
document.getElementById("search-form").submit();
|
2022-06-10 01:40:49 +03:00
|
|
|
} else if (searchBar.value !== searchValue && !arrowKeys.includes(event.keyCode)) {
|
|
|
|
searchValue = searchBar.value;
|
|
|
|
handleUserInput();
|
2021-03-07 22:04:05 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|