Files
Inventory-Manager/public/javascripts/header.js
T
2025-01-12 02:38:12 +00:00

41 lines
1.2 KiB
JavaScript

document.addEventListener('DOMContentLoaded', () => {
const brandNav = document.querySelector('#brandNav');
if (brandNav) {
brandNav.addEventListener('click', () => {
window.location.href = '/';
});
}
const homeNav = document.querySelector('#homeNav');
if (homeNav) {
homeNav.addEventListener('click', () => {
window.location.href = '/';
});
}
const inventoryNav = document.querySelector('#inventoryNav');
if (inventoryNav) {
inventoryNav.addEventListener('click', () => {
window.location.href = '/inventory';
});
}
const loginNav = document.querySelector('#loginNav');
if (loginNav) {
loginNav.addEventListener('click', () => {
window.location.href = '/login';
});
}
const logoutNav = document.querySelector('#logoutNav');
if (logoutNav) {
logoutNav.addEventListener('click', (event) => {
event.preventDefault(); // Prevent default link behavior
$.get('/auth/logout', function(data) {
window.location.href = '/login';
}).fail((jqXHR) => {
alert('Logout failed: ' + jqXHR.responseText);
});
});
}
});