Skip to content

Instantly share code, notes, and snippets.

@Thinkscape
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Thinkscape/8974923 to your computer and use it in GitHub Desktop.
Save Thinkscape/8974923 to your computer and use it in GitHub Desktop.
tooltip-group support for angular-strap
module.directive('tooltipGroup', [
var popoverRegistry = {};
var suspend = false; // semaphore used to prevent circular calling of hide triggers
function(){
return {
restrict : 'A',
priority : 1,
link : {
pre : function ($scope, el, attrs, formCtrl) {
// $scope.artifactPickerSelectOptions = artifactPicker.getSelectOptions();
},
post: function ($scope, el, attr) {
var groupName = attr.tooltipGroup;
// Store the name of the popover group in popover scope
$scope.$$childHead.tt_group = groupName;
// Init group registry
if(!angular.isDefined(popoverRegistry[groupName])){
popoverRegistry[groupName] = [];
}
// Store the popover in the registry
popoverRegistry[groupName].push($scope.$$childHead);
// Hide all other popups when this one is opened
$scope.$$childHead.$watch('$isShown', function(isOpen){
if (!isOpen || suspend) {
return false;
}
suspend = true; // prevent circular ref
// Hide all other tooltips from the same group
_.each(popoverRegistry[groupName], function(ttScope){
if(ttScope !== $scope.$$childHead && ttScope.$isShown){
ttScope.$hide();
}
});
suspend = false;
});
// Remove the tooltip from registry upon destruction
$scope.$$childHead.$on('$destroy', function onDestroyTooltip() {
_.remove(popoverRegistry[groupName], function(ttScope){ return ttScope === $scope });
});
}
}
};
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment