* Add custom CSS field to config This allows users to set/customize an instance's theme and appearance to their liking. The config CSS field is prepopulated with all default CSS variable values to allow quick editing. Note that this can be somewhat of a "footgun" if someone updates the CSS to hide all fields/search/etc. Should probably add some sort of bandaid "admin" feature for public instances to employ until the whole cookie/session issue is investigated further. * Symlink all app static files to test dir * Refactor app/misc/*.json -> app/static/settings/*.json The country/language json files are used for user config settings, so the "misc" name didn't really make sense. Also moved these to the static folder to make testing easier. * Fix light theme variables in dark theme css * Minor style tweaking
83 lines
2.3 KiB
JavaScript
83 lines
2.3 KiB
JavaScript
const setupSearchLayout = () => {
|
|
// Setup search field
|
|
const searchBar = document.getElementById("search-bar");
|
|
const searchBtn = document.getElementById("search-submit");
|
|
|
|
// Automatically focus on search field
|
|
searchBar.focus();
|
|
searchBar.select();
|
|
|
|
searchBar.addEventListener("keyup", function(event) {
|
|
if (event.keyCode === 13) {
|
|
event.preventDefault();
|
|
searchBtn.click();
|
|
} else {
|
|
handleUserInput(searchBar);
|
|
}
|
|
});
|
|
};
|
|
|
|
const setupConfigLayout = () => {
|
|
// Setup whoogle config
|
|
const collapsible = document.getElementById("config-collapsible");
|
|
collapsible.addEventListener("click", function() {
|
|
this.classList.toggle("active");
|
|
let content = this.nextElementSibling;
|
|
if (content.style.maxHeight) {
|
|
content.style.maxHeight = null;
|
|
} else {
|
|
content.style.maxHeight = content.scrollHeight + "px";
|
|
}
|
|
|
|
content.classList.toggle("open");
|
|
});
|
|
};
|
|
|
|
const loadConfig = event => {
|
|
event.preventDefault();
|
|
let config = prompt("Enter name of config:");
|
|
if (!config) {
|
|
alert("Must specify a name for the config to load");
|
|
return;
|
|
}
|
|
|
|
let xhrPUT = new XMLHttpRequest();
|
|
xhrPUT.open("PUT", "config?name=" + config + ".conf");
|
|
xhrPUT.onload = function() {
|
|
if (xhrPUT.readyState === 4 && xhrPUT.status !== 200) {
|
|
alert("Error loading Whoogle config");
|
|
return;
|
|
}
|
|
|
|
location.reload(true);
|
|
};
|
|
|
|
xhrPUT.send();
|
|
};
|
|
|
|
const saveConfig = event => {
|
|
event.preventDefault();
|
|
let config = prompt("Enter name for this config:");
|
|
if (!config) {
|
|
alert("Must specify a name for the config to save");
|
|
return;
|
|
}
|
|
|
|
let configForm = document.getElementById("config-form");
|
|
configForm.action = 'config?name=' + config + ".conf";
|
|
configForm.submit();
|
|
};
|
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
setTimeout(function() {
|
|
document.getElementById("main").style.display = "block";
|
|
}, 100);
|
|
|
|
setupSearchLayout();
|
|
setupConfigLayout();
|
|
|
|
// Focusing on the search input field requires a delay for elements to finish
|
|
// loading (seemingly only on FF)
|
|
setTimeout(function() { document.getElementById("search-bar").focus(); }, 250);
|
|
});
|