Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit dfa5315

Browse files
Josh David Millerpkozlowski-opensource
Josh David Miller
authored andcommitted
feat(tooltip): add custom trigger support
The $tooltipProvider now allows extending the default set of open and close trigger mappings. Closes #382.
1 parent d089626 commit dfa5315

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/tooltip/test/tooltip.spec.js

+28
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,34 @@ describe( '$tooltipProvider', function() {
429429
}));
430430
});
431431

432+
describe( 'triggers with a custom mapped value', function() {
433+
beforeEach(module('ui.bootstrap.tooltip', function($tooltipProvider){
434+
$tooltipProvider.setTriggers({ 'customOpenTrigger': 'customCloseTrigger' });
435+
$tooltipProvider.options({trigger: 'customOpenTrigger'});
436+
}));
437+
438+
// load the template
439+
beforeEach(module('template/tooltip/tooltip-popup.html'));
440+
441+
it( 'should use the show trigger and the mapped value for the hide trigger', inject( function ( $rootScope, $compile ) {
442+
elmBody = angular.element(
443+
'<div><input tooltip="tooltip text" /></div>'
444+
);
445+
446+
scope = $rootScope;
447+
$compile(elmBody)(scope);
448+
scope.$digest();
449+
elm = elmBody.find('input');
450+
elmScope = elm.scope();
451+
452+
expect( elmScope.tt_isOpen ).toBeFalsy();
453+
elm.trigger('customOpenTrigger');
454+
expect( elmScope.tt_isOpen ).toBeTruthy();
455+
elm.trigger('customCloseTrigger');
456+
expect( elmScope.tt_isOpen ).toBeFalsy();
457+
}));
458+
});
459+
432460
describe( 'triggers without a mapped value', function() {
433461
beforeEach(module('ui.bootstrap.tooltip', function($tooltipProvider){
434462
$tooltipProvider.options({trigger: 'fakeTrigger'});

src/tooltip/tooltip.js

+9
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
4040
angular.extend( globalOptions, value );
4141
};
4242

43+
/**
44+
* This allows you to extend the set of trigger mappings available. E.g.:
45+
*
46+
* $tooltipProvider.setTriggers( 'openTrigger': 'closeTrigger' );
47+
*/
48+
this.setTriggers = function setTriggers ( triggers ) {
49+
angular.extend( triggerMap, triggers );
50+
};
51+
4352
/**
4453
* This is a helper function for translating camel-case to snake-case.
4554
*/

0 commit comments

Comments
 (0)