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

Commit

Permalink
fix(tooltip): tackle DOM node and event handlers leak
Browse files Browse the repository at this point in the history
Closes #1133
  • Loading branch information
pkozlowski-opensource committed Nov 17, 2013
1 parent 127ab70 commit 0d810ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/tooltip/test/tooltip.spec.js
Expand Up @@ -332,7 +332,6 @@ describe('tooltip', function() {
expect( inCache() ).toBeTruthy();
elm.trigger('fooTrigger');
elmScope.$destroy();
$timeout.flush();
expect( inCache() ).toBeFalsy();
}));
});
Expand Down
25 changes: 13 additions & 12 deletions src/tooltip/tooltip.js
Expand Up @@ -100,7 +100,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
'title="'+startSym+'tt_title'+endSym+'" '+
'content="'+startSym+'tt_content'+endSym+'" '+
'placement="'+startSym+'tt_placement'+endSym+'" '+
'animation="tt_animation()" '+
'animation="tt_animation" '+
'is-open="tt_isOpen"'+
'>'+
'</'+ directiveName +'-popup>';
Expand All @@ -112,7 +112,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
var tooltip = $compile( template )( scope );
var transitionTimeout;
var popupTimeout;
var $body;
var $body = $document.find( 'body' );
var appendToBody = angular.isDefined( options.appendToBody ) ? options.appendToBody : false;
var triggers = getTriggers( undefined );
var hasRegisteredTriggers = false;
Expand Down Expand Up @@ -172,7 +172,6 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
// Now we add it to the DOM because need some info about it. But it's not
// visible yet anyway.
if ( appendToBody ) {
$body = $body || $document.find( 'body' );
$body.append( tooltip );
} else {
element.after( tooltip );
Expand Down Expand Up @@ -235,8 +234,10 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
// And now we remove it from the DOM. However, if we have animation, we
// need to wait for it to expire beforehand.
// FIXME: this is a placeholder for a port of the transitions library.
if ( angular.isDefined( scope.tt_animation ) && scope.tt_animation() ) {
transitionTimeout = $timeout( function () { tooltip.remove(); }, 500 );
if ( scope.tt_animation ) {
transitionTimeout = $timeout(function () {
tooltip.remove();
}, 500);
} else {
tooltip.remove();
}
Expand All @@ -263,8 +264,8 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
scope.tt_placement = angular.isDefined( val ) ? val : options.placement;
});

attrs.$observe( prefix+'Animation', function ( val ) {
scope.tt_animation = angular.isDefined( val ) ? $parse( val ) : function(){ return options.animation; };
attrs.$observe(prefix + 'Animation', function (val) {
scope.tt_animation = angular.isDefined(val) ? !!val : options.animation;
});

attrs.$observe( prefix+'PopupDelay', function ( val ) {
Expand Down Expand Up @@ -308,11 +309,11 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap

// Make sure tooltip is destroyed and removed.
scope.$on('$destroy', function onDestroyTooltip() {
if ( scope.tt_isOpen ) {
hide();
} else {
tooltip.remove();
}
$timeout.cancel( popupTimeout );
tooltip.remove();
tooltip.unbind();
tooltip = null;
$body = null;
});
}
};
Expand Down

0 comments on commit 0d810ac

Please sign in to comment.