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

Commit a65bea9

Browse files
committed
refactor(tooltip): remove observer for triggers
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.
1 parent 13b5cd9 commit a65bea9

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/tooltip/test/tooltip.spec.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ describe('tooltip', function() {
271271
expect( elmScope.tt_isOpen ).toBeFalsy();
272272
}));
273273

274-
it('should not share triggers among different element instances - issue 692', inject( function ($compile) {
274+
it('should only set up triggers once', inject( function ($compile) {
275275

276276
scope.test = true;
277277
elmBody = angular.element(
@@ -290,10 +290,12 @@ describe('tooltip', function() {
290290

291291
scope.$apply('test = false');
292292

293-
elm2.trigger('mouseenter');
293+
// click trigger isn't set
294+
elm2.click();
294295
expect( elmScope2.tt_isOpen ).toBeFalsy();
295296

296-
elm2.click();
297+
// mouseenter trigger is still set
298+
elm2.trigger('mouseenter');
297299
expect( elmScope2.tt_isOpen ).toBeTruthy();
298300
}));
299301
});

src/tooltip/tooltip.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
281281
element.unbind(triggers.hide, hideTooltipBind);
282282
};
283283

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

287288
triggers = getTriggers( val );
@@ -292,7 +293,8 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
292293
element.bind( triggers.show, showTooltipBind );
293294
element.bind( triggers.hide, hideTooltipBind );
294295
}
295-
});
296+
}
297+
prepTriggers();
296298

297299
var animation = scope.$eval(attrs[prefix + 'Animation']);
298300
scope.tt_animation = angular.isDefined(animation) ? !!animation : options.animation;

0 commit comments

Comments
 (0)