diff --git a/src/tooltip/test/tooltip.spec.js b/src/tooltip/test/tooltip.spec.js index 5fe92be409..3058429dae 100644 --- a/src/tooltip/test/tooltip.spec.js +++ b/src/tooltip/test/tooltip.spec.js @@ -27,7 +27,7 @@ describe('tooltip', function() { })); afterEach(function() { - $document.off('keypress'); + $document.off('keyup'); }); function trigger(element, evt) { @@ -295,10 +295,9 @@ describe('tooltip', function() { trigger(elm, 'mouseenter'); expect(tooltipScope.isOpen).toBe(false); - $timeout.flush(500); - expect(tooltipScope.isOpen).toBe(false); elmScope.disabled = true; elmScope.$digest(); + $timeout.flush(500); expect(tooltipScope.isOpen).toBe(false); }); @@ -343,22 +342,24 @@ describe('tooltip', function() { expect(tooltipScope.isOpen).toBe(true); expect(tooltipScope2.isOpen).toBe(true); - var evt = $.Event('keypress'); + var evt = $.Event('keyup'); evt.which = 27; $document.trigger(evt); tooltipScope.$digest(); tooltipScope2.$digest(); + $timeout.flush(); expect(tooltipScope.isOpen).toBe(true); expect(tooltipScope2.isOpen).toBe(false); - var evt2 = $.Event('keypress'); + var evt2 = $.Event('keyup'); evt2.which = 27; $document.trigger(evt2); tooltipScope.$digest(); tooltipScope2.$digest(); + $timeout.flush(500); expect(tooltipScope.isOpen).toBe(false); expect(tooltipScope2.isOpen).toBe(false); diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index 37006fb18d..5ac0bd54aa 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -71,10 +71,10 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s */ this.$get = ['$window', '$compile', '$timeout', '$document', '$uibPosition', '$interpolate', '$rootScope', '$parse', '$$stackedMap', function($window, $compile, $timeout, $document, $position, $interpolate, $rootScope, $parse, $$stackedMap) { var openedTooltips = $$stackedMap.createNew(); - $document.on('keypress', keypressListener); + $document.on('keyup', keypressListener); $rootScope.$on('$destroy', function() { - $document.off('keypress', keypressListener); + $document.off('keyup', keypressListener); }); function keypressListener(e) { @@ -82,7 +82,6 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s var last = openedTooltips.top(); if (last) { last.value.close(); - openedTooltips.removeTop(); last = null; } } @@ -207,9 +206,6 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s // By default, the tooltip is not open. // TODO add ability to start tooltip opened ttScope.isOpen = false; - openedTooltips.add(ttScope, { - close: hide - }); function toggleTooltipBind() { if (!ttScope.isOpen) { @@ -336,6 +332,10 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s } }); + openedTooltips.add(ttScope, { + close: hide + }); + prepObservers(); } @@ -348,6 +348,9 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s tooltip.remove(); tooltip = null; } + + openedTooltips.remove(ttScope); + if (tooltipLinkedScope) { tooltipLinkedScope.$destroy(); tooltipLinkedScope = null; @@ -563,7 +566,6 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s scope.$on('$destroy', function onDestroyTooltip() { unregisterTriggers(); removeTooltip(); - openedTooltips.remove(ttScope); ttScope = null; }); };