Skip to content

Instantly share code, notes, and snippets.

@tacone
Last active December 16, 2015 06:09
Show Gist options
  • Save tacone/5389055 to your computer and use it in GitHub Desktop.
Save tacone/5389055 to your computer and use it in GitHub Desktop.
How to know when a Bootstrap dropdown has been closed, even if it supports no events
/*
* Quorque tu, @fat.
* https://github.com/twitter/bootstrap/issues/1343
*/
$('[data-toggle=dropdown]').click(function() {
var parent = $(this).parent();
if (!parent.hasClass('open') && parent.data('close-callback'))
{ //sta per aprirsi
parent.data('has-been-opened', true);
}
});
var hasDropDownBeenClosed = function()
{
$('[data-toggle=dropdown]').each(function() {
var parent = $(this).parent();
if (parent.data('has-been-opened') && !parent.hasClass('open') && parent.data('close-callback'))
{
parent.data('has-been-opened', false);
parent.data('close-callback')();
}
});
setTimeout(hasDropDownBeenClosed, checkClosedDelay);
}
var checkClosedDelay = 1000;
setTimeout(hasDropDownBeenClosed, checkClosedDelay);
$('#notifications-button').parent().data('close-callback', function() {
console.log('just closed');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment