Search/static/js/sidemenu.js
2024-11-20 14:57:55 +01:00

31 lines
No EOL
948 B
JavaScript

/*
This script is responsible for opening and closing the menu from the side.
*/
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
document.body.classList.add('menu-open');
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.body.classList.remove('menu-open');
}
function setTheme(theme) {
window.location.href = '/search?theme=' + theme;
}
function updateLanguage(langCode) {
// Send AJAX request to update language settings
const xhr = new XMLHttpRequest();
xhr.open('POST', '/updateSettings', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function () {
if (this.status >= 200 && this.status < 300) {
location.reload();
} else {
console.error('Failed to update language.');
}
};
xhr.send(encodeURI('site_lang=' + langCode));
}