53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
const ROUTES = {
|
|
'/': 's-landing',
|
|
'/core': 's-core',
|
|
'/channels': 's-channels',
|
|
'/categories': 's-categories',
|
|
'/gmail': 's-gmail',
|
|
'/behavior': 's-behavior',
|
|
'/threads': 's-threads',
|
|
'/pins': 's-pins',
|
|
'/notifications': 's-notifications',
|
|
'/logging': 's-logging',
|
|
'/automation': 's-automation',
|
|
'/appearance': 's-appearance',
|
|
'/staff': 's-staff',
|
|
'/advanced': 's-advanced'
|
|
};
|
|
|
|
function navigate(path, updateHistory = true) {
|
|
const sectionId = ROUTES[path] || ROUTES['/'];
|
|
const normalizedPath = ROUTES[path] ? path : '/';
|
|
if (updateHistory) history.pushState({}, '', normalizedPath);
|
|
|
|
document.querySelectorAll('.section').forEach(section => {
|
|
section.classList.toggle('hidden', section.id !== sectionId);
|
|
});
|
|
|
|
document.querySelectorAll('.sidebar a').forEach(link => {
|
|
link.classList.toggle('active', link.getAttribute('href') === normalizedPath);
|
|
});
|
|
}
|
|
|
|
function setupSidebarRouting() {
|
|
// Delegated at document so the same handler covers sidebar links AND
|
|
// landing-grid cards without duplication. Scoped by the compound selector.
|
|
document.addEventListener('click', e => {
|
|
const a = e.target.closest('.sidebar a, .landing-grid a');
|
|
if (!a) return;
|
|
e.preventDefault();
|
|
navigate(a.getAttribute('href'));
|
|
if (Util.isMobileViewport()) Util.setSidebarOpen(false);
|
|
});
|
|
|
|
window.addEventListener('popstate', () => {
|
|
navigate(location.pathname, false);
|
|
});
|
|
}
|
|
|
|
window.Router = { ROUTES, navigate, setupSidebarRouting };
|
|
})();
|