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

Commit 3fe7aa8

Browse files
committed
fix(tooltip): unbind element events on scope destroy
Closes #1339 Closes #1346 Closes #1400
1 parent 5dd9823 commit 3fe7aa8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/tooltip/tooltip.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
112112
var tooltip = $compile( template )( scope );
113113
var transitionTimeout;
114114
var popupTimeout;
115-
var $body = $document.find( 'body' );
116115
var appendToBody = angular.isDefined( options.appendToBody ) ? options.appendToBody : false;
117116
var triggers = getTriggers( undefined );
118117
var hasRegisteredTriggers = false;
@@ -172,7 +171,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
172171
// Now we add it to the DOM because need some info about it. But it's not
173172
// visible yet anyway.
174173
if ( appendToBody ) {
175-
$body.append( tooltip );
174+
$document.find( 'body' ).append( tooltip );
176175
} else {
177176
element.after( tooltip );
178177
}
@@ -271,12 +270,15 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
271270
scope.tt_popupDelay = ! isNaN(delay) ? delay : options.popupDelay;
272271
});
273272

274-
attrs.$observe( prefix+'Trigger', function ( val ) {
275-
273+
var unregisterTriggers = function() {
276274
if (hasRegisteredTriggers) {
277275
element.unbind( triggers.show, showTooltipBind );
278276
element.unbind( triggers.hide, hideTooltipBind );
279277
}
278+
};
279+
280+
attrs.$observe( prefix+'Trigger', function ( val ) {
281+
unregisterTriggers();
280282

281283
triggers = getTriggers( val );
282284

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

308310
// Make sure tooltip is destroyed and removed.
309311
scope.$on('$destroy', function onDestroyTooltip() {
312+
$timeout.cancel( transitionTimeout );
310313
$timeout.cancel( popupTimeout );
314+
unregisterTriggers();
311315
tooltip.remove();
312316
tooltip.unbind();
313317
tooltip = null;
314-
$body = null;
315318
});
316319
}
317320
};

0 commit comments

Comments
 (0)