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

feat(tooltip): Added custom trigger support #553

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/tooltip/test/tooltip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,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