From f5b357fd1152f5462089b680fcf4a624b498185e Mon Sep 17 00:00:00 2001 From: Matthias Dailey Date: Mon, 23 Jan 2017 14:20:50 -0500 Subject: [PATCH] fix(tooltip): unbind keypress listener on hide - Unbind listener on hide to fix memory leak Closes #6423 Fixes #6405 --- src/tooltip/tooltip.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index 6749a4f4bc..dd02a077a1 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -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') { @@ -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') { @@ -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); }); } }