diff --git a/src/tooltip/test/tooltip.spec.js b/src/tooltip/test/tooltip.spec.js index 2f49bbc00e..73d2fcba82 100644 --- a/src/tooltip/test/tooltip.spec.js +++ b/src/tooltip/test/tooltip.spec.js @@ -271,7 +271,7 @@ describe('tooltip', function() { expect( elmScope.tt_isOpen ).toBeFalsy(); })); - it('should not share triggers among different element instances - issue 692', inject( function ($compile) { + it('should only set up triggers once', inject( function ($compile) { scope.test = true; elmBody = angular.element( @@ -290,10 +290,12 @@ describe('tooltip', function() { scope.$apply('test = false'); - elm2.trigger('mouseenter'); + // click trigger isn't set + elm2.click(); expect( elmScope2.tt_isOpen ).toBeFalsy(); - elm2.click(); + // mouseenter trigger is still set + elm2.trigger('mouseenter'); expect( elmScope2.tt_isOpen ).toBeTruthy(); })); }); diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index 68ba0788d9..dfed38d87f 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -146,6 +146,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap if(hasEnableExp && !scope.$eval(attrs[prefix+'Enable'])) { return; } + + prepareTooltip(); + if ( scope.tt_popupDelay ) { // Do nothing if the tooltip was already scheduled to pop-up. // This happens if show is triggered multiple times before any hide is triggered. @@ -242,6 +245,11 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap } } + function prepareTooltip() { + prepPlacement(); + prepPopupDelay(); + } + /** * Observe the relevant attributes. */ @@ -257,21 +265,24 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap scope.tt_title = val; }); - attrs.$observe( prefix+'Placement', function ( val ) { + function prepPlacement() { + var val = attrs[ prefix + 'Placement' ]; scope.tt_placement = angular.isDefined( val ) ? val : options.placement; - }); + } - attrs.$observe( prefix+'PopupDelay', function ( val ) { + function prepPopupDelay() { + var val = attrs[ prefix + 'PopupDelay' ]; var delay = parseInt( val, 10 ); scope.tt_popupDelay = ! isNaN(delay) ? delay : options.popupDelay; - }); + } var unregisterTriggers = function () { element.unbind(triggers.show, showTooltipBind); element.unbind(triggers.hide, hideTooltipBind); }; - attrs.$observe( prefix+'Trigger', function ( val ) { + function prepTriggers() { + var val = attrs[ prefix + 'Trigger' ]; unregisterTriggers(); triggers = getTriggers( val ); @@ -282,7 +293,8 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap element.bind( triggers.show, showTooltipBind ); element.bind( triggers.hide, hideTooltipBind ); } - }); + } + prepTriggers(); var animation = scope.$eval(attrs[prefix + 'Animation']); scope.tt_animation = angular.isDefined(animation) ? !!animation : options.animation;