First, if you haven't already looked, here are the sources for tooltips and popovers:
tooltip.js
popover.js
You can add custom triggers. Popovers use the $tooltip
provider:
.directive( 'popover', [ '$tooltip', function ( $tooltip ) {
return $tooltip( 'popover', 'popover', 'click' );
}]);
Where the $tooltip
's provider $get
method, used to make new tooltip
's, is defined here:
this.$get = [ '$window', '$compile', '$timeout', '$parse', '$document', '$position', '$interpolate', function ( $window, $compile, $timeout, $parse, $document, $position, $interpolate ) {
return function $tooltip ( type, prefix, defaultTriggerShow ) {...}
The $tooltip
provider has this method: (triggerMap is the 3 triggers that are defined in the $tooltip
provider out of the box.
/**
* This allows you to extend the set of trigger mappings available. E.g.:
*
* $tooltipProvider.setTriggers({'openTrigger': 'closeTrigger'});
*/
this.setTriggers = function setTriggers ( triggers ) {
angular.extend( triggerMap, triggers );
};
You can use it in a config block, like this:
myApp.config(['$tooltipProvider', function ( $tooltipProvider ) {
$tooltipProvider.setTriggers({'openTrigger': 'closeTrigger'}) ;
}]);
Then, you can create a new popover directive like this:
.directive('myPopover', ['$tooltip', function ( $tooltip ) {
return $tooltip( 'myPopover', 'myPopover', 'openTrigger' );
}]);
And triggering the popover would then be as simple as element.triggerHandler( 'openTrigger' )
(or closeTrigger
) where element
is the popover.