Skip to content

Commit

Permalink
fix(tooltip): clean up keypress listener to avoid memory leaks
Browse files Browse the repository at this point in the history
Addresses angular-ui#6405
  • Loading branch information
matthias-ccri committed Jan 23, 2017
1 parent 761db7b commit 561e4b9
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,15 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s

if (tooltip) {
tooltip.remove();

tooltip = null;
if (adjustmentTimeout) {
$timeout.cancel(adjustmentTimeout);
}
}

openedTooltips.remove(ttScope);

if (tooltipLinkedScope) {
tooltipLinkedScope.$destroy();
tooltipLinkedScope = null;
Expand Down Expand Up @@ -496,6 +496,13 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
}
}

// KeyboardEvent handler to hide the tooltip on Escape key press
function hideOnEscapeKey(e) {
if (e.which === 27) {
hideTooltipBind();
}
}

var unregisterTriggers = function() {
triggers.show.forEach(function(trigger) {
if (trigger === 'outsideClick') {
Expand All @@ -504,6 +511,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
element.off(trigger, showTooltipBind);
element.off(trigger, toggleTooltipBind);
}
element.off('keypress', hideOnEscapeKey);
});
triggers.hide.forEach(function(trigger) {
if (trigger === 'outsideClick') {
Expand Down Expand Up @@ -543,12 +551,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
element.on(trigger, showTooltipBind);
element.on(triggers.hide[idx], hideTooltipBind);
}

element.on('keypress', function(e) {
if (e.which === 27) {
hideTooltipBind();
}
});
element.on('keypress', hideOnEscapeKey);
});
}
}
Expand Down

0 comments on commit 561e4b9

Please sign in to comment.