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

Commit e5d593b

Browse files
author
Josh David Miller
committed
feat(tooltipProvider): added appendToBody option for $tooltip
1 parent 2c9dc05 commit e5d593b

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

src/tooltip/test/tooltip.spec.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,43 @@ describe('tooltip', function() {
123123
}));
124124
});
125125

126-
126+
describe('$tooltipProvider', function() {
127+
var elm,
128+
elmBody,
129+
scope,
130+
elmScope,
131+
body;
132+
133+
// load the tooltip code
134+
beforeEach(module('ui.bootstrap.tooltip'));
135+
136+
// load the template
137+
beforeEach(module('template/tooltip/tooltip-popup.html'));
138+
139+
it( 'should not be open initially', function() {
140+
module( function ( $tooltipProvider ) {
141+
$tooltipProvider.options({ appendToBody: true });
142+
});
143+
144+
inject( function( $rootScope, $compile, $document ) {
145+
$body = $document.find( 'body' );
146+
elmBody = angular.element(
147+
'<div><span tooltip="tooltip text">Selector Text</span></div>'
148+
);
149+
150+
scope = $rootScope;
151+
$compile(elmBody)(scope);
152+
scope.$digest();
153+
elm = elmBody.find('span');
154+
elmScope = elm.scope();
155+
156+
var bodyLength = $body.children().length;
157+
elm.trigger( 'mouseenter' );
158+
159+
expect( elmScope.tt_isOpen ).toBe( true );
160+
expect( elmBody.children().length ).toBe( 1 );
161+
expect( $body.children().length ).toEqual( bodyLength + 1 );
162+
});
163+
});
164+
});
165+

src/tooltip/tooltip.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ angular.module( 'ui.bootstrap.tooltip', [] )
2020
var globalOptions = {};
2121

2222
/**
23-
* The `options({})` allows global configuration of all dialogs in the
23+
* `options({})` allows global configuration of all tooltips in the
2424
* application.
2525
*
2626
* var app = angular.module( 'App', ['ui.bootstrap.tooltip'], function( $tooltipProvider ) {
@@ -36,7 +36,7 @@ angular.module( 'ui.bootstrap.tooltip', [] )
3636
* Returns the actual instance of the $tooltip service.
3737
* TODO support multiple triggers
3838
*/
39-
this.$get = [ '$window', '$compile', '$timeout', '$parse', function ( $window, $compile, $timeout, $parse ) {
39+
this.$get = [ '$window', '$compile', '$timeout', '$parse', '$document', function ( $window, $compile, $timeout, $parse, $document ) {
4040
return function $tooltip ( type, defaultTriggerShow, defaultTriggerHide ) {
4141
var options = angular.extend( {}, defaultOptions, globalOptions );
4242

@@ -65,8 +65,9 @@ angular.module( 'ui.bootstrap.tooltip', [] )
6565
restrict: 'EA',
6666
scope: true,
6767
link: function link ( scope, element, attrs ) {
68-
var tooltip = $compile( template )( scope ),
69-
transitionTimeout;
68+
var tooltip = $compile( template )( scope );
69+
var transitionTimeout;
70+
var $body;
7071

7172
attrs.$observe( type, function ( val ) {
7273
scope.tt_content = val;
@@ -111,7 +112,12 @@ angular.module( 'ui.bootstrap.tooltip', [] )
111112

112113
// Now we add it to the DOM because need some info about it. But it's not
113114
// visible yet anyway.
114-
element.after( tooltip );
115+
if ( options.appendToBody ) {
116+
$body = $body || $document.find( 'body' );
117+
$body.append( tooltip );
118+
} else {
119+
element.after( tooltip );
120+
}
115121

116122
// Get the position of the directive element.
117123
position = getPosition( element );

0 commit comments

Comments
 (0)