Created
January 24, 2017 10:53
-
-
Save strika/47544bf530b316f01159590c5ebc3d7e to your computer and use it in GitHub Desktop.
A utility for keeping a Bootstrap drop down menu open after a link is clicked.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A utility for keeping a Bootstrap drop down menu open after a link is | |
// clicked | |
// | |
// Usage: | |
// | |
// <div class="dropdown"> | |
// <a href="" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"> | |
// Dropdown trigger <span class="caret"></span> | |
// </a> | |
// | |
// <ul class="dropdown-menu" aria-labelledby="dLabel"> | |
// <li><a href="">Edit</a></li> | |
// <li><a href="" keep-menu-open="true">Delete</a></li> | |
// </ul> | |
// </div> | |
$(".dropdown .dropdown-menu a").on("click", function(e) { | |
var keepMenuOpen = $(this).data("keep-menu-open"), | |
$dropdown = $(this).parents(".dropdown"); | |
$dropdown.data("keep-menu-open", keepMenuOpen); | |
}); | |
$(".dropdown").on("hide.bs.dropdown", function(e) { | |
var keepMenuOpen = $(this).data("keep-menu-open"); | |
$(this).removeData("keep-menu-open"); | |
return keepMenuOpen !== true; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment