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

Commit

Permalink
fix(tooltip): unbind element events on scope destroy
Browse files Browse the repository at this point in the history
Closes #1339
Closes #1346
Closes #1400
  • Loading branch information
bekos committed Dec 14, 2013
1 parent 5dd9823 commit 3fe7aa8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
var tooltip = $compile( template )( scope );
var transitionTimeout;
var popupTimeout;
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 +171,7 @@ 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.append( tooltip );
$document.find( 'body' ).append( tooltip );
} else {
element.after( tooltip );
}
Expand Down Expand Up @@ -271,12 +270,15 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
scope.tt_popupDelay = ! isNaN(delay) ? delay : options.popupDelay;
});

attrs.$observe( prefix+'Trigger', function ( val ) {

var unregisterTriggers = function() {
if (hasRegisteredTriggers) {
element.unbind( triggers.show, showTooltipBind );
element.unbind( triggers.hide, hideTooltipBind );
}
};

attrs.$observe( prefix+'Trigger', function ( val ) {
unregisterTriggers();

triggers = getTriggers( val );

Expand Down Expand Up @@ -307,11 +309,12 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap

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

0 comments on commit 3fe7aa8

Please sign in to comment.