Skip to content

Commit

Permalink
fix(tooltip): link on demand
Browse files Browse the repository at this point in the history
Attempts to fix angular-ui#1450
  • Loading branch information
chrisirhc committed Dec 24, 2013
1 parent 9b8b678 commit 22f3858
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
8 changes: 1 addition & 7 deletions src/tooltip/test/tooltip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,18 +348,12 @@ describe('tooltip', function() {

elm = elmBody.find('input');
elmScope = elm.scope();
elm.trigger('fooTrigger');
tooltipScope = elmScope.$$childTail;
}));

it( 'should not contain a cached reference', function() {
expect( inCache() ).toBeTruthy();
elmScope.$destroy();
expect( inCache() ).toBeFalsy();
});

it( 'should not contain a cached reference when visible', inject( function( $timeout ) {
expect( inCache() ).toBeTruthy();
elm.trigger('fooTrigger');
elmScope.$destroy();
expect( inCache() ).toBeFalsy();
}));
Expand Down
27 changes: 19 additions & 8 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
return {
restrict: 'EA',
scope: true,
link: function link ( scope, element, attrs ) {
var tooltip = $compile( template )( scope );
compile: function (tElem, tAttrs) {
var tooltipLinker = $compile( template );

return function link ( scope, element, attrs ) {
var tooltip;
var transitionTimeout;
var popupTimeout;
var appendToBody = angular.isDefined( options.appendToBody ) ? options.appendToBody : false;
Expand Down Expand Up @@ -154,6 +157,10 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
ttHeight,
ttPosition;

// There can only be one tooltip element per directive shown at once.
removeTooltip();
tooltip = tooltipLinker(scope);

// Don't show empty tooltips.
if ( ! scope.tt_content ) {
return;
Expand Down Expand Up @@ -234,11 +241,16 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
// need to wait for it to expire beforehand.
// FIXME: this is a placeholder for a port of the transitions library.
if ( scope.tt_animation ) {
transitionTimeout = $timeout(function () {
tooltip.remove();
}, 500);
transitionTimeout = $timeout(removeTooltip, 500);
} else {
removeTooltip();
}
}

function removeTooltip() {
if (tooltip) {
tooltip.remove();
tooltip = null;
}
}

Expand Down Expand Up @@ -316,10 +328,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
$timeout.cancel( transitionTimeout );
$timeout.cancel( popupTimeout );
unregisterTriggers();
tooltip.remove();
tooltip.unbind();
tooltip = null;
removeTooltip();
});
};
}
};
};
Expand Down

0 comments on commit 22f3858

Please sign in to comment.