<script>
document.body.addEventListener('click', (ev) => {
    /* Close any open details elements that this click is outside of */
    var target = ev.target;
    var detailsClickedWithin = null;
    while (target && target.tagName != 'DETAILS') {
        target = target.parentNode;
    }
    if (target && target.tagName == 'DETAILS') {
        detailsClickedWithin = target;
    }
    Array.from(document.querySelectorAll('details.details-menu')).filter(
        (details) => details.open && details != detailsClickedWithin
    ).forEach(details => details.open = false);
});
</script>
