Skip to content

Instantly share code, notes, and snippets.

@Skinner927
Last active August 29, 2015 14:00
Show Gist options
  • Save Skinner927/11228342 to your computer and use it in GitHub Desktop.
Save Skinner927/11228342 to your computer and use it in GitHub Desktop.
Replaces the Bootstrap Split Button Dropdowns js
// Replaces the Bootstrap Split Button Dropdowns js
// Works automatically
// http://getbootstrap.com/components/#btn-dropdowns
angular.module('splitButtonDropdowns', [])
.directive('dropdownToggle', ['$timeout', function($timeout){
return {
restrict: 'C',
link: function(scope, element, attrs) {
element.on('click', function(){
var me = angular.element(this);
var parent = me.parent();
// Are we trying to close the dropdown? Body click will handle it
if(parent.hasClass('open'))
return;
// Add the open class, this pops the dropdown
parent.addClass('open');
// wait till this event is done, then add the body click listener
$timeout(function(){
angular.element('body').one('click', function(){
parent.removeClass('open');
});
},0);
});
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment