diff --git a/tildes/static/js/behaviors/dropdown-toggle.js b/tildes/static/js/behaviors/dropdown-toggle.js new file mode 100644 index 0000000..8789df9 --- /dev/null +++ b/tildes/static/js/behaviors/dropdown-toggle.js @@ -0,0 +1,21 @@ +// Copyright (c) 2020 Tildes contributors +// SPDX-License-Identifier: AGPL-3.0-or-later + +// Note: unlike almost all other JS behaviors, this one does not attach to elements +// based on the presence of a data-js-* HTML attribute. This attaches to any element +// with the dropdown-toggle class so that this behavior is always applied to dropdowns. +$.onmount(".dropdown-toggle", function() { + $(this).click(function() { + if ($(this).is(":focus")) { + // If the button was already focused (so the menu is visible), close it + $(this).blur(); + } else { + // Spectre.css's dropdown menus use the focus event to display the menu, + // but Safari and Firefox on OSX don't give focus to a