← back to Interiordesignershowroom
public/js/roommenu.js
19 lines
// Progressive enhancement for the header room hamburger. The menu is a native
// <details> (collapsed on load, works with zero JS); this only adds the niceties
// users expect from a dropdown: close on outside-click and on Escape. If this file
// fails to load, the menu still opens/closes via the summary button.
(function () {
var menu = document.getElementById('roomMenu');
if (!menu) return;
document.addEventListener('click', function (e) {
if (menu.open && !menu.contains(e.target)) menu.open = false;
});
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && menu.open) {
menu.open = false;
var s = menu.querySelector('summary');
if (s) s.focus();
}
});
})();