From 041261b5366aa44a0c0314e8262c91d1d867f4d1 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Sat, 4 May 2013 07:18:11 -0700 Subject: [PATCH] fix(tooltip): close tooltips appended to body on location change Closes #345 --- src/tooltip/test/tooltip.spec.js | 20 ++++++++++++++++++++ src/tooltip/tooltip.js | 10 ++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/tooltip/test/tooltip.spec.js b/src/tooltip/test/tooltip.spec.js index 1bc4e2e69b..c068377f17 100644 --- a/src/tooltip/test/tooltip.spec.js +++ b/src/tooltip/test/tooltip.spec.js @@ -309,6 +309,26 @@ describe( '$tooltipProvider', function() { expect( elmBody.children().length ).toBe( 1 ); expect( $body.children().length ).toEqual( bodyLength + 1 ); })); + + it('should close on location change', inject( function( $rootScope, $compile) { + + elmBody = angular.element( + '
Selector Text
' + ); + + scope = $rootScope; + $compile(elmBody)(scope); + scope.$digest(); + elm = elmBody.find('span'); + elmScope = elm.scope(); + + elm.trigger( 'mouseenter' ); + expect( elmScope.tt_isOpen ).toBe( true ); + + scope.$broadcast('$locationChangeSuccess'); + scope.$digest(); + expect( elmScope.tt_isOpen ).toBe( false ); + })); }); describe( 'triggers', function() { diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index 0f1cf4b9ac..1e137f97bf 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -266,6 +266,11 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] ) element.bind( triggers.hide, hideTooltipBind ); } }); + + //if a tooltip is attached to we need to remove it on location change + if ( options.appendToBody ) { + scope.$on('$locationChangeSuccess', hide); + } } }; }; @@ -296,7 +301,4 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] ) .directive( 'tooltipHtmlUnsafe', [ '$tooltip', function ( $tooltip ) { return $tooltip( 'tooltipHtmlUnsafe', 'tooltip', 'mouseenter' ); -}]) - -; - +}]);