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

Commit d089626

Browse files
Josh David Millerpkozlowski-opensource
Josh David Miller
authored andcommittedJun 24, 2013
feat(tooltip): add *-append-to-body attribute
The tooltip and popover directives (through the $tooltip service) now support using an attribute in addition to the provider to set a particular tooltip or popover to use $body as the container for the popup element rather than the directive element's parent. Closes #395.
1 parent ace7bc6 commit d089626

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed
 

‎src/popover/docs/readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ will display:
1515
over the element before the popover shows (in milliseconds)? Defaults to 0.
1616
- `popover-trigger`: What should trigger the show of the popover? See the
1717
`tooltip` directive for supported values.
18+
- `popover-append-to-body`: Should the tooltip be appended to `$body` instead of
19+
the parent element?
1820

1921
The popover directives require the `$position` service.
2022

‎src/tooltip/docs/readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ will display:
1616
- `tooltip-popup-delay`: For how long should the user have to have the mouse
1717
over the element before the tooltip shows (in milliseconds)? Defaults to 0.
1818
- `tooltip-trigger`: What should trigger a show of the tooltip?
19+
- `tooltip-append-to-body`: Should the tooltip be appended to `$body` instead of
20+
the parent element?
1921

2022
The tooltip directives require the `$position` service.
2123

‎src/tooltip/test/tooltip.spec.js

+27
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,33 @@ describe('tooltip', function() {
211211
}));
212212
});
213213

214+
describe( 'with an append-to-body attribute', function() {
215+
var scope, elmBody, elm, elmScope;
216+
217+
beforeEach( inject( function( $rootScope ) {
218+
scope = $rootScope;
219+
}));
220+
221+
it( 'should append to the body', inject( function( $compile, $document ) {
222+
$body = $document.find( 'body' );
223+
elmBody = angular.element(
224+
'<div><span tooltip="tooltip text" tooltip-append-to-body="true">Selector Text</span></div>'
225+
);
226+
227+
$compile(elmBody)(scope);
228+
scope.$digest();
229+
elm = elmBody.find('span');
230+
elmScope = elm.scope();
231+
232+
var bodyLength = $body.children().length;
233+
elm.trigger( 'mouseenter' );
234+
235+
expect( elmScope.tt_isOpen ).toBe( true );
236+
expect( elmBody.children().length ).toBe( 1 );
237+
expect( $body.children().length ).toEqual( bodyLength + 1 );
238+
}));
239+
});
240+
214241
});
215242

216243
describe('tooltipWithDifferentSymbols', function() {

‎src/tooltip/tooltip.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
112112
var transitionTimeout;
113113
var popupTimeout;
114114
var $body;
115+
var appendToBody = angular.isDefined( options.appendToBody ) ? options.appendToBody : false;
115116

116117
// By default, the tooltip is not open.
117118
// TODO add ability to start tooltip opened
@@ -163,7 +164,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
163164

164165
// Now we add it to the DOM because need some info about it. But it's not
165166
// visible yet anyway.
166-
if ( options.appendToBody ) {
167+
if ( appendToBody ) {
167168
$body = $body || $document.find( 'body' );
168169
$body.append( tooltip );
169170
} else {
@@ -279,10 +280,14 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
279280
}
280281
});
281282

283+
attrs.$observe( prefix+'AppendToBody', function ( val ) {
284+
appendToBody = angular.isDefined( val ) ? $parse( val )( scope ) : appendToBody;
285+
});
286+
282287
// if a tooltip is attached to <body> we need to remove it on
283288
// location change as its parent scope will probably not be destroyed
284289
// by the change.
285-
if ( options.appendToBody ) {
290+
if ( appendToBody ) {
286291
scope.$on('$locationChangeSuccess', function closeTooltipOnLocationChangeSuccess () {
287292
if ( scope.tt_isOpen ) {
288293
hide();

0 commit comments

Comments
 (0)