diff --git a/paper-tooltip.js b/paper-tooltip.js index 9476bc8..6568bfb 100644 --- a/paper-tooltip.js +++ b/paper-tooltip.js @@ -339,6 +339,7 @@ Polymer({ */ attached: function() { this._findTarget(); + this.listen(this.$.tooltip, 'animationend', '_onAnimationEnd'); }, /** @@ -347,6 +348,7 @@ Polymer({ detached: function() { if (!this.manualMode) this._removeListeners(); + this.unlisten(this.$.tooltip, 'animationend', '_onAnimationEnd'); }, /** @@ -496,7 +498,6 @@ Polymer({ this.listen(this._target, 'blur', 'hide'); this.listen(this._target, 'tap', 'hide'); } - this.listen(this.$.tooltip, 'animationend', '_onAnimationEnd'); this.listen(this, 'mouseenter', 'hide'); }, @@ -582,7 +583,6 @@ Polymer({ this.unlisten(this._target, 'blur', 'hide'); this.unlisten(this._target, 'tap', 'hide'); } - this.unlisten(this.$.tooltip, 'animationend', '_onAnimationEnd'); this.unlisten(this, 'mouseenter', 'hide'); } }); diff --git a/test/basic.html b/test/basic.html index fe86f40..e893af9 100644 --- a/test/basic.html +++ b/test/basic.html @@ -477,6 +477,29 @@ expect(tooltip._removeListeners.callCount).to.be.equal(1); }); + test('animation state is updated in manual-mode', function() { + var f = fixture('manual-mode'); + + var tooltip = f.querySelector('paper-tooltip'); + assert.isTrue(tooltip.manualMode); + sinon.spy(tooltip, '_onAnimationEnd'); + + // Manually set the animation state for testing purposes + tooltip._animationPlaying = true; + assert.isTrue(tooltip._animationPlaying); + + // Select the inner tooltip div and use it to simulate the end of its + // animation + var tooltipContainer = tooltip.shadowRoot.querySelector('#tooltip'); + + // Dispatch an event simulating the end of a tooltip animation and make + // sure that the callback has been executed and that the animation + // state has been updated + tooltipContainer.dispatchEvent(new CustomEvent('animationend')); + expect(tooltip._onAnimationEnd.callCount).to.be.equal(1); + assert.isFalse(tooltip._animationPlaying); + }); + test('changing for= re-targets event listeners', function() { var f = fixture('dynamic'); var tooltip = f.querySelector('paper-tooltip');