diff --git a/src/modal/modal.js b/src/modal/modal.js index c9dc529599..9304b635f4 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -1,4 +1,4 @@ -angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition']) +angular.module('ui.bootstrap.modal', []) /** * A helper, internal data structure that acts as a map but also allows getting / removing @@ -155,8 +155,8 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition']) }; }) - .factory('$modalStack', ['$transition', '$timeout', '$document', '$compile', '$rootScope', '$$stackedMap', - function ($transition, $timeout, $document, $compile, $rootScope, $$stackedMap) { + .factory('$modalStack', ['$animate', '$timeout', '$document', '$compile', '$rootScope', '$$stackedMap', + function ($animate, $timeout, $document, $compile, $rootScope, $$stackedMap) { var OPENED_MODAL_CLASS = 'modal-open'; @@ -190,8 +190,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition']) openedWindows.remove(modalInstance); //remove window DOM element - removeAfterAnimate(modalWindow.modalDomEl, modalWindow.modalScope, 300, function() { - modalWindow.modalScope.$destroy(); + removeAfterAnimate(modalWindow.modalDomEl, modalWindow.modalScope, function() { body.toggleClass(OPENED_MODAL_CLASS, openedWindows.length() > 0); checkRemoveBackdrop(); }); @@ -201,8 +200,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition']) //remove backdrop if no longer needed if (backdropDomEl && backdropIndex() == -1) { var backdropScopeRef = backdropScope; - removeAfterAnimate(backdropDomEl, backdropScope, 150, function () { - backdropScopeRef.$destroy(); + removeAfterAnimate(backdropDomEl, backdropScope, function () { backdropScopeRef = null; }); backdropDomEl = undefined; @@ -210,19 +208,14 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition']) } } - function removeAfterAnimate(domEl, scope, emulateTime, done) { + function removeAfterAnimate(domEl, scope, done) { // Closing animation scope.animate = false; - var transitionEndEventName = $transition.transitionEndEventName; - if (transitionEndEventName) { + if ($animate.enabled()) { // transition out - var timeout = $timeout(afterAnimating, emulateTime); - - domEl.bind(transitionEndEventName, function () { - $timeout.cancel(timeout); - afterAnimating(); - scope.$apply(); + domEl.one('$animate:close', function closeFn() { + $rootScope.$evalAsync(afterAnimating); }); } else { // Ensure this call is async @@ -236,6 +229,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition']) afterAnimating.done = true; domEl.remove(); + scope.$destroy(); if (done) { done(); } diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index ff8107328c..cb87d33e6a 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -8,14 +8,6 @@ describe('$modal', function () { element.trigger(e); }; - var waitForBackdropAnimation = function () { - inject(function ($transition) { - if ($transition.transitionEndEventName) { - $timeout.flush(); - } - }); - }; - beforeEach(module('ui.bootstrap.modal')); beforeEach(module('template/modal/backdrop.html')); beforeEach(module('template/modal/window.html')); @@ -106,16 +98,20 @@ describe('$modal', function () { return modal; } - function close(modal, result) { + function close(modal, result, noFlush) { var closed = modal.close(result); - $timeout.flush(); + if (!noFlush) { + $timeout.flush(); + } $rootScope.$digest(); return closed; } - function dismiss(modal, reason) { + function dismiss(modal, reason, noFlush) { var closed = modal.dismiss(reason); - $timeout.flush(); + if (!noFlush) { + $timeout.flush(); + } $rootScope.$digest(); return closed; } @@ -134,7 +130,6 @@ describe('$modal', function () { expect($document).toHaveModalsOpen(0); - waitForBackdropAnimation(); expect($document).not.toHaveBackdrop(); }); @@ -150,7 +145,7 @@ describe('$modal', function () { expect($document).toHaveModalsOpen(0); - dismiss(modal, 'closing in test'); + dismiss(modal, 'closing in test', true); }); it('should not throw an exception on a second close', function () { @@ -165,7 +160,7 @@ describe('$modal', function () { expect($document).toHaveModalsOpen(0); - close(modal, 'closing in test'); + close(modal, 'closing in test', true); }); it('should open a modal from templateUrl', function () { @@ -181,7 +176,6 @@ describe('$modal', function () { expect($document).toHaveModalsOpen(0); - waitForBackdropAnimation(); expect($document).not.toHaveBackdrop(); }); @@ -244,8 +238,6 @@ describe('$modal', function () { function openAndCloseModalWithAutofocusElement() { var modal = open({template: '
'}); - waitForBackdropAnimation(); - expect(angular.element('#auto-focus-element')).toHaveFocus(); close(modal, 'closed ok'); @@ -505,7 +497,6 @@ describe('$modal', function () { expect(backdropEl).toHaveClass('in'); dismiss(modal); - waitForBackdropAnimation(); modal = open({ template: '
With backdrop
' }); backdropEl = $document.find('body > div.modal-backdrop');