Created
July 7, 2014 06:38
-
-
Save sibsfinx/302f95329dc1b1282352 to your computer and use it in GitHub Desktop.
Terrible hack to close popovers in Angular (using angular-strap)
This file contains hidden or 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
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