From 9801d27336f0f8da1af9fce5ab91aee0bedb71ad Mon Sep 17 00:00:00 2001 From: Chris Chua Date: Tue, 18 Feb 2014 01:18:46 -0800 Subject: [PATCH] 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. --- src/tooltip/test/tooltip.spec.js | 8 +++++--- src/tooltip/tooltip.js | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) 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 9d004c55f3..dfed38d87f 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -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 ); @@ -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;