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

Commit

Permalink
fix(tooltip): close tooltips appended to body on location change
Browse files Browse the repository at this point in the history
Closes #345
  • Loading branch information
pkozlowski-opensource authored and joshdmiller committed May 4, 2013
1 parent 76fee1f commit 041261b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
20 changes: 20 additions & 0 deletions src/tooltip/test/tooltip.spec.js
Expand Up @@ -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(
'<div><span tooltip="tooltip text">Selector Text</span></div>'
);

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() {
Expand Down
10 changes: 6 additions & 4 deletions src/tooltip/tooltip.js
Expand Up @@ -266,6 +266,11 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
element.bind( triggers.hide, hideTooltipBind );
}
});

//if a tooltip is attached to <body> we need to remove it on location change
if ( options.appendToBody ) {
scope.$on('$locationChangeSuccess', hide);
}
}
};
};
Expand Down Expand Up @@ -296,7 +301,4 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )

.directive( 'tooltipHtmlUnsafe', [ '$tooltip', function ( $tooltip ) {
return $tooltip( 'tooltipHtmlUnsafe', 'tooltip', 'mouseenter' );
}])

;

}]);

0 comments on commit 041261b

Please sign in to comment.