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

Commit

Permalink
feat(tooltip): add custom trigger support
Browse files Browse the repository at this point in the history
The $tooltipProvider now allows extending the default set of open and
close trigger mappings.

Closes #382.
  • Loading branch information
Josh David Miller authored and pkozlowski-opensource committed Jun 24, 2013
1 parent d089626 commit dfa5315
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/tooltip/test/tooltip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,34 @@ describe( '$tooltipProvider', function() {
}));
});

describe( 'triggers with a custom mapped value', function() {
beforeEach(module('ui.bootstrap.tooltip', function($tooltipProvider){
$tooltipProvider.setTriggers({ 'customOpenTrigger': 'customCloseTrigger' });
$tooltipProvider.options({trigger: 'customOpenTrigger'});
}));

// load the template
beforeEach(module('template/tooltip/tooltip-popup.html'));

it( 'should use the show trigger and the mapped value for the hide trigger', inject( function ( $rootScope, $compile ) {
elmBody = angular.element(
'<div><input tooltip="tooltip text" /></div>'
);

scope = $rootScope;
$compile(elmBody)(scope);
scope.$digest();
elm = elmBody.find('input');
elmScope = elm.scope();

expect( elmScope.tt_isOpen ).toBeFalsy();
elm.trigger('customOpenTrigger');
expect( elmScope.tt_isOpen ).toBeTruthy();
elm.trigger('customCloseTrigger');
expect( elmScope.tt_isOpen ).toBeFalsy();
}));
});

describe( 'triggers without a mapped value', function() {
beforeEach(module('ui.bootstrap.tooltip', function($tooltipProvider){
$tooltipProvider.options({trigger: 'fakeTrigger'});
Expand Down
9 changes: 9 additions & 0 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
angular.extend( globalOptions, value );
};

/**
* 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 );
};

/**
* This is a helper function for translating camel-case to snake-case.
*/
Expand Down

0 comments on commit dfa5315

Please sign in to comment.