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 3a4f0b2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
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 3a4f0b2

Please sign in to comment.