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

Commit

Permalink
fix(tooltip): bind correct 'hide' event handler
Browse files Browse the repository at this point in the history
If a user defines a tooltip-trigger attribute, this ensures the correct event handlers is used to hide the tooltip.

Fixes a bug where if a user sets both a default trigger using the tooltip provider, and then tries to override with an attribute, the wrong 'hide' event was being used.
  • Loading branch information
psgibbs authored and pkozlowski-opensource committed Aug 3, 2013
1 parent 4fd5bf4 commit d50b054
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
18 changes: 18 additions & 0 deletions src/tooltip/test/tooltip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,24 @@ describe( '$tooltipProvider', function() {
elm.trigger('blur');
expect( elmScope.tt_isOpen ).toBeFalsy();
}));

it( 'should override the show and hide triggers if there is an attribute', inject( function ( $rootScope, $compile ) {
elmBody = angular.element(
'<div><input tooltip="tooltip text" tooltip-trigger="mouseenter"/></div>'
);

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

expect( elmScope.tt_isOpen ).toBeFalsy();
elm.trigger('mouseenter');
expect( elmScope.tt_isOpen ).toBeTruthy();
elm.trigger('mouseleave');
expect( elmScope.tt_isOpen ).toBeFalsy();
}));
});

describe( 'triggers with a custom mapped value', function() {
Expand Down
17 changes: 5 additions & 12 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
* undefined; otherwise, it uses the `triggerMap` value of the show
* trigger; else it will just use the show trigger.
*/
function setTriggers ( trigger ) {
var show, hide;

show = trigger || options.trigger || defaultTriggerShow;
if ( angular.isDefined ( options.trigger ) ) {
hide = triggerMap[options.trigger] || show;
} else {
hide = triggerMap[show] || show;
}

function getTriggers ( trigger ) {
var show = trigger || options.trigger || defaultTriggerShow;
var hide = triggerMap[show] || show;
return {
show: show,
hide: hide
Expand Down Expand Up @@ -121,7 +114,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
var popupTimeout;
var $body;
var appendToBody = angular.isDefined( options.appendToBody ) ? options.appendToBody : false;
var triggers = setTriggers( undefined );
var triggers = getTriggers( undefined );
var hasRegisteredTriggers = false;

// By default, the tooltip is not open.
Expand Down Expand Up @@ -283,7 +276,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
element.unbind( triggers.hide, hideTooltipBind );
}

triggers = setTriggers( val );
triggers = getTriggers( val );

if ( triggers.show === triggers.hide ) {
element.bind( triggers.show, toggleTooltipBind );
Expand Down

0 comments on commit d50b054

Please sign in to comment.