Skip to content

Instantly share code, notes, and snippets.

@sibsfinx
Created July 7, 2014 06:38
Show Gist options
  • Save sibsfinx/302f95329dc1b1282352 to your computer and use it in GitHub Desktop.
Save sibsfinx/302f95329dc1b1282352 to your computer and use it in GitHub Desktop.
Terrible hack to close popovers in Angular (using angular-strap)
angular.module('app').directive('rmPopovers',
function($document, $rootScope, $timeout, $popover, $location) {
return {
restrict: 'EA',
link : function(scope, element, attrs, $location) {
var $element = $(element);
function closeAllPopovers(){
$('[popover-block]').each(function(){
var $this = $(this);
$this.scope().$hide();
$this.find('[popover-close]').click();
});
}
$(element).click(function() {
$('[popover-block]').each(function(){
var $this = $(this);
if($this.attr('popover-name') != $element.attr('popover-target'))
{
$this.scope().$hide();
}
});
});
angular.element($('body')).click(function(e) {
var $popover = $(e.target).parents('[popover-block], [bs-popover]');
if($popover.length <= 0){
closeAllPopovers();
}
});
scope.$on('$locationChangeSuccess', function(){
closeAllPopovers();
});
}
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment