From ca6b7d0fa2e355ebd764230260758cee9a4ebe1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Wed, 22 Jan 2014 12:38:26 -0500 Subject: [PATCH] feat($animate): provide support for a close callback Closes #5685 Closes #5053 Closes #4993 --- src/ngAnimate/animate.js | 5 ++++- test/ngAnimate/animateSpec.js | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/ngAnimate/animate.js b/src/ngAnimate/animate.js index bf5e3af438bd..b1ea7d3d0216 100644 --- a/src/ngAnimate/animate.js +++ b/src/ngAnimate/animate.js @@ -828,7 +828,10 @@ angular.module('ngAnimate', ['ng']) } function fireDoneCallbackAsync() { - doneCallback && async(doneCallback); + async(function() { + fireDOMCallback('close'); + doneCallback && doneCallback(); + }); } //it is less complicated to use a flag than managing and cancelling diff --git a/test/ngAnimate/animateSpec.js b/test/ngAnimate/animateSpec.js index 6d9367bdbab0..a5123929167b 100644 --- a/test/ngAnimate/animateSpec.js +++ b/test/ngAnimate/animateSpec.js @@ -1519,7 +1519,13 @@ describe("ngAnimate", function() { steps.push(['after', data.className, data.event]); }); - $animate.addClass(element, 'klass'); + element.on('$animate:close', function(e, data) { + steps.push(['close', data.className, data.event]); + }); + + $animate.addClass(element, 'klass', function() { + steps.push(['done', 'klass', 'addClass']); + }); $timeout.flush(1); @@ -1529,6 +1535,13 @@ describe("ngAnimate", function() { $timeout.flush(1); expect(steps.pop()).toEqual(['after', 'klass', 'addClass']); + + browserTrigger(element,'transitionend', { timeStamp: Date.now() + 1000, elapsedTime: 1 }); + $timeout.flush(1); + + expect(steps.shift()).toEqual(['close', 'klass', 'addClass']); + + expect(steps.shift()).toEqual(['done', 'klass', 'addClass']); })); it('should fire the DOM callbacks even if no animation is rendered',