You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
whoogle-search/app/static/js/controller.js

53 lines
1.6 KiB
JavaScript

5 years ago
document.addEventListener("DOMContentLoaded", function() {
// Setup search field
5 years ago
const searchBar = document.getElementById("search-bar");
const searchBtn = document.getElementById("search-submit");
// Automatically focus on search field
searchBar.focus();
searchBar.select();
5 years ago
searchBar.addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
searchBtn.click();
}
});
searchBtn.onclick = function() {
window.location.href = '/search?q=' + encodeURI(searchBar.value);
};
// Setup shoogle config
const saveConfig = document.getElementById("config-submit");
const nearConfig = document.getElementById("config-near");
// Request existing config info
var xhr = new XMLHttpRequest();
xhr.open("GET", "/static/config.json");
xhr.onload = function() {
if (xhr.readyState === 4 && xhr.status !== 200) {
alert("Error loading Shoogle config");
return;
}
// Allow for updating/saving config values
let configSettings = JSON.parse(xhr.responseText);
nearConfig.value = configSettings["near"];
nearConfig.addEventListener("keyup", function(event) {
configSettings["near"] = nearConfig.value;
});
saveConfig.onclick = function() {
var xhr = new XMLHttpRequest();
xhr.open("POST", "/config");
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.send(JSON.stringify(configSettings));
}
};
xhr.send();
5 years ago
});