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

Commit

Permalink
refactor(tooltip): remove observer for triggers
Browse files Browse the repository at this point in the history
This change fixes the usage of the tooltip directive with AngularJS
1.3.1 when no trigger attribute is used.

BREAKING CHANGE: tooltip/popover trigger is no longer a watched
attribute.
This affects both popovers and tooltips. The triggers are now set up
once and can no longer be changed after initialization.
  • Loading branch information
chrisirhc committed Nov 2, 2014
1 parent 13b5cd9 commit a65bea9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/tooltip/test/tooltip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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();
}));
});
Expand Down
6 changes: 4 additions & 2 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
element.unbind(triggers.hide, hideTooltipBind);
};

attrs.$observe( prefix+'Trigger', function ( val ) {
function prepTriggers() {
var val = attrs[ prefix + 'Trigger' ];
unregisterTriggers();

triggers = getTriggers( val );
Expand All @@ -292,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;
Expand Down

0 comments on commit a65bea9

Please sign in to comment.