Browse Source

Close dropdowns by clicking toggle button again

merge-requests/88/head
Deimos 5 years ago
parent
commit
0f020d4a2a
  1. 12
      tildes/static/js/behaviors/dropdown-toggle.js

12
tildes/static/js/behaviors/dropdown-toggle.js

@ -12,5 +12,17 @@ $.onmount(".dropdown-toggle", function() {
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus
// This should make the behavior consistent across all browsers
$(this).focus();
$(this).toggleClass("active");
// If toggleClass removed the class, that means that the click was on an
// already-active button, so we should hide the menu (via losing focus).
if (!$(this).hasClass("active")) {
$(this).blur();
}
});
$(this).blur(function() {
$(this).removeClass("active");
});
});
Loading…
Cancel
Save